Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ScopesTest.php
Go to the documentation of this file.
1 <?php
8 
13 
14 class ScopesTest extends \PHPUnit\Framework\TestCase
15 {
19  private $unit;
20 
24  private $sourceMock;
25 
26  protected function setUp()
27  {
28  $this->sourceMock = $this->getMockBuilder(ConfigSourceInterface::class)->getMock();
29  $this->unit = (new ObjectManager($this))->getObject(
30  Scopes::class,
31  [
32  'source' => $this->sourceMock,
33  ]
34  );
35  }
36 
40  public function testGet($path, $expectedResult)
41  {
42  $configData = [
43  'websites' => [
44  'admin' => [
45  'website_id' => 0,
46  'code' => 'admin',
47  ],
48  'default' => [
49  'website_id' => 1,
50  'code' => 'default',
51  ],
52  ],
53  'groups' => [
54  '0' => [
55  'group_id' => 0,
56  'code' => 'admin',
57  ],
58  ],
59  ];
60  $this->sourceMock->expects($this->once())->method('get')->with('')->willReturn($configData);
61 
62  $this->assertEquals($expectedResult, $this->unit->get($path));
63  }
64 
66  {
67  $initConfigData = [
68  'websites' => [
69  'base' => [
70  'website_id' => 0,
71  'code' => 'base'
72  ]
73  ]
74  ];
75  $this->sourceMock->expects($this->any())->method('get')->willReturnMap([
76  ['', $initConfigData],
77  ['websites/1', null],
78  ]);
79 
80  $this->assertNull($this->unit->get('websites/1'));
81  }
82 
88  public function getDataProvider()
89  {
90  return [
91  [
92  'websites',
93  [
94  'admin' => [
95  'website_id' => 0,
96  'code' => 'admin',
97  ],
98  'default' => [
99  'website_id' => 1,
100  'code' => 'default',
101  ]
102  ],
103  ],
104  [
105  'websites/admin',
106  [
107  'website_id' => 0,
108  'code' => 'admin',
109  ],
110  ],
111  [
112  'websites/1',
113  [
114  'website_id' => 1,
115  'code' => 'default',
116  ],
117  ],
118  [
119  'websites/1/code',
120  'default',
121  ],
122  [
123  'groups/0',
124  [
125  'group_id' => 0,
126  'code' => 'admin',
127  ],
128  ],
129  ];
130  }
131 }