diff --git a/tests/suites/unit/joomla/document/image/JDocumentImageTest.php b/tests/suites/unit/joomla/document/image/JDocumentImageTest.php new file mode 100644 index 0000000000..5f586dd91d --- /dev/null +++ b/tests/suites/unit/joomla/document/image/JDocumentImageTest.php @@ -0,0 +1,157 @@ +saveFactoryState(); + + require_once JPATH_PLATFORM . '/joomla/factory.php'; + + $app = $this->getMockApplication(); + + JFactory::$application = $app; + + $this->object = new JDocumentImage; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + * + * @access protected + * + * @return void + */ + protected function tearDown() + { + $this->restoreFactoryState(); + + parent::teardown(); + } + + /** + * Tests the JDocumentImage::__construct method. + * + * @return void + * + * @covers JDocumentImage::__construct + */ + public function test__construct($options = array()) + { + $documentImage = new JDocumentImage; + + $this->assertThat( + $documentImage->_mime, + $this->equalTo('image/png'), + 'JDocumentImage::__construct: Default Mime does not match' + ); + + $this->assertThat( + $documentImage->_type, + $this->equalTo('image'), + 'JDocumentImage::__construct: Default Type does not match' + ); + } + + /** + * Test... + * + * @covers JDocumentImage::render + * + * @return void + */ + public function testRender() + { + JResponse::clearHeaders(); + + $testFiles = array( + 'jpg' => array( + 'file' => 'logo.jpg', + 'mime' => 'image/jpeg' + ), + 'jpeg' => array( + 'file' => 'logo.jpeg', + 'mime' => 'image/jpeg' + ), + 'gif' => array( + 'file' => 'logo.gif', + 'mime' => 'image/gif' + ), + 'png' => array( + 'file' => 'logo.png', + 'mime' => 'image/png', + ), + 'bmp' => array( + 'file' => 'logo.png', + 'mime' => 'image/png' + ) + ); + + foreach ($testFiles as $type => $info) + { + // Set type + JFactory::$application->input->set('type', $type); + + $buffer = file_get_contents(__DIR__ . '/' . $info['file']); + + // Render + $this->object->setBuffer($buffer); + $returnBuffer = $this->object->render(); + + // Check buffer return + $this->assertThat( + $returnBuffer, + $this->equalTo($buffer), + 'JDocumentImage::render: Buffer does not match' + ); + + // Check Mime + $this->assertThat( + $this->object->_mime, + $this->equalTo($info['mime']), + 'JDocumentImage::render: Mime does not match' + ); + } + + // Chek Charset + $this->assertThat( + $this->object->_charset, + $this->isNull(), + 'JDocumentImage::render Charset is not null' + ); + } +} diff --git a/tests/suites/unit/joomla/document/image/logo.gif b/tests/suites/unit/joomla/document/image/logo.gif new file mode 100644 index 0000000000..69f46b52bd Binary files /dev/null and b/tests/suites/unit/joomla/document/image/logo.gif differ diff --git a/tests/suites/unit/joomla/document/image/logo.jpeg b/tests/suites/unit/joomla/document/image/logo.jpeg new file mode 100644 index 0000000000..916a87fe2a Binary files /dev/null and b/tests/suites/unit/joomla/document/image/logo.jpeg differ diff --git a/tests/suites/unit/joomla/document/image/logo.jpg b/tests/suites/unit/joomla/document/image/logo.jpg new file mode 100644 index 0000000000..916a87fe2a Binary files /dev/null and b/tests/suites/unit/joomla/document/image/logo.jpg differ diff --git a/tests/suites/unit/joomla/document/image/logo.png b/tests/suites/unit/joomla/document/image/logo.png new file mode 100644 index 0000000000..28a8eae2d5 Binary files /dev/null and b/tests/suites/unit/joomla/document/image/logo.png differ