Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SortOrderTest.php
Go to the documentation of this file.
1 <?php
8 
10 
14 class SortOrderTest extends \PHPUnit\Framework\TestCase
15 {
19  private $sortOrder;
20 
21  protected function setUp()
22  {
23  $this->sortOrder = new SortOrder();
24  }
25 
27  {
28  $this->assertNull($this->sortOrder->getDirection());
29  }
30 
35  {
36  $this->sortOrder->setDirection($sortOrder);
37  $this->assertSame($sortOrder, $this->sortOrder->getDirection());
38  }
39 
43  public function sortOrderDirectionProvider()
44  {
46  }
47 
53  public function testItThrowsAnExceptionIfAnInvalidSortOrderIsSet($invalidDirection)
54  {
55  $this->sortOrder->setDirection($invalidDirection);
56  }
57 
61  public function invalidSortDirectionProvider()
62  {
63  return [
64  [-1],
65  [1],
66  [0],
67  [true],
68  [false],
69  [[]],
70  ];
71  }
72 
74  {
75  $this->sortOrder->setDirection(strtolower(SortOrder::SORT_ASC));
76  $this->assertSame(SortOrder::SORT_ASC, $this->sortOrder->getDirection());
77  $this->sortOrder->setDirection(strtoupper(SortOrder::SORT_ASC));
78  $this->assertSame(SortOrder::SORT_ASC, $this->sortOrder->getDirection());
79 
80  $this->sortOrder->setDirection(strtolower(SortOrder::SORT_DESC));
81  $this->assertSame(SortOrder::SORT_DESC, $this->sortOrder->getDirection());
82  $this->sortOrder->setDirection(strtoupper(SortOrder::SORT_DESC));
83  $this->assertSame(SortOrder::SORT_DESC, $this->sortOrder->getDirection());
84  }
85 
90  {
91  $this->sortOrder = new SortOrder([
92  SortOrder::DIRECTION => 'not-asc-or-desc'
93  ]);
94  }
95 
99  public function testValidateField()
100  {
101  $this->sortOrder = new SortOrder([
102  SortOrder::FIELD => 'invalid field (value);'
103  ]);
104  }
105 }
testItThrowsAnExceptionIfAnInvalidSortOrderIsSet($invalidDirection)