class ConditionGroupTest in Commerce Core 8.2
@coversDefaultClass \Drupal\commerce\ConditionGroup @group commerce
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\commerce\Unit\ConditionGroupTest
Expanded class hierarchy of ConditionGroupTest
File
- tests/
src/ Unit/ ConditionGroupTest.php, line 15
Namespace
Drupal\Tests\commerce\UnitView source
class ConditionGroupTest extends UnitTestCase {
/**
* ::covers __construct.
*/
public function testInvalidOperator() {
$this
->expectException(\InvalidArgumentException::class);
new ConditionGroup([], 'INVALID');
}
/**
* ::covers getConditions
* ::covers getOperator.
*/
public function testGetters() {
$conditions = [];
$conditions[] = new OrderTotalPrice([
'operator' => '>',
'amount' => [
'number' => '10',
'currency_code' => 'USD',
],
], 'order_total_price', [
'entity_type' => 'commerce_order',
]);
$condition_group = new ConditionGroup($conditions, 'AND');
$this
->assertEquals($conditions, $condition_group
->getConditions());
$this
->assertEquals('AND', $condition_group
->getOperator());
}
/**
* ::covers evaluate.
*/
public function testEvaluate() {
$conditions = [];
$conditions[] = new OrderTotalPrice([
'operator' => '>',
'amount' => [
'number' => '10',
'currency_code' => 'USD',
],
], 'order_total_price', [
'entity_type' => 'commerce_order',
]);
$conditions[] = new OrderTotalPrice([
'operator' => '<',
'amount' => [
'number' => '100',
'currency_code' => 'USD',
],
], 'order_total_price', [
'entity_type' => 'commerce_order',
]);
$first_order = $this
->prophesize(OrderInterface::class);
$first_order
->getEntityTypeId()
->willReturn('commerce_order');
$first_order
->getTotalPrice()
->willReturn(new Price('101', 'USD'));
$first_order = $first_order
->reveal();
$second_order_item = $this
->prophesize(OrderInterface::class);
$second_order_item
->getEntityTypeId()
->willReturn('commerce_order');
$second_order_item
->getTotalPrice()
->willReturn(new Price('90', 'USD'));
$second_order_item = $second_order_item
->reveal();
$empty_condition_group = new ConditionGroup([], 'AND');
$this
->assertTrue($empty_condition_group
->evaluate($first_order));
$and_condition_group = new ConditionGroup($conditions, 'AND');
$this
->assertFalse($and_condition_group
->evaluate($first_order));
$this
->assertTrue($and_condition_group
->evaluate($second_order_item));
$or_condition_group = new ConditionGroup($conditions, 'OR');
$this
->assertTrue($or_condition_group
->evaluate($first_order));
$this
->assertTrue($or_condition_group
->evaluate($second_order_item));
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConditionGroupTest:: |
public | function | ::covers evaluate. | |
ConditionGroupTest:: |
public | function | ::covers getConditions ::covers getOperator. | |
ConditionGroupTest:: |
public | function | ::covers __construct. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |