Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AreaListTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Framework\App\AreaList;
10 
11 class AreaListTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $_model;
17 
21  protected $_resolverFactory;
22 
26  protected $objectManagerMock;
27 
28  protected function setUp()
29  {
30  $this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
31  $this->_resolverFactory = $this
32  ->createMock(\Magento\Framework\App\Area\FrontNameResolverFactory::class);
33  }
34 
36  {
37  $expected = 'expectedFrontName';
38  $this->_model = new \Magento\Framework\App\AreaList(
39  $this->objectManagerMock,
40  $this->_resolverFactory,
41  ['testArea' => ['frontNameResolver' => 'testValue']],
42  $expected
43  );
44 
45  $resolverMock = $this->createMock(\Magento\Framework\App\Area\FrontNameResolverInterface::class);
46  $this->_resolverFactory->expects(
47  $this->any()
48  )->method(
49  'create'
50  )->with(
51  'testValue'
52  )->will(
53  $this->returnValue($resolverMock)
54  );
55 
56  $actual = $this->_model->getCodeByFrontName('testFrontName');
57  $this->assertEquals($expected, $actual);
58  }
59 
61  {
62  $expected = 'testArea';
63  $this->_model = new \Magento\Framework\App\AreaList(
64  $this->objectManagerMock,
65  $this->_resolverFactory,
66  ['testArea' => ['frontName' => 'testFrontName']],
67  $expected
68  );
69 
70  $actual = $this->_model->getCodeByFrontName('testFrontName');
71  $this->assertEquals($expected, $actual);
72  }
73 
75  {
76  $expected = 'testFrontName';
77  $this->_model = new \Magento\Framework\App\AreaList(
78  $this->objectManagerMock,
79  $this->_resolverFactory,
80  ['testAreaCode' => ['frontName' => 'testFrontName']],
81  $expected
82  );
83 
84  $actual = $this->_model->getFrontName('testAreaCode');
85  $this->assertEquals($expected, $actual);
86  }
87 
89  {
90  $model = new \Magento\Framework\App\AreaList($this->objectManagerMock, $this->_resolverFactory);
91  $code = 'testAreaCode';
92  $this->assertNull($model->getCodeByFrontName($code));
93  $this->assertNull($model->getFrontName($code));
94  $this->assertSame([], $model->getCodes());
95  $this->assertNull($model->getDefaultRouter($code));
96  $this->objectManagerMock->expects($this->once())
97  ->method('create')
98  ->with(\Magento\Framework\App\AreaInterface::class, ['areaCode' => $code])
99  ->willReturn('test');
100  $this->assertSame('test', $model->getArea($code));
101  }
102 
103  public function testGetCodes()
104  {
105  $areas = ['area1' => 'value1', 'area2' => 'value2'];
106  $this->_model = new \Magento\Framework\App\AreaList(
107  $this->objectManagerMock,
108  $this->_resolverFactory,
109  $areas,
110  ''
111  );
112 
113  $expected = array_keys($areas);
114  $actual = $this->_model->getCodes();
115  $this->assertEquals($expected, $actual);
116  }
117 
118  public function testGetDefaultRouter()
119  {
120  $areas = ['area1' => ['router' => 'value1'], 'area2' => 'value2'];
121  $this->_model = new \Magento\Framework\App\AreaList(
122  $this->objectManagerMock,
123  $this->_resolverFactory,
124  $areas,
125  ''
126  );
127 
128  $this->assertEquals($this->_model->getDefaultRouter('area1'), $areas['area1']['router']);
129  $this->assertNull($this->_model->getDefaultRouter('area2'));
130  }
131 
132  public function testGetArea()
133  {
136  $areas = ['area1' => ['router' => 'value1'], 'area2' => 'value2'];
137  $this->_model = new AreaList(
139  $this->_resolverFactory,
140  $areas,
141  ''
142  );
143 
144  $this->assertEquals($this->_model->getArea('testArea'), 'ok');
145  }
146 
150  protected function getObjectManagerMockGetArea()
151  {
152  $objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
154  ->expects($this->any())
155  ->method('create')
156  ->with(
157  $this->equalTo(\Magento\Framework\App\AreaInterface::class),
158  $this->equalTo(['areaCode' => 'testArea'])
159  )
160  ->will($this->returnValue('ok'));
161 
162  return $objectManagerMock;
163  }
164 }
$code
Definition: info.phtml:12