Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InitialThemeSourceTest.php
Go to the documentation of this file.
1 <?php
7 
10 use Magento\Framework\DataObject\Factory as DataObjectFactory;
14 use Magento\Theme\Model\ResourceModel\ThemeFactory;
16 use PHPUnit_Framework_MockObject_MockObject as Mock;
17 
21 class InitialThemeSourceTest extends \PHPUnit\Framework\TestCase
22 {
26  private $model;
27 
31  private $deploymentConfigMock;
32 
36  private $themeFactoryMock;
37 
41  private $dataObjectFactoryMock;
42 
46  private $dataObjectMock;
47 
51  private $themeMock;
52 
56  private $connectionMock;
57 
61  private $selectMock;
62 
63  protected function setUp()
64  {
65  $this->deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
66  ->disableOriginalConstructor()
67  ->getMock();
68  $this->themeFactoryMock = $this->getMockBuilder(ThemeFactory::class)
69  ->setMethods(['create'])
70  ->disableOriginalConstructor()
71  ->getMock();
72  $this->themeMock = $this->getMockBuilder(Theme::class)
73  ->disableOriginalConstructor()
74  ->getMock();
75  $this->selectMock = $this->getMockBuilder(Select::class)
76  ->disableOriginalConstructor()
77  ->setMethods(['sort', 'from'])
78  ->getMock();
79  $this->connectionMock = $this->getMockBuilder(AdapterInterface::class)
80  ->getMockForAbstractClass();
81  $this->dataObjectFactoryMock = $this->getMockBuilder(DataObjectFactory::class)
82  ->setMethods(['create'])
83  ->disableOriginalConstructor()
84  ->getMock();
85  $this->dataObjectMock = $this->getMockBuilder(DataObject::class)
86  ->disableOriginalConstructor()
87  ->getMock();
88 
89  $this->themeMock->expects($this->any())
90  ->method('getConnection')
91  ->willReturn($this->connectionMock);
92  $this->themeFactoryMock->expects($this->any())
93  ->method('create')
94  ->willReturn($this->themeMock);
95  $this->connectionMock->expects($this->any())
96  ->method('select')
97  ->willReturn($this->selectMock);
98  $this->selectMock->expects($this->any())
99  ->method('from')
100  ->willReturnSelf();
101  $this->selectMock->expects($this->any())
102  ->method('sort')
103  ->willReturnSelf();
104 
105  $this->model = new InitialThemeSource(
106  $this->deploymentConfigMock,
107  $this->themeFactoryMock,
108  $this->dataObjectFactoryMock
109  );
110  }
111 
112  public function testGetNotDeployed()
113  {
114  $this->deploymentConfigMock->expects($this->once())
115  ->method('isDbAvailable')
116  ->willReturn(false);
117 
118  $this->assertSame([], $this->model->get());
119  }
120 
121  public function testGet()
122  {
123  $this->deploymentConfigMock->expects($this->once())
124  ->method('isDbAvailable')
125  ->willReturn(true);
126  $this->connectionMock->expects($this->once())
127  ->method('fetchAssoc')
128  ->willReturn(
129  [
130  '1' => [
131  'theme_id' => '1',
132  'parent_id' => null,
133  'theme_path' => 'Magento/backend',
134  'theme_title' => 'Magento 2 backend',
135  'is_featured' => '0',
136  'area' => 'adminhtml',
137  'type' => '0',
138  'code' => 'Magento/backend',
139  ],
140  '2' => [
141  'theme_id' => '2',
142  'parent_id' => null,
143  'theme_path' => 'Magento/blank',
144  'theme_title' => 'Magento Blank',
145  'is_featured' => '0',
146  'area' => 'frontend',
147  'type' => '0',
148  'code' => 'Magento/blank',
149  ],
150  '3' => [
151  'theme_id' => '3',
152  'parent_id' => '2',
153  'theme_path' => 'Magento/luma',
154  'theme_title' => 'Magento Luma',
155  'is_featured' => '0',
156  'area' => 'frontend',
157  'type' => '0',
158  'code' => 'Magento/luma',
159  ],
160  ]
161  );
162  $this->dataObjectFactoryMock->expects($this->once())
163  ->method('create')
164  ->with(
165  [
166  'adminhtml/Magento/backend' => [
167  'parent_id' => null,
168  'theme_path' => 'Magento/backend',
169  'theme_title' => 'Magento 2 backend',
170  'is_featured' => '0',
171  'area' => 'adminhtml',
172  'type' => '0',
173  'code' => 'Magento/backend',
174  ],
175  'frontend/Magento/blank' => [
176  'parent_id' => null,
177  'theme_path' => 'Magento/blank',
178  'theme_title' => 'Magento Blank',
179  'is_featured' => '0',
180  'area' => 'frontend',
181  'type' => '0',
182  'code' => 'Magento/blank',
183  ],
184  'frontend/Magento/luma' => [
185  'parent_id' => 'Magento/blank',
186  'theme_path' => 'Magento/luma',
187  'theme_title' => 'Magento Luma',
188  'is_featured' => '0',
189  'area' => 'frontend',
190  'type' => '0',
191  'code' => 'Magento/luma',
192  ],
193  ]
194  )
195  ->willReturn($this->dataObjectMock);
196  $this->dataObjectMock->expects($this->once())
197  ->method('getData');
198 
199  $this->model->get();
200  }
201 }