Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DesignConfigRepositoryTest.php
Go to the documentation of this file.
1 <?php
8 
12 
13 class DesignConfigRepositoryTest extends \PHPUnit\Framework\TestCase
14 {
16  protected $configStorage;
17 
19  protected $reinitableConfig;
20 
22  protected $indexerRegistry;
23 
25  protected $designConfig;
26 
28  protected $designExtension;
29 
31  protected $designConfigData;
32 
34  protected $indexer;
35 
37  protected $repository;
38 
42  protected $validator;
43 
44  public function setUp()
45  {
46  $this->configStorage = $this->createMock(\Magento\Theme\Model\Design\Config\Storage::class);
47  $this->reinitableConfig = $this->getMockForAbstractClass(
48  \Magento\Framework\App\Config\ReinitableConfigInterface::class,
49  [],
50  '',
51  false
52  );
53  $this->indexerRegistry = $this->createMock(\Magento\Framework\Indexer\IndexerRegistry::class);
54  $this->designConfig = $this->getMockForAbstractClass(
55  \Magento\Theme\Api\Data\DesignConfigInterface::class,
56  [],
57  '',
58  false
59  );
60  $this->designExtension = $this->getMockForAbstractClass(
61  \Magento\Theme\Api\Data\DesignConfigExtensionInterface::class,
62  [],
63  '',
64  false,
65  false,
66  true,
67  ['getDesignConfigData']
68  );
69  $this->designConfigData = $this->getMockForAbstractClass(
70  \Magento\Theme\Api\Data\DesignConfigDataInterface::class,
71  [],
72  '',
73  false
74  );
75  $this->indexer = $this->getMockForAbstractClass(
76  \Magento\Framework\Indexer\IndexerInterface::class,
77  [],
78  '',
79  false
80  );
81 
82  $this->validator = $this->createMock(\Magento\Theme\Model\Design\Config\Validator::class);
83  $objectManagerHelper = new ObjectManager($this);
84  $this->repository = $objectManagerHelper->getObject(
85  DesignConfigRepository::class,
86  [
87  'configStorage' => $this->configStorage,
88  'reinitableConfig' => $this->reinitableConfig,
89  'indexerRegistry' => $this->indexerRegistry,
90  'validator' => $this->validator
91  ]
92  );
93  }
94 
95  public function testSave()
96  {
97  $this->designConfig->expects($this->exactly(2))
98  ->method('getExtensionAttributes')
99  ->willReturn($this->designExtension);
100  $this->designExtension->expects($this->once())
101  ->method('getDesignConfigData')
102  ->willReturn([$this->designConfigData]);
103  $this->configStorage->expects($this->once())
104  ->method('save')
105  ->willReturn($this->designConfig);
106  $this->reinitableConfig->expects($this->once())
107  ->method('reinit');
108  $this->indexerRegistry->expects($this->once())
109  ->method('get')
111  ->willReturn($this->indexer);
112  $this->indexer->expects($this->once())
113  ->method('reindexAll');
114  $this->validator->expects($this->once())->method('validate')->with($this->designConfig);
115  $this->assertSame($this->designConfig, $this->repository->save($this->designConfig));
116  }
117 
122  public function testSaveWithoutConfig()
123  {
124  $this->designConfig->expects($this->exactly(2))
125  ->method('getExtensionAttributes')
126  ->willReturn($this->designExtension);
127  $this->designExtension->expects($this->once())
128  ->method('getDesignConfigData')
129  ->willReturn(false);
130  $this->repository->save($this->designConfig);
131  }
132 
133  public function testDelete()
134  {
135  $this->designConfig->expects($this->exactly(2))
136  ->method('getExtensionAttributes')
137  ->willReturn($this->designExtension);
138  $this->designExtension->expects($this->once())
139  ->method('getDesignConfigData')
140  ->willReturn([$this->designConfigData]);
141  $this->configStorage->expects($this->once())
142  ->method('delete')
143  ->with($this->designConfig);
144  $this->reinitableConfig->expects($this->once())
145  ->method('reinit');
146  $this->indexerRegistry->expects($this->once())
147  ->method('get')
149  ->willReturn($this->indexer);
150  $this->indexer->expects($this->once())
151  ->method('reindexAll');
152  $this->assertSame($this->designConfig, $this->repository->delete($this->designConfig));
153  }
154 }