| 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 |
|