class OrderCustomerTest in Commerce Core 8.2
@coversDefaultClass \Drupal\commerce_order\Plugin\Commerce\Condition\OrderCustomer @group commerce
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\commerce_order\Unit\Plugin\Commerce\Condition\OrderCustomerTest
Expanded class hierarchy of OrderCustomerTest
File
- modules/
order/ tests/ src/ Unit/ Plugin/ Commerce/ Condition/ OrderCustomerTest.php, line 17
Namespace
Drupal\Tests\commerce_order\Unit\Plugin\Commerce\ConditionView source
class OrderCustomerTest extends UnitTestCase {
/**
* ::covers evaluate.
*/
public function testEvaluate() {
$entity_type_manager = $this
->prophesize(EntityTypeManagerInterface::class);
$entity_type_manager = $entity_type_manager
->reveal();
$entity_uuid_mapper = $this
->prophesize(EntityUuidMapperInterface::class);
$entity_uuid_mapper = $entity_uuid_mapper
->reveal();
$condition = new OrderCustomer([
'entities' => [],
], 'order_customer', [
'entity_type' => 'commerce_order',
], $entity_type_manager, $entity_uuid_mapper);
$customer = $this
->prophesize(UserInterface::class);
$customer
->uuid()
->willReturn('');
$customer = $customer
->reveal();
$order = $this
->buildOrder($customer);
$this
->assertFalse($condition
->evaluate($order));
// Set two UUIDs, one of which will match the customer.
$condition
->setConfiguration([
'entities' => [
'20363dff-479a-40a1-afcb-1f5f7b9e280c',
'2141473e-c62a-455e-9388-4cf3858fbde1',
],
]);
$customer = $this
->prophesize(UserInterface::class);
$customer
->uuid()
->willReturn('20363dff-479a-40a1-afcb-1f5f7b9e280c');
$customer = $customer
->reveal();
$order = $this
->buildOrder($customer);
$this
->assertTrue($condition
->evaluate($order));
// Set two UUIDs that won't match the customer.
$condition
->setConfiguration([
'entities' => [
'6c0556de-b867-4fd1-8d03-56c818944bfc',
'd540ae0e-ec45-4ca8-91d7-7882ccafbf57',
],
]);
$order = $this
->buildOrder($customer);
$this
->assertFalse($condition
->evaluate($order));
}
/**
* Builds a mock order with the given customer.
*
* @param \Drupal\Core\Session\AccountInterface $customer
* The customer account.
*
* @return \Drupal\commerce_order\Entity\OrderInterface
* The mock order.
*/
protected function buildOrder(AccountInterface $customer) {
$order = $this
->prophesize(OrderInterface::class);
$order
->getEntityTypeId()
->willReturn('commerce_order');
$order
->getCustomer()
->willReturn($customer);
$order = $order
->reveal();
return $order;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OrderCustomerTest:: |
protected | function | Builds a mock order with the given customer. | |
OrderCustomerTest:: |
public | function | ::covers evaluate. | |
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 |