You are here

public function AdjustmentTest::testGetters in Commerce Core 8.2

Tests getters.

@covers ::getType @covers ::getLabel @covers ::getAmount @covers ::isPositive @covers ::isNegative @covers ::getPercentage @covers ::getSourceId @covers ::isIncluded @covers ::isLocked @covers ::toArray

File

modules/order/tests/src/Kernel/AdjustmentTest.php, line 119

Class

AdjustmentTest
@coversDefaultClass \Drupal\commerce_order\Adjustment @group commerce

Namespace

Drupal\Tests\commerce_order\Kernel

Code

public function testGetters() {
  $definition = [
    'type' => 'custom',
    'label' => '10% off',
    'amount' => new Price('-1.00', 'USD'),
    'percentage' => '0.1',
    'source_id' => '1',
    'included' => TRUE,
    'locked' => TRUE,
  ];
  $adjustment = new Adjustment($definition);
  $this
    ->assertEquals('custom', $adjustment
    ->getType());
  $this
    ->assertEquals('10% off', $adjustment
    ->getLabel());
  $this
    ->assertEquals('-1.00', $adjustment
    ->getAmount()
    ->getNumber());
  $this
    ->assertEquals('USD', $adjustment
    ->getAmount()
    ->getCurrencyCode());
  $this
    ->assertFalse($adjustment
    ->isPositive());
  $this
    ->assertTrue($adjustment
    ->isNegative());
  $this
    ->assertEquals('0.1', $adjustment
    ->getPercentage());
  $this
    ->assertEquals('1', $adjustment
    ->getSourceId());
  $this
    ->assertTrue($adjustment
    ->isIncluded());
  $this
    ->assertTrue($adjustment
    ->isLocked());
  $this
    ->assertEquals($definition, $adjustment
    ->toArray());

  // Test adjustment with percentage equals zero.
  $definition['percentage'] = '0';
  $adjustment = new Adjustment($definition);
  $this
    ->assertEquals('0', $adjustment
    ->getPercentage());
}