Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ThemePackageListTest.php
Go to the documentation of this file.
1 <?php
7 
10 
11 class ThemePackageListTest extends \PHPUnit\Framework\TestCase
12 {
16  private $registrar;
17 
21  private $object;
22 
26  private $factory;
27 
28  protected function setUp()
29  {
30  $this->registrar = $this->getMockForAbstractClass(
31  \Magento\Framework\Component\ComponentRegistrarInterface::class
32  );
33  $this->factory = $this->createMock(\Magento\Framework\View\Design\Theme\ThemePackageFactory::class);
34  $this->object = new ThemePackageList($this->registrar, $this->factory);
35  }
36 
41  public function testGetThemeNonexistent()
42  {
43  $themeKey = 'theme';
44  $this->registrar->expects($this->once())
45  ->method('getPath')
46  ->with(ComponentRegistrar::THEME, $themeKey)
47  ->willReturn(null);
48  $this->factory->expects($this->never())
49  ->method('create');
50  $this->object->getTheme($themeKey);
51  }
52 
53  public function testGetTheme()
54  {
55  $themeKey = 'theme';
56  $themePath = 'path';
57  $this->registrar->expects($this->once())
58  ->method('getPath')
59  ->with(ComponentRegistrar::THEME, $themeKey)
60  ->willReturn($themePath);
61  $themePackage = $this->createMock(\Magento\Framework\View\Design\Theme\ThemePackage::class);
62  $this->factory->expects($this->once())
63  ->method('create')
64  ->with($themeKey, $themePath)
65  ->willReturn($themePackage);
66  $this->assertSame($themePackage, $this->object->getTheme($themeKey));
67  }
68 
69  public function testGetThemes()
70  {
71  $this->registrar->expects($this->once())
72  ->method('getPaths')
74  ->willReturn(['theme1' => 'path1', 'theme2' => 'path2']);
75  $themePackage = $this->createMock(\Magento\Framework\View\Design\Theme\ThemePackage::class);
76  $this->factory->expects($this->exactly(2))
77  ->method('create')
78  ->withConsecutive(
79  ['theme1', 'path1'],
80  ['theme2', 'path2']
81  )
82  ->willReturn($themePackage);
83  $actual = $this->object->getThemes();
84  $this->assertCount(2, $actual);
85  foreach ($actual as $themePackage) {
86  $this->assertSame($themePackage, $themePackage);
87  }
88  }
89 }