| 1 |
<?php |
| 2 |
|
| 3 |
namespace Extendify\Tests\Integration\Shared\Services\PluginsActivation; |
| 4 |
|
| 5 |
use Extendify\Shared\Services\PluginsActivation\Imagify; |
| 6 |
use ReflectionMethod; |
| 7 |
use WP_UnitTestCase; |
| 8 |
|
| 9 |
class ImagifyTest extends WP_UnitTestCase |
| 10 |
{ |
| 11 |
private static function saveKey(array $data) |
| 12 |
{ |
| 13 |
$method = new ReflectionMethod(Imagify::class, 'saveKey'); |
| 14 |
$method->setAccessible(true); |
| 15 |
$method->invoke(null, $data); |
| 16 |
} |
| 17 |
|
| 18 |
public function test_save_key_stores_api_key_when_settings_absent() |
| 19 |
{ |
| 20 |
self::saveKey(['api_key' => 'abc123']); |
| 21 |
|
| 22 |
$this->assertSame(['api_key' => 'abc123'], get_option('imagify_settings')); |
| 23 |
} |
| 24 |
|
| 25 |
public function test_save_key_preserves_existing_settings() |
| 26 |
{ |
| 27 |
update_option('imagify_settings', ['optimization_level' => 2, 'api_key' => 'old']); |
| 28 |
|
| 29 |
self::saveKey(['api_key' => 'new456']); |
| 30 |
|
| 31 |
$this->assertSame( |
| 32 |
['optimization_level' => 2, 'api_key' => 'new456'], |
| 33 |
get_option('imagify_settings') |
| 34 |
); |
| 35 |
} |
| 36 |
|
| 37 |
public function test_save_key_does_nothing_without_api_key() |
| 38 |
{ |
| 39 |
update_option('imagify_settings', ['optimization_level' => 2]); |
| 40 |
|
| 41 |
self::saveKey([]); |
| 42 |
|
| 43 |
$this->assertSame(['optimization_level' => 2], get_option('imagify_settings')); |
| 44 |
} |
| 45 |
} |
| 46 |
|