Perforce Chronicle 2012.2/486814
API Documentation
|
Test the video widget subform. More...
Public Member Functions | |
setUp () | |
Initialize the module. | |
testFormInit () | |
Test form initialization and default values. | |
testValidation () | |
Verifies the validation of the form, specificly the youtube url. |
Test the video widget subform.
Youtube_Test_VideoWidgetTest::setUp | ( | ) |
Initialize the module.
{ parent::setUp(); // enable youtube module $module = P4Cms_Module::fetch('Youtube'); $module->enable(); $module->load(); }
Youtube_Test_VideoWidgetTest::testFormInit | ( | ) |
Test form initialization and default values.
Verifies that the defaults and form structure hasn't been accidently changed.
{ // verify form defaults $form = new Youtube_Form_VideoWidget; $expected = array( '' => array( 'videoUrl' => '', 'videoSize' => Youtube_Form_VideoWidget::DIMENSION_MEDIUM, 'videoWidth' => '', 'videoHeight' => '', 'controls' => Youtube_Form_VideoWidget::CONTROLS_ALWAYS_SHOW, 'autoplay' => true, 'loop' => 0, 'allowFullscreen' => true, 'playHd' => true, 'showAnnotations' => 0, 'showRelated' => 0 ) ); $this->assertEquals( $expected, $form->getValues(), "Expected default values" ); }
Youtube_Test_VideoWidgetTest::testValidation | ( | ) |
Verifies the validation of the form, specificly the youtube url.
{ // configure the widget // should fail because it is missing the required video url field. $data = array( 'region' => 'test', 'widget' => '1', 'title' => 'YouTube test', 'config' => array( 'videoUrl' => '' ) ); $form = new Widget_Form_Config; $form->addSubForm(new Youtube_Form_VideoWidget, 'config', 2); $form->setCsrfProtection(false); $this->assertFalse($form->isValid($data), 'Expected form to be invalid.'); // should fail because it is contains an invalid url $data['config']['videoUrl'] = 'invalidyoutubeurl'; $form = new Widget_Form_Config; $form->addSubForm(new Youtube_Form_VideoWidget, 'config', 2); $form->setCsrfProtection(false); $this->assertFalse( $form->isValid($data), 'Expected url ' . $data['config']['videoUrl'] .' to be invalid.' ); // should fail because it is contains no video id $data['config']['videoUrl'] = 'http://www.youtube.com/'; $form = new Widget_Form_Config; $form->addSubForm(new Youtube_Form_VideoWidget, 'config', 2); $form->setCsrfProtection(false); $this->assertFalse( $form->isValid($data), 'Expected url ' . $data['config']['videoUrl'] .' to be invalid.' ); // should fail because it is contains an invalid domain $data['config']['videoUrl'] = 'http://www.perforce.com/watch?v=CDunnQz81FY'; $form = new Widget_Form_Config; $form->addSubForm(new Youtube_Form_VideoWidget, 'config', 2); $form->setCsrfProtection(false); $this->assertFalse( $form->isValid($data), 'Expected url ' . $data['config']['videoUrl'] .' to be invalid.' ); // should pass $data['config']['videoUrl'] = 'http://www.youtube.com/watch?v=CDunnQz81FY'; $form = new Widget_Form_Config; $form->addSubForm(new Youtube_Form_VideoWidget, 'config', 2); $form->setCsrfProtection(false); $this->assertTrue( $form->isValid($data), 'Expected url ' . $data['config']['videoUrl'] .' to be valid.' ); // should pass as well, as the id as appended to a hardcoded domain in the view script $data['config']['videoUrl'] = 'http://www.youtube.evilhacksite.com/watch?v=CDunnQz81FY'; $form = new Widget_Form_Config; $form->addSubForm(new Youtube_Form_VideoWidget, 'config', 2); $form->setCsrfProtection(false); $this->assertTrue( $form->isValid($data), 'Expected url ' . $data['config']['videoUrl'] .' to be valid.' ); }