Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RouterListTest.php
Go to the documentation of this file.
1 <?php
9 
10 class RouterListTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $model;
16 
20  protected $objectManagerMock;
21 
25  protected $routerList;
26 
27  protected function setUp()
28  {
29  $this->routerList = [
30  'adminRouter' => ['class' => 'AdminClass', 'disable' => true, 'sortOrder' => 10],
31  'frontendRouter' => ['class' => 'FrontClass', 'disable' => false, 'sortOrder' => 10],
32  'default' => ['class' => 'DefaultClass', 'disable' => false, 'sortOrder' => 5],
33  'someRouter' => ['class' => 'SomeClass', 'disable' => false, 'sortOrder' => 10],
34  'anotherRouter' => ['class' => 'AnotherClass', 'disable' => false, 'sortOrder' => 15],
35  ];
36 
37  $this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
38  $this->model = new \Magento\Framework\App\RouterList($this->objectManagerMock, $this->routerList);
39  }
40 
41  public function testCurrent()
42  {
43  $expectedClass = new DefaultClass();
44  $this->objectManagerMock->expects($this->at(0))
45  ->method('create')
46  ->with('DefaultClass')
47  ->will($this->returnValue($expectedClass));
48 
49  $this->assertEquals($expectedClass, $this->model->current());
50  }
51 
52  public function testNext()
53  {
54  $expectedClass = new FrontClass();
55  $this->objectManagerMock->expects($this->at(0))
56  ->method('create')
57  ->with('FrontClass')
58  ->will($this->returnValue($expectedClass));
59 
60  $this->model->next();
61  $this->assertEquals($expectedClass, $this->model->current());
62  }
63 
64  public function testValid()
65  {
66  $this->assertTrue($this->model->valid());
67  $this->model->next();
68  $this->assertTrue($this->model->valid());
69  $this->model->next();
70  $this->assertTrue($this->model->valid());
71  $this->model->next();
72  $this->assertTrue($this->model->valid());
73  $this->model->next();
74  $this->assertFalse($this->model->valid());
75  }
76 
77  public function testRewind()
78  {
79  $frontClass = new FrontClass();
80  $defaultClass = new DefaultClass();
81 
82  $this->objectManagerMock->expects($this->at(0))
83  ->method('create')
84  ->with('DefaultClass')
85  ->will($this->returnValue($defaultClass));
86 
87  $this->objectManagerMock->expects($this->at(1))
88  ->method('create')
89  ->with('FrontClass')
90  ->will($this->returnValue($frontClass));
91 
92  $this->assertEquals($defaultClass, $this->model->current());
93  $this->model->next();
94  $this->assertEquals($frontClass, $this->model->current());
95  $this->model->rewind();
96  $this->assertEquals($defaultClass, $this->model->current());
97  }
98 }