You are here

class OrderCustomerTest in Commerce Core 8.2

@coversDefaultClass \Drupal\commerce_order\Plugin\Commerce\Condition\OrderCustomer @group commerce

Hierarchy

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\Condition
View 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

Namesort descending Modifiers Type Description Overrides
OrderCustomerTest::buildOrder protected function Builds a mock order with the given customer.
OrderCustomerTest::testEvaluate public function ::covers evaluate.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340