Perforce Chronicle 2012.2/486814
API Documentation

Flickr_Test_StreamWidgetTest Class Reference

Test the flickr stream widget subform. More...

List of all members.

Public Member Functions

 setUp ()
 Initialize the module.
 testFormInit ()
 Test form initialization and default values.
 testValidation ()
 Verifies the validation of the form.

Detailed Description

Test the flickr stream widget subform.

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

Flickr_Test_StreamWidgetTest::setUp ( )

Initialize the module.

    {
        parent::setUp();

        // enable flickr module
        $module = P4Cms_Module::fetch('Flickr');
        $module->enable();
        $module->load();
    }
Flickr_Test_StreamWidgetTest::testFormInit ( )

Test form initialization and default values.

Verifies that the defaults and form structure hasn't been accidently changed.

    {
        // verify form defaults
        $form = new Flickr_Form_StreamWidget;

        $expected = array(
            '' => array(
                'sourceType'        => Flickr_Form_StreamWidget::SOURCE_TAG,
                'sourceTag'         => '',
                'sourceUser'        => '',
                'sourceGroup'       => '',
                'imageSize'         => Flickr_Form_StreamWidget::DIMENSION_THUMBNAIL,
                'showImageTitle'    => 0,
                'imageDelay'        => 3
            )
        );

        $this->assertEquals(
            $expected,
            $form->getValues(),
            "Expected default values"
        );
    }
Flickr_Test_StreamWidgetTest::testValidation ( )

Verifies the validation of the form.

    {
        // configure the widget
        // should fail because it is missing the required source key
        $data = array(
            'region'            => 'test',
            'widget'            => '1',
            'title'             => 'Flickr Test',
            'config'            => array(
                'sourceType'        => Flickr_Form_StreamWidget::SOURCE_TAG,
                'sourceTag'         => '',
                'sourceUser'        => '',
                'sourceGroup'       => '',
                'imageSize'         => Flickr_Form_StreamWidget::DIMENSION_THUMBNAIL,
                'showImageTitle'    => 0,
                'imageDelay'        => 3
            )
        );

        $form = new Widget_Form_Config;
        $form->addSubForm(new Flickr_Form_StreamWidget, 'config', 2);
        $form->setCsrfProtection(false);
        
        // will be false because no tag is set
        $this->assertFalse($form->isValid($data), 'Expected form to be invalid.');

        // expected to be false due to missing information
        $data['config']['sourceType']   = Flickr_Form_StreamWidget::SOURCE_GROUP;
        $data['config']['sourceGroup']  = '';
        $this->assertFalse($form->isValid($data), 'Expected form to be invalid.');

        // expected to be false due to missing information
        $data['config']['sourceType']   = Flickr_Form_StreamWidget::SOURCE_USER;
        $data['config']['sourceUser']   = '';
        $this->assertFalse($form->isValid($data), 'Expected form to be invalid.');

        $form = new Widget_Form_Config;
        $form->addSubForm(new Flickr_Form_StreamWidget, 'config', 2);
        $form->setCsrfProtection(false);

        $data['config']['sourceType']   = Flickr_Form_StreamWidget::SOURCE_TAG;
        $data['config']['sourceTag']    = 'perforce';
        $this->assertTrue($form->isValid($data), 'Expected form to be valid.');

        $data['config']['sourceType']   = Flickr_Form_StreamWidget::SOURCE_GROUP;
        $data['config']['sourceGroup']  = '52241285452@N01';   // victoria, bc group
        $this->assertTrue($form->isValid($data), 'Expected form to be valid.');

        $data['config']['sourceType']   = Flickr_Form_StreamWidget::SOURCE_USER;
        $data['config']['sourceUser']  = 'p4cms';
        $this->assertTrue($form->isValid($data), 'Expected form to be valid.');
    }

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