Files
piratepoet/mailpoet/tests/unit/API/JSON/PremiumTest.php
Rodrigo Primo 1865fc8930 Replace expect()->isInstanceOf() with verify()->instanceOf()
codeception/verify 2.1 removed support for expect()->isInstanceOf() so we need
to replace it with verify()->instanceOf().

[MAILPOET-5664]
2023-10-24 08:58:22 +03:00

136 lines
4.5 KiB
PHP

<?php declare(strict_types = 1);
namespace MailPoet\Test\API\JSON;
use Codeception\Stub\Expected;
use MailPoet\API\JSON\ErrorResponse;
use MailPoet\API\JSON\SuccessResponse;
use MailPoet\API\JSON\v1\Premium;
use MailPoet\Config\ServicesChecker;
use MailPoet\WP\Functions as WPFunctions;
use MailPoet\WPCOM\DotcomHelperFunctions;
class PremiumTest extends \MailPoetUnitTest {
public function testItInstallsPlugin() {
$servicesChecker = $this->makeEmpty(ServicesChecker::class, [
'isPremiumKeyValid' => Expected::once(true),
]);
$wp = $this->make(WPFunctions::class, [
'pluginsApi' => Expected::once([
'download_link' => 'https://some-download-link',
]),
'installPlugin' => Expected::once(true),
]);
$premium = new Premium($servicesChecker, $wp, new DotcomHelperFunctions());
$response = $premium->installPlugin();
verify($response)->instanceOf(SuccessResponse::class);
}
public function testInstallationFailsWhenKeyInvalid() {
$servicesChecker = $this->makeEmpty(ServicesChecker::class, [
'isPremiumKeyValid' => Expected::once(false),
]);
$wp = $this->make(WPFunctions::class, [
'pluginsApi' => Expected::never(),
'installPlugin' => Expected::never(),
]);
$premium = new Premium($servicesChecker, $wp, new DotcomHelperFunctions());
$response = $premium->installPlugin();
verify($response)->instanceOf(ErrorResponse::class);
verify($response->getData()['errors'][0])->same([
'error' => 'bad_request',
'message' => 'Premium key is not valid.',
]);
}
public function testInstallationFailsWhenNoPluginInfo() {
$servicesChecker = $this->makeEmpty(ServicesChecker::class, [
'isPremiumKeyValid' => Expected::once(true),
]);
$wp = $this->make(WPFunctions::class, [
'pluginsApi' => Expected::once(null),
'installPlugin' => Expected::never(),
]);
$premium = new Premium($servicesChecker, $wp, new DotcomHelperFunctions());
$response = $premium->installPlugin();
verify($response)->instanceOf(ErrorResponse::class);
verify($response->getData()['errors'][0])->same([
'error' => 'bad_request',
'message' => 'Error when installing MailPoet Premium plugin.',
]);
}
public function testInstallationFailsOnError() {
$servicesChecker = $this->makeEmpty(ServicesChecker::class, [
'isPremiumKeyValid' => Expected::once(true),
]);
$wp = $this->make(WPFunctions::class, [
'pluginsApi' => Expected::once([
'download_link' => 'https://some-download-link',
]),
'installPlugin' => Expected::once(false),
]);
$premium = new Premium($servicesChecker, $wp, new DotcomHelperFunctions());
$response = $premium->installPlugin();
verify($response)->instanceOf(ErrorResponse::class);
verify($response->getData()['errors'][0])->same([
'error' => 'bad_request',
'message' => 'Error when installing MailPoet Premium plugin.',
]);
}
public function testItActivatesPlugin() {
$servicesChecker = $this->makeEmpty(ServicesChecker::class, [
'isPremiumKeyValid' => Expected::once(true),
]);
$wp = $this->make(WPFunctions::class, [
'activatePlugin' => Expected::once(null),
]);
$premium = new Premium($servicesChecker, $wp, new DotcomHelperFunctions());
$response = $premium->activatePlugin();
verify($response)->instanceOf(SuccessResponse::class);
}
public function testActivationFailsWhenKeyInvalid() {
$servicesChecker = $this->makeEmpty(ServicesChecker::class, [
'isPremiumKeyValid' => Expected::once(false),
]);
$premium = new Premium($servicesChecker, new WPFunctions(), new DotcomHelperFunctions());
$response = $premium->activatePlugin();
verify($response)->instanceOf(ErrorResponse::class);
verify($response->getData()['errors'][0])->same([
'error' => 'bad_request',
'message' => 'Premium key is not valid.',
]);
}
public function testActivationFailsOnError() {
$servicesChecker = $this->makeEmpty(ServicesChecker::class, [
'isPremiumKeyValid' => Expected::once(true),
]);
$wp = $this->make(WPFunctions::class, [
'activatePlugin' => Expected::once('error'),
]);
$premium = new Premium($servicesChecker, $wp, new DotcomHelperFunctions());
$response = $premium->activatePlugin();
verify($response)->instanceOf(ErrorResponse::class);
verify($response->getData()['errors'][0])->same([
'error' => 'bad_request',
'message' => 'Error when activating MailPoet Premium plugin.',
]);
}
}