Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ViewFactoryTest.php
Go to the documentation of this file.
1 <?php
7 
8 class ViewFactoryTest extends \PHPUnit\Framework\TestCase
9 {
10  const AREA = 'frontend';
11 
15  protected $model;
16 
20  protected $objectManager;
21 
25  protected $theme;
26 
30  protected $view;
31 
32  protected function setUp()
33  {
34  $this->objectManager = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
35  $this->model = new \Magento\Framework\Config\ViewFactory($this->objectManager);
36  $this->theme = $this->createMock(\Magento\Framework\View\Design\ThemeInterface::class);
37  $this->view = $this->createMock(\Magento\Framework\Config\View::class);
38  }
39 
40  public function testCreate()
41  {
42  $this->objectManager->expects($this->once())
43  ->method('create')
44  ->with(\Magento\Framework\Config\View::class, [])
45  ->willReturn($this->view);
46  $this->assertEquals($this->view, $this->model->create());
47  }
48 
49  public function testCreateWithArguments()
50  {
52  $design = $this->createMock(\Magento\Theme\Model\View\Design::class);
53  $design->expects($this->once())
54  ->method('setDesignTheme')
55  ->with($this->theme, self::AREA);
56 
58  $fileResolver = $this->createMock(\Magento\Framework\Config\FileResolver::class);
59 
60  $valueMap = [
61  [\Magento\Theme\Model\View\Design::class, [], $design],
62  [\Magento\Framework\Config\FileResolver::class, ['designInterface' => $design], $fileResolver],
63  [\Magento\Framework\Config\View::class, ['fileResolver' => $fileResolver], $this->view],
64  ];
65  $this->objectManager->expects($this->exactly(3))
66  ->method('create')
67  ->willReturnMap($valueMap);
68 
69  $this->assertEquals($this->view, $this->model->create($this->getArguments()));
70  }
71 
76  public function testCreateException()
77  {
78  $this->model->create(
79  [
80  'themeModel' => 'wrong theme',
81  'area' => self::AREA
82  ]
83  );
84  }
85 
89  protected function getArguments()
90  {
91  return [
92  'themeModel' => $this->theme,
93  'area' => self::AREA
94  ];
95  }
96 }