helper = new Zend_View_Helper_TinySrc(); $this->view = new Zend_View(); $this->view->doctype()->setDoctype(strtoupper("XHTML1_STRICT")); $this->helper->setView($this->view); } public function testCallingHelperMethodWithNoArgumentsReturnsHelperInstance() { $test = $this->helper->tinySrc(); $this->assertSame($this->helper, $test); } public function testHelperUsesServerAndBaseUrlFromHelpersByDefault() { $base = $this->view->getHelper('baseUrl'); $base->setBaseUrl('/foo/bar'); $server = $this->view->getHelper('serverUrl'); $server->setScheme('https') ->setHost('example.com:8080'); $test = $this->helper->getBaseUrl(); $this->assertEquals('https://example.com:8080/foo/bar/', $test); } public function testAllowsSettingDefaultFormat() { $this->helper->setDefaultFormat('png') ->setBaseUrl('http://example.com'); $image = $this->helper->tinySrc('foo.jpg'); $this->assertContains('/png/', $image); } public function testSettingInvalidDefaultFormatRaisesException() { $this->setExpectedException('Zend_View_Exception', 'Invalid format'); $this->helper->setDefaultFormat('gif'); } public function testPassingNullValueToDefaultFormatClearsSetFormat() { $this->helper->setDefaultFormat('png') ->setBaseUrl('http://example.com'); $this->helper->setDefaultFormat(null); $image = $this->helper->tinySrc('foo.jpg'); $this->assertNotContains('/png/', $image); } public function testAllowsPassingDefaultWidth() { $this->helper->setBaseUrl('http://example.com') ->setDefaultDimensions('-5'); $image = $this->helper->tinySrc('foo.jpg'); $this->assertContains('/-5/', $image); } /** * @dataProvider invalidDimensions */ public function testRaisesExceptionOnInvalidDefaultWidthValue($dim) { $this->setExpectedException('Zend_View_Exception', 'Invalid dimension'); $this->helper->setDefaultDimensions($dim); } public function testAllowsPassingDefaultWidthAndHeight() { $this->helper->setBaseUrl('http://example.com') ->setDefaultDimensions('5', 'x20'); $image = $this->helper->tinySrc('foo.jpg'); $this->assertContains('/5/x20/', $image); } /** * @dataProvider invalidDimensions */ public function testRaisesExceptionOnInvalidDefaultHeightValue($dim) { $this->setExpectedException('Zend_View_Exception', 'Invalid dimension'); $this->helper->setDefaultDimensions('10', $dim); } public function testPassingNullAsDefaultWidthValueClearsBothWidthAndHeight() { $this->helper->setBaseUrl('http://example.com') ->setDefaultDimensions('5', 'x20'); $this->helper->setDefaultDimensions(null, 'x20'); $image = $this->helper->tinySrc('foo.jpg'); $this->assertNotContains('/5/x20/', $image); $this->assertNotContains('/5/', $image); $this->assertNotContains('/x20/', $image); } public function testPassingNullAsDefaultHeightValueClearsHeight() { $this->helper->setBaseUrl('http://example.com') ->setDefaultDimensions('5', 'x20'); $this->helper->setDefaultDimensions('5'); $image = $this->helper->tinySrc('foo.jpg'); $this->assertNotContains('/5/x20/', $image); $this->assertContains('/5/', $image); } public function testCreatesImageTagByDefault() { $this->helper->setBaseUrl('http://example.com'); $image = $this->helper->tinySrc('foo.jpg'); $this->assertContains('helper->setBaseUrl('http://example.com') ->setCreateTag(false) ->setDefaultDimensions(320, 480); $image = $this->helper->tinySrc('foo.jpg', array( 'base_url' => 'https://example.org:8080/public', 'format' => 'png', 'width' => 160, 'height' => null, 'create_tag' => true, )); $this->assertContains('helper->setBaseUrl('http://example.com'); $image = $this->helper->tinySrc('foo.jpg', array( 'alt' => 'Alt text for image', )); $this->assertContains('alt="Alt text for image"', $image); } public function invalidDimensions() { return array( array('foo'), array(true), array(array()), array(new stdClass), ); } } // Call Zend_View_Helper_TinySrcTest::main() if this source file is executed directly. if (PHPUnit_MAIN_METHOD == 'Zend_View_Helper_TinySrcTest::main') { Zend_View_Helper_TinySrcTest::main(); }