BuilderTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Test theme page layout config model
  8. */
  9. namespace Magento\Theme\Test\Unit\Model\PageLayout\Config;
  10. class BuilderTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var Builder
  14. */
  15. protected $builder;
  16. /**
  17. * @var \Magento\Framework\View\PageLayout\ConfigFactory|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $configFactory;
  20. /**
  21. * @var \Magento\Framework\View\PageLayout\File\Collector\Aggregated|\PHPUnit_Framework_MockObject_MockObject
  22. */
  23. protected $fileCollector;
  24. /**
  25. * @var \Magento\Theme\Model\ResourceModel\Theme\Collection|\PHPUnit_Framework_MockObject_MockObject
  26. */
  27. protected $themeCollection;
  28. /**
  29. * SetUp method
  30. *
  31. * @return void
  32. */
  33. protected function setUp()
  34. {
  35. $this->configFactory = $this->getMockBuilder(\Magento\Framework\View\PageLayout\ConfigFactory::class)
  36. ->disableOriginalConstructor()
  37. ->setMethods(['create'])
  38. ->getMock();
  39. $this->fileCollector = $this->getMockBuilder(
  40. \Magento\Framework\View\PageLayout\File\Collector\Aggregated::class
  41. )->disableOriginalConstructor()->getMock();
  42. $this->themeCollection = $this->getMockBuilder(\Magento\Theme\Model\ResourceModel\Theme\Collection::class)
  43. ->disableOriginalConstructor()
  44. ->getMock();
  45. $this->themeCollection->expects($this->once())
  46. ->method('setItemObjectClass')
  47. ->with(\Magento\Theme\Model\Theme\Data::class)
  48. ->willReturnSelf();
  49. $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  50. $this->builder = $helper->getObject(
  51. \Magento\Theme\Model\PageLayout\Config\Builder::class,
  52. [
  53. 'configFactory' => $this->configFactory,
  54. 'fileCollector' => $this->fileCollector,
  55. 'themeCollection' => $this->themeCollection
  56. ]
  57. );
  58. }
  59. /**
  60. * Test get page layouts config
  61. *
  62. * @return void
  63. */
  64. public function testGetPageLayoutsConfig()
  65. {
  66. $files1 = ['content layouts_1.xml', 'content layouts_2.xml'];
  67. $files2 = ['content layouts_3.xml', 'content layouts_4.xml'];
  68. $theme1 = $this->getMockBuilder(\Magento\Theme\Model\Theme\Data::class)
  69. ->disableOriginalConstructor()
  70. ->getMock();
  71. $theme2 = $this->getMockBuilder(\Magento\Theme\Model\Theme\Data::class)
  72. ->disableOriginalConstructor()
  73. ->getMock();
  74. $this->themeCollection->expects($this->once())
  75. ->method('loadRegisteredThemes')
  76. ->willReturn([$theme1, $theme2]);
  77. $this->fileCollector->expects($this->exactly(2))
  78. ->method('getFilesContent')
  79. ->willReturnMap(
  80. [
  81. [$theme1, 'layouts.xml', $files1],
  82. [$theme2, 'layouts.xml', $files2]
  83. ]
  84. );
  85. $config = $this->getMockBuilder(\Magento\Framework\View\PageLayout\Config::class)
  86. ->disableOriginalConstructor()
  87. ->getMock();
  88. $this->configFactory->expects($this->once())
  89. ->method('create')
  90. ->with(['configFiles' => array_merge($files1, $files2)])
  91. ->willReturn($config);
  92. $this->assertSame($config, $this->builder->getPageLayoutsConfig());
  93. }
  94. }