ViewFactoryTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Config\Test\Unit;
  7. class ViewFactoryTest extends \PHPUnit\Framework\TestCase
  8. {
  9. const AREA = 'frontend';
  10. /**
  11. * @var \Magento\Framework\Config\ViewFactory
  12. */
  13. protected $model;
  14. /**
  15. * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $objectManager;
  18. /**
  19. * @var \Magento\Framework\View\Design\ThemeInterface|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $theme;
  22. /**
  23. * @var \Magento\Framework\Config\View|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $view;
  26. protected function setUp()
  27. {
  28. $this->objectManager = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
  29. $this->model = new \Magento\Framework\Config\ViewFactory($this->objectManager);
  30. $this->theme = $this->createMock(\Magento\Framework\View\Design\ThemeInterface::class);
  31. $this->view = $this->createMock(\Magento\Framework\Config\View::class);
  32. }
  33. public function testCreate()
  34. {
  35. $this->objectManager->expects($this->once())
  36. ->method('create')
  37. ->with(\Magento\Framework\Config\View::class, [])
  38. ->willReturn($this->view);
  39. $this->assertEquals($this->view, $this->model->create());
  40. }
  41. public function testCreateWithArguments()
  42. {
  43. /** @var \Magento\Theme\Model\View\Design|\PHPUnit_Framework_MockObject_MockObject $design */
  44. $design = $this->createMock(\Magento\Theme\Model\View\Design::class);
  45. $design->expects($this->once())
  46. ->method('setDesignTheme')
  47. ->with($this->theme, self::AREA);
  48. /** @var \Magento\Framework\Config\FileResolver|\PHPUnit_Framework_MockObject_MockObject $fileResolver */
  49. $fileResolver = $this->createMock(\Magento\Framework\Config\FileResolver::class);
  50. $valueMap = [
  51. [\Magento\Theme\Model\View\Design::class, [], $design],
  52. [\Magento\Framework\Config\FileResolver::class, ['designInterface' => $design], $fileResolver],
  53. [\Magento\Framework\Config\View::class, ['fileResolver' => $fileResolver], $this->view],
  54. ];
  55. $this->objectManager->expects($this->exactly(3))
  56. ->method('create')
  57. ->willReturnMap($valueMap);
  58. $this->assertEquals($this->view, $this->model->create($this->getArguments()));
  59. }
  60. /**
  61. * @expectedException \Magento\Framework\Exception\LocalizedException
  62. * @expectedExceptionMessage wrong theme doesn't implement ThemeInterface
  63. */
  64. public function testCreateException()
  65. {
  66. $this->model->create(
  67. [
  68. 'themeModel' => 'wrong theme',
  69. 'area' => self::AREA
  70. ]
  71. );
  72. }
  73. /**
  74. * @return array
  75. */
  76. protected function getArguments()
  77. {
  78. return [
  79. 'themeModel' => $this->theme,
  80. 'area' => self::AREA
  81. ];
  82. }
  83. }