Files
piratepoet/mailpoet/tests/integration/Segments/SegmentDependencyValidatorTest.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

58 lines
2.2 KiB
PHP

<?php declare(strict_types = 1);
namespace MailPoet\Segments;
use MailPoet\Entities\DynamicSegmentFilterData;
use MailPoet\Entities\DynamicSegmentFilterEntity;
use MailPoet\Entities\SegmentEntity;
use MailPoet\Segments\DynamicSegments\Filters\WooCommerceCategory;
use MailPoet\Util\License\Features\Subscribers as SubscribersFeature;
use MailPoet\WP\Functions as WPFunctions;
class SegmentDependencyValidatorTest extends \MailPoetTest {
public function testItMissingPluginsForWooCommerceDynamicSegment(): void {
$dynamicSegment = $this->createSegment(
DynamicSegmentFilterData::TYPE_WOOCOMMERCE,
WooCommerceCategory::ACTION_CATEGORY,
[
'category_ids' => ['1'],
'operator' => DynamicSegmentFilterData::OPERATOR_ANY,
]
);
// Plugin is not active
$validator = $this->createValidator(false);
$missingPlugins = $validator->getMissingPluginsBySegment($dynamicSegment);
verify($missingPlugins)->equals(['WooCommerce']);
// Plugin is active
$validator = $this->createValidator(true);
$missingPlugins = $validator->getMissingPluginsBySegment($dynamicSegment);
verify($missingPlugins)->equals([]);
}
private function createSegment(string $filterType, string $action, array $filterData): SegmentEntity {
$segment = new SegmentEntity('Dynamic Segment', SegmentEntity::TYPE_DYNAMIC, 'description');
$this->entityManager->persist($segment);
$filterData = new DynamicSegmentFilterData($filterType, $action, $filterData);
$dynamicSegmentFilter = new DynamicSegmentFilterEntity($segment, $filterData);
$this->entityManager->persist($dynamicSegmentFilter);
$segment->addDynamicFilter($dynamicSegmentFilter);
return $segment;
}
private function createValidator(
bool $isPluginActive,
bool $hasValidPremiumKey = true,
bool $subscribersLimitReached = false
): SegmentDependencyValidator {
$wp = $this->make(WPFunctions::class, [
'isPluginActive' => $isPluginActive,
]);
$subscribersFeature = $this->make(SubscribersFeature::class, [
'hasValidPremiumKey' => $hasValidPremiumKey,
'check' => $subscribersLimitReached,
]);
return new SegmentDependencyValidator($subscribersFeature, $wp);
}
}