public function PriceTest::testComparison in Commerce Core 8.2
Tests the comparison methods.
::covers isPositive ::covers isNegative ::covers isZero ::covers equals ::covers greaterThan ::covers greaterThanOrEqual ::covers lessThan ::covers lessThanOrEqual ::covers compareTo.
File
- modules/
price/ tests/ src/ Unit/ PriceTest.php, line 149
Class
- PriceTest
- Tests the Price class.
Namespace
Drupal\Tests\commerce_price\UnitCode
public function testComparison() {
$this
->assertTrue($this->price
->isPositive());
$this
->assertFalse($this->price
->isNegative());
$this
->assertFalse($this->price
->isZero());
$negative_price = new Price('-10', 'USD');
$this
->assertFalse($negative_price
->isPositive());
$this
->assertTrue($negative_price
->isNegative());
$this
->assertFalse($negative_price
->isZero());
$zero_price = new Price('0', 'USD');
$this
->assertFalse($zero_price
->isPositive());
$this
->assertFalse($zero_price
->isNegative());
$this
->assertTrue($zero_price
->isZero());
$this
->assertNotEmpty($this->price
->equals(new Price('10', 'USD')));
$this
->assertEmpty($this->price
->equals(new Price('15', 'USD')));
$this
->assertNotEmpty($this->price
->greaterThan(new Price('5', 'USD')));
$this
->assertEmpty($this->price
->greaterThan(new Price('10', 'USD')));
$this
->assertEmpty($this->price
->greaterThan(new Price('15', 'USD')));
$this
->assertNotEmpty($this->price
->greaterThanOrEqual(new Price('5', 'USD')));
$this
->assertNotEmpty($this->price
->greaterThanOrEqual(new Price('10', 'USD')));
$this
->assertEmpty($this->price
->greaterThanOrEqual(new Price('15', 'USD')));
$this
->assertNotEmpty($this->price
->lessThan(new Price('15', 'USD')));
$this
->assertEmpty($this->price
->lessThan(new Price('10', 'USD')));
$this
->assertEmpty($this->price
->lessThan(new Price('5', 'USD')));
$this
->assertNotEmpty($this->price
->lessThanOrEqual(new Price('15', 'USD')));
$this
->assertNotEmpty($this->price
->lessThanOrEqual(new Price('10', 'USD')));
$this
->assertEmpty($this->price
->lessThanOrEqual(new Price('5', 'USD')));
}