Files
piratepoet/mailpoet/tests/integration/WPCOM/DotcomLicenseProvisionerTest.php
Rodrigo Primo afe378ba22 Replace expect()->equals() with verify()->equals()
codeception/verify 2.1 removed support for expect()->equals() so we need
to replace it with verify()->equals().

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

132 lines
5.2 KiB
PHP

<?php declare(strict_types = 1);
namespace MailPoet\WPCOM;
use MailPoet\API\JSON\ErrorResponse;
use MailPoet\API\JSON\SuccessResponse;
use MailPoet\API\JSON\v1\Services;
use MailPoet\API\JSON\v1\Settings;
use MailPoet\Logging\LoggerFactory;
class DotcomLicenseProvisionerTest extends \MailPoetTest {
/** @var DotcomLicenseProvisioner */
private $provisioner;
public function _before() {
parent::_before();
$this->provisioner = $this->construct(
DotcomLicenseProvisioner::class,
[
$this->diContainer->get(LoggerFactory::class),
$this->make(Settings::class),
$this->make(Services::class),
$this->make(DotcomHelperFunctions::class, ['isAtomicPlatform' => true]),
]);
}
public function testItReturnsResultIfNotAtomic() {
$result = false;
$payload = ['apiKey' => 'some-key'];
$provisioner = $this->construct(
DotcomLicenseProvisioner::class,
[
$this->make(LoggerFactory::class),
$this->make(Settings::class),
$this->make(Services::class),
$this->make(DotcomHelperFunctions::class, ['isAtomicPlatform' => false]),
]);
verify($provisioner->provisionLicense($result, $payload, DotcomLicenseProvisioner::EVENT_TYPE_PROVISION_LICENSE))->equals($result);
}
public function testItReturnsResultIfWrongEvent() {
$result = false;
$payload = ['apiKey' => 'some-key'];
$eventType = 'wrong-event';
verify($this->provisioner->provisionLicense($result, $payload, $eventType))->equals($result);
}
public function testItReturnsWPErrorIfMissingKey() {
$result = false;
$payload = [];
$eventType = DotcomLicenseProvisioner::EVENT_TYPE_PROVISION_LICENSE;
$error = $this->provisioner->provisionLicense($result, $payload, $eventType);
$this->assertInstanceOf(\WP_Error::class, $error);
verify($error->get_error_message())->equals('Invalid license payload: Missing API key.');
}
public function testItReturnsWPErrorIfErrorOnSettingUpMSS() {
$result = false;
$payload = ['apiKey' => 'some-key'];
$eventType = DotcomLicenseProvisioner::EVENT_TYPE_PROVISION_LICENSE;
$provisioner = $this->construct(
DotcomLicenseProvisioner::class,
[
$this->diContainer->get(LoggerFactory::class),
$this->make(Settings::class, ['setKeyAndSetupMss' => new ErrorResponse(['error' => 'some-error'])]),
$this->make(Services::class, ['refreshMSSKeyStatus' => new SuccessResponse()]),
$this->make(DotcomHelperFunctions::class, ['isAtomicPlatform' => true]),
]);
$error = $provisioner->provisionLicense($result, $payload, $eventType);
$this->assertInstanceOf(\WP_Error::class, $error);
verify($error->get_error_message())->equals('some-error ');
}
public function testItReturnsErrorIfCouldNotRefreshKey() {
$result = false;
$payload = ['apiKey' => 'some-key'];
$eventType = DotcomLicenseProvisioner::EVENT_TYPE_PROVISION_LICENSE;
$provisioner = $this->construct(
DotcomLicenseProvisioner::class,
[
$this->diContainer->get(LoggerFactory::class),
$this->make(Settings::class, ['setKeyAndSetupMss' => new SuccessResponse()]),
$this->make(Services::class, ['refreshMSSKeyStatus' => new ErrorResponse(['error' => 'some-error'])]),
$this->make(DotcomHelperFunctions::class, ['isAtomicPlatform' => true]),
]);
$error = $provisioner->provisionLicense($result, $payload, $eventType);
$this->assertInstanceOf(\WP_Error::class, $error);
verify($error->get_error_message())->equals('some-error ');
}
public function testItReturnsErrorIfCouldNotVerifyPremiumKey() {
$result = false;
$payload = ['apiKey' => 'some-key'];
$eventType = DotcomLicenseProvisioner::EVENT_TYPE_PROVISION_LICENSE;
$provisioner = $this->construct(
DotcomLicenseProvisioner::class,
[
$this->diContainer->get(LoggerFactory::class),
$this->make(Settings::class, ['setKeyAndSetupMss' => new SuccessResponse()]),
$this->make(Services::class,
[
'refreshMSSKeyStatus' => new SuccessResponse(),
'refreshPremiumKeyStatus' => new ErrorResponse(['error' => 'some-error']),
]),
$this->make(DotcomHelperFunctions::class, ['isAtomicPlatform' => true]),
]);
$error = $provisioner->provisionLicense($result, $payload, $eventType);
$this->assertInstanceOf(\WP_Error::class, $error);
verify($error->get_error_message())->equals('some-error ');
}
public function testItReturnsTrueIfKeyProvidedMSSActivatedAndRefreshed() {
$result = false;
$payload = ['apiKey' => 'some-key'];
$eventType = DotcomLicenseProvisioner::EVENT_TYPE_PROVISION_LICENSE;
$provisioner = $this->construct(
DotcomLicenseProvisioner::class,
[
$this->diContainer->get(LoggerFactory::class),
$this->make(Settings::class, ['setKeyAndSetupMss' => new SuccessResponse()]),
$this->make(Services::class,
[
'refreshMSSKeyStatus' => new SuccessResponse(),
'refreshPremiumKeyStatus' => new SuccessResponse(),
]),
$this->make(DotcomHelperFunctions::class, ['isAtomicPlatform' => true]),
]);
$result = $provisioner->provisionLicense($result, $payload, $eventType);
verify($result)->equals(true);
}
}