You are here

class ConditionGroupTest in Commerce Core 8.2

@coversDefaultClass \Drupal\commerce\ConditionGroup @group commerce

Hierarchy

Expanded class hierarchy of ConditionGroupTest

File

tests/src/Unit/ConditionGroupTest.php, line 15

Namespace

Drupal\Tests\commerce\Unit
View 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

Namesort descending Modifiers Type Description Overrides
ConditionGroupTest::testEvaluate public function ::covers evaluate.
ConditionGroupTest::testGetters public function ::covers getConditions ::covers getOperator.
ConditionGroupTest::testInvalidOperator public function ::covers __construct.
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