diff options
author | Mario <mario@mariovavti.com> | 2020-11-26 08:43:03 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2020-11-26 08:43:03 +0000 |
commit | 21cd4a1b4845858c3421dbd5f2673eceee421f5d (patch) | |
tree | 56d80b7e16f99d8037e8ff48431aa9d191ff39dd /Tests/Unit/Photo | |
parent | e9a50371f5dd4cffb0ba4894f2286b28e8f535b9 (diff) | |
download | volse-hubzilla-21cd4a1b4845858c3421dbd5f2673eceee421f5d.tar.gz volse-hubzilla-21cd4a1b4845858c3421dbd5f2673eceee421f5d.tar.bz2 volse-hubzilla-21cd4a1b4845858c3421dbd5f2673eceee421f5d.zip |
psr-4 autoloading standard
Diffstat (limited to 'Tests/Unit/Photo')
-rw-r--r-- | Tests/Unit/Photo/PhotoGdTest.php | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/Tests/Unit/Photo/PhotoGdTest.php b/Tests/Unit/Photo/PhotoGdTest.php new file mode 100644 index 000000000..ae7382c43 --- /dev/null +++ b/Tests/Unit/Photo/PhotoGdTest.php @@ -0,0 +1,147 @@ +<?php + +namespace Zotlabs\Tests\Unit\Photo; + +use Zotlabs\Photo\PhotoGd; +use phpmock\phpunit\PHPMock; +use Zotlabs\Tests\Unit\UnitTestCase; + +/** + * @brief PhotoGd test case. + * + * These tests are not really useful yet, just some obvious behaviour. + * + * @todo Compare the actual results. + * @todo Test different image types. + */ +class PhotoGdTest extends UnitTestCase { + + use PHPMock; + + /** + * @var PhotoGd + */ + private $photoGd; + + /** + * Prepares the environment before running a test. + */ + protected function setUp(): void { + parent::setUp(); + + $data = file_get_contents('images/hz-16.png'); + + $this->photoGd = new PhotoGd($data, 'image/png'); + } + + /** + * Cleans up the environment after running a test. + */ + protected function tearDown(): void { + $this->photoGd = null; + + parent::tearDown(); + } + + /** + * Tests PhotoGd->supportedTypes() + * + * Without mocking gd this check is environment dependent. + * + public function testSupportedTypes() { + $sft = $this->photoGd->supportedTypes(); + + $this->assertArrayHasKey('image/jpeg', $sft); + $this->assertArrayHasKey('image/gif', $sft); + $this->assertArrayHasKey('image/png', $sft); + + $this->assertArrayNotHasKey('image/foo', $sft); + } + */ + + /** + * Tests PhotoGd->clearexif() + */ + public function testClearexifIsNotImplementedInGdAndDoesNotAlterImageOrReturnSomething() { + $data_before = $this->photoGd->getImage(); + $this->assertNull($this->photoGd->clearexif()); + $this->assertSame($data_before, $this->photoGd->getImage()); + } + + /** + * Tests PhotoGd->getImage() + */ + public function testGetimageReturnsAResource() { + $res = $this->photoGd->getImage(); + $this->assertIsResource($res); + $this->assertEquals('gd', get_resource_type($res)); + } + public function testGetimageReturnsFalseOnFailure() { + $this->photoGd = new PhotoGd(''); + $this->assertFalse($this->photoGd->getImage()); + } + + /** + * Tests PhotoGd->doScaleImage() + */ + public function testDoscaleImageSetsCorrectDimensions() { + $this->photoGd->doScaleImage(5, 8); + + $this->assertSame(5, $this->photoGd->getWidth()); + $this->assertSame(8, $this->photoGd->getHeight()); + } + + /** + * Tests PhotoGd->rotate() + */ + public function testRotate360DegreesCreatesANewImage() { + $data = $this->photoGd->getImage(); + $this->photoGd->rotate(360); + $this->assertNotEquals($data, $this->photoGd->getImage()); + } + + /** + * Tests PhotoGd->flip() + * + public function testFlip() { + // TODO Auto-generated PhotoGdTest->testFlip() + $this->markTestIncomplete("flip test not implemented"); + + $this->photoGd->flip(); + } + */ + + /** + * Tests PhotoGd->cropImageRect() + */ + public function testCropimagerectSetsCorrectDimensions() { + $this->photoGd->cropImageRect(10, 12, 1, 2, 11, 11); + + $this->assertSame(10, $this->photoGd->getWidth()); + $this->assertSame(12, $this->photoGd->getHeight()); + } + + /** + * Tests PhotoGd->imageString() + */ + public function testImagestringReturnsABinaryString() { + // Create a stub for global function get_config() + // get_config('system', 'png_quality') + // get_config('system', 'jpeg_quality'); + $gc = $this->getFunctionMock('Zotlabs\Photo', 'get_config'); + $gc->expects($this->once())->willReturnCallback( + function() { + switch($this->photoGd->getType()){ + case 'image/png': + return 7; + case 'image/jpeg': + default: + return 70; + } + } + ); + + $this->assertIsString($this->photoGd->imageString()); + } + +} |