Perforce Chronicle 2012.2/486814
API Documentation

Content_Test_TypeGroupElementTest Class Reference

Test methods for the type group form element. More...

List of all members.

Public Member Functions

 _createTestType ($id= 'test-type')
 Create a type for testing.
 testDefaults ()
 Test that the default values are set as expected.
 testInstantiation ()
 Test instantiation.
 testNormalization ()
 Test the normalization.
 testSetValue ()
 Test the functionality in setValue Note that the order of results depends on which element is appended by the method.

Detailed Description

Test methods for the type group form element.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

Content_Test_TypeGroupElementTest::_createTestType ( id = 'test-type')

Create a type for testing.

Parameters:
string$idThe id to use for the test content type
    {
        $elements = array(
            'title' => array(
                'type'      => 'text',
                'options'   => array('label' => 'Title', 'required' => true),
            ),
            'body'  => array(
                'type'      => 'textarea',
                'options'   => array('label' => 'Body'),
            ),
            'abstract'  => array(
                'type'      => 'textarea',
                'options'   => array('label' => 'Abstract'),
            ),
            'id'        => array(
                'type'      => 'text',
                'options'   => array('label' => 'ID', 'required' => true)
            )
        );
        
        $type = new P4Cms_Content_Type;
        $type->setId($id)
             ->setLabel("Test Type")
             ->setElements($elements)
             ->setValue('icon', file_get_contents(TEST_ASSETS_PATH . '/images/content-type-icon.png'))
             ->setFieldMetadata('icon', array("mimeType" => "image/png"))
             ->setGroup('test-group')
             ->save();

        return $type;
    }
Content_Test_TypeGroupElementTest::testDefaults ( )

Test that the default values are set as expected.

    {
        $element = new Content_Form_Element_TypeGroup('test');
        $options = $element->getMultiOptions();
        $this->assertEquals(array(), $options, 'Expected empty options due to no content types present.');
        
        $this->_createTestType();
        $element  = new Content_Form_Element_TypeGroup('test');
        $options  = $element->getMultiOptions();
        $expected = array(
            'test-group/'  => array('test-group/test-type' => 'Test Type'), 
            'test-group/*' => 'test-group'
        );
        $this->assertEquals($expected, $options, 'Expected test options to be present.');
    }
Content_Test_TypeGroupElementTest::testInstantiation ( )

Test instantiation.

    {
        $element = new Content_Form_Element_TypeGroup('test');
        $this->assertTrue($element instanceof Content_Form_Element_TypeGroup, 'Expected class');
    }
Content_Test_TypeGroupElementTest::testNormalization ( )

Test the normalization.

    {
        $this->_createTestType();
        $element    = new Content_Form_Element_TypeGroup('test');
        $normalized = $element->getNormalizedTypes();
        $this->assertEquals(array(), $normalized, 'Expected empty array for normalized value.');
        
        $element->setValue(array('test-group/*'));
        $normalized = $element->getNormalizedTypes();
        $expected   = array(
            'test-group/test-type' => 'Test Type',
            '1'                    => 'test-type'
        );
        
        $this->assertEquals($expected, $normalized, 'Expected normalized value.');
    }
Content_Test_TypeGroupElementTest::testSetValue ( )

Test the functionality in setValue Note that the order of results depends on which element is appended by the method.

    {
        $element = new Content_Form_Element_TypeGroup('test');
        $this->assertEquals(null, $element->getValue(), 'Expected value to be null, line ' . __LINE__);
        
        $this->_createTestType();
        $this->_createTestType('test-type-2');
        $element = new Content_Form_Element_TypeGroup('test');
        
        $element->setValue(array('test-group/test-type'));
        $expected = array('test-group/test-type');
        $this->assertEquals(
            $expected, 
            $element->getValue(), 
            'Expected a single value when it is selected, line ' . __LINE__
        );
        
        $element->setValue(array('test-group/*'));
        $expected = array(
            'test-group/*',
            'test-group/test-type-2',
            'test-group/test-type'
        );
        $this->assertEquals(
            $expected, 
            $element->getValue(), 
            'Expected all types to be selected when group is selected, line ' . __LINE__
        );
        
        $element->setValue(
            array(
                'test-group/test-type',
                'test-group/test-type-2'
            )
        );
        $expected = array(
            'test-group/test-type',
            'test-group/test-type-2',
            'test-group/*'
        );
        $this->assertEquals(
            $expected, 
            $element->getValue(), 
            'Expected group to be selected when all types are selected, line ' . __LINE__
        );
    }

The documentation for this class was generated from the following file: