PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / rosell-dk / webp-convert / tests / Convert / Converters / EwwwTest.php

EwwwTest.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/EwwwTest.php

98 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * WebPConvert - Convert JPEG & PNG to WebP with PHP
5 *
6 * @link https://github.com/rosell-dk/webp-convert
7 * @license MIT
8 */
9
10 namespace WebPConvert\Tests\Convert\Converters;
11
12 use WebPConvert\Convert\Converters\Ewww;
13 use PHPUnit\Framework\TestCase;
14 use WebPConvert\Convert\Exceptions\ConversionFailed\ConverterNotOperational\InvalidApiKeyException;
15 use WebPConvert\Tests\Convert\TestConverters\ExtendedConverters\EwwwExtended;
16
17 class EwwwTest extends TestCase
18 {
19
20 public static function getImageFolder()
21 {
22 return realpath(__DIR__ . '/../../images');
23 }
24
25 public static function getImagePath($image)
26 {
27 return self::getImageFolder() . '/' . $image;
28 }
29
30 public function testConvert()
31 {
32 ConverterTestHelper::runAllConvertTests($this, 'Ewww', [
33 //'api-key' => ''
34 ]);
35 }
36
37 public function testConvertInvalidKeyLessThan20()
38 {
39 $this->expectException(InvalidApiKeyException::class);
40
41 $source = self::getImagePath('test.png');
42 Ewww::convert($source, $source . '.webp', [
43 'api-key' => 'wrong-key!'
44 ]);
45 }
46
47 public function testConvertInvalidKeyLess32()
48 {
49 $this->expectException(InvalidApiKeyException::class);
50
51 $wrongKeyRightLength = 'invalid-key-but-hasright-length';
52
53 $source = self::getImagePath('test.png');
54 Ewww::convert($source, $source . '.webp', [
55 'api-key' => $wrongKeyRightLength
56 ]);
57 }
58
59 public function testConvertInvalidKeyDuringConversion()
60 {
61 $this->expectException(InvalidApiKeyException::class);
62
63 $wrongKeyRightLength = 'invalid-key-but-hasright-length';
64
65 $source = self::getImagePath('test.png');
66
67 $ee = EwwwExtended::createInstance($source, $source . '.webp', [
68 'api-key' => $wrongKeyRightLength
69 ]);
70
71 $ee->callDoActualConvert();
72 }
73
74
75 public function testIsValidKey()
76 {
77 $invalidKey = 'notvalidno';
78 $this->assertFalse(Ewww::isValidKey($invalidKey));
79
80 $demoKey = 'abc123';
81 $this->assertTrue(Ewww::isValidKey($demoKey));
82
83
84 //InvalidApiKeyException
85 }
86
87 public function testIsWorkingKey()
88 {
89 $invalidKey = 'notvalidno';
90 $this->assertFalse(Ewww::isWorkingKey($invalidKey));
91
92 if (!empty(getenv('WEBPCONVERT_EWWW_API_KEY'))) {
93 $realWorkingKey = getenv('WEBPCONVERT_EWWW_API_KEY');
94 $this->assertTrue(Ewww::isWorkingKey($realWorkingKey));
95 }
96 }
97 }
98