wp-optimize
/
vendor
/
rosell-dk
/
webp-convert
/
tests
/
Convert
/
Converters
/
GraphicsMagickTest.php
GraphicsMagickTest.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at vendor/rosell-dk/webp-convert/tests/Convert/Converters/GraphicsMagickTest.php
| 1 | <?php |
| 2 | /** |
| 3 | * WebPConvert - Convert JPEG & PNG to WebP with PHP |
| 4 | * |
| 5 | * @link https://github.com/rosell-dk/webp-convert |
| 6 | * @license MIT |
| 7 | */ |
| 8 | |
| 9 | namespace WebPConvert\Tests\Convert\Converters; |
| 10 | |
| 11 | use WebPConvert\Convert\Converters\GraphicsMagick; |
| 12 | use WebPConvert\Convert\Exceptions\ConversionFailed\ConverterNotOperationalException; |
| 13 | use WebPConvert\Loggers\BufferLogger; |
| 14 | |
| 15 | use PHPUnit\Framework\TestCase; |
| 16 | |
| 17 | /** |
| 18 | * @coversDefaultClass WebPConvert\Convert\Converters\GraphicsMagick |
| 19 | * @covers WebPConvert\Convert\Converters\GraphicsMagick |
| 20 | */ |
| 21 | class GraphicsMagickTest extends TestCase |
| 22 | { |
| 23 | |
| 24 | public static function getImageFolder() |
| 25 | { |
| 26 | return realpath(__DIR__ . '/../../images'); |
| 27 | } |
| 28 | |
| 29 | public static function getImagePath($image) |
| 30 | { |
| 31 | return self::getImageFolder() . '/' . $image; |
| 32 | } |
| 33 | |
| 34 | public function testConvert() |
| 35 | { |
| 36 | ConverterTestHelper::runAllConvertTests($this, 'GraphicsMagick'); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Try converting. |
| 41 | * It is ok if converter is not operational. |
| 42 | * It is not ok if converter thinks it is operational, but fails |
| 43 | * |
| 44 | * @return $ok |
| 45 | * @throws ConversionFailedException if convert throws it |
| 46 | */ |
| 47 | private static function tryThis($test, $source, $options) |
| 48 | { |
| 49 | $bufferLogger = new BufferLogger(); |
| 50 | |
| 51 | try { |
| 52 | GraphicsMagick::convert($source, $source . '.webp', $options, $bufferLogger); |
| 53 | } catch (ConversionFailedException $e) { |
| 54 | |
| 55 | //$bufferLogger->getText() |
| 56 | throw $e; |
| 57 | } catch (ConverterNotOperationalException $e) { |
| 58 | // (SystemRequirementsNotMetException is also a ConverterNotOperationalException) |
| 59 | // this is ok. |
| 60 | return true; |
| 61 | } |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | public function testWithNice() { |
| 66 | $source = self::getImagePath('test.png'); |
| 67 | $options = [ |
| 68 | 'use-nice' => true, |
| 69 | 'lossless' => true, |
| 70 | ]; |
| 71 | $this->assertTrue(self::tryThis($this, $source, $options)); |
| 72 | } |
| 73 | |
| 74 | } |
| 75 |