1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
||
5 | * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
||
6 | */ |
||
7 | |||
8 | namespace SprykerTest\Zed\Cms\Business\Page; |
||
9 | |||
10 | use Orm\Zed\Cms\Persistence\SpyCmsPage; |
||
11 | use Orm\Zed\Cms\Persistence\SpyCmsPageLocalizedAttributes; |
||
12 | use Orm\Zed\Cms\Persistence\SpyCmsTemplate; |
||
13 | use Orm\Zed\Locale\Persistence\SpyLocale; |
||
14 | use Orm\Zed\Url\Persistence\SpyUrl; |
||
15 | use Spryker\Zed\Cms\Business\Page\CmsPageMapperInterface; |
||
16 | use Spryker\Zed\Cms\Business\Page\CmsPageReader; |
||
17 | use Spryker\Zed\Cms\Business\Page\CmsPageUrlBuilderInterface; |
||
18 | use Spryker\Zed\Cms\Dependency\Facade\CmsToLocaleInterface; |
||
19 | use Spryker\Zed\Cms\Persistence\CmsQueryContainerInterface; |
||
20 | use SprykerTest\Zed\Cms\Business\CmsMocks; |
||
21 | |||
22 | /** |
||
23 | * Auto-generated group annotations |
||
24 | * |
||
25 | * @group SprykerTest |
||
26 | * @group Zed |
||
27 | * @group Cms |
||
28 | * @group Business |
||
29 | * @group Page |
||
30 | * @group CmsPageReaderTest |
||
31 | * Add your own group annotations below this line |
||
32 | */ |
||
33 | class CmsPageReaderTest extends CmsMocks |
||
34 | { |
||
35 | /** |
||
36 | * @return void |
||
37 | */ |
||
38 | public function testGetCmsPageByIdShouldReturnMappedTransferObjectFromPersistence(): void |
||
39 | { |
||
40 | $cmsPageReaderMock = $this->createCmsPageReaderMock(); |
||
41 | |||
42 | $cmsPageEntity = $this->buildCmsPageEntity(); |
||
43 | |||
44 | $cmsPageReaderMock->expects($this->once()) |
||
45 | ->method('findCmsPageEntity') |
||
46 | ->willReturn($cmsPageEntity); |
||
47 | |||
48 | $cmsPageTransfer = $cmsPageReaderMock->findCmsPageById(1); |
||
49 | |||
50 | $this->assertSame($cmsPageEntity->getIdCmsPage(), $cmsPageTransfer->getFkPage()); |
||
51 | $this->assertCount(2, $cmsPageTransfer->getPageAttributes()); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @return void |
||
56 | */ |
||
57 | public function testGetCmsPageByIdWhenPageNotFoundShouldReturnNull(): void |
||
58 | { |
||
59 | $cmsPageReaderMock = $this->createCmsPageReaderMock(); |
||
60 | |||
61 | $cmsPageReaderMock->expects($this->once()) |
||
62 | ->method('findCmsPageEntity') |
||
63 | ->willReturn(null); |
||
64 | |||
65 | $cmsPageTransfer = $cmsPageReaderMock->findCmsPageById(1); |
||
66 | |||
67 | $this->assertNull($cmsPageTransfer); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @param \Spryker\Zed\Cms\Business\Page\CmsPageMapperInterface|null $cmsPageMapperMock |
||
72 | * @param \Spryker\Zed\Cms\Persistence\CmsQueryContainerInterface|null $cmsQueryContainerMock |
||
73 | * @param \Spryker\Zed\Cms\Dependency\Facade\CmsToLocaleInterface|null $localeFacadeMock |
||
74 | * |
||
75 | * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\Cms\Business\Page\CmsPageReader |
||
76 | */ |
||
77 | protected function createCmsPageReaderMock( |
||
78 | ?CmsPageMapperInterface $cmsPageMapperMock = null, |
||
79 | ?CmsQueryContainerInterface $cmsQueryContainerMock = null, |
||
80 | ?CmsToLocaleInterface $localeFacadeMock = null |
||
81 | ): CmsPageReader { |
||
82 | if ($cmsPageMapperMock === null) { |
||
83 | $cmsPageMapperMock = $this->createCmsPageMapperMock(); |
||
84 | } |
||
85 | |||
86 | if ($cmsQueryContainerMock === null) { |
||
87 | $cmsQueryContainerMock = $this->createCmsQueryContainerMock(); |
||
88 | } |
||
89 | |||
90 | if ($localeFacadeMock === null) { |
||
91 | $localeFacadeMock = $this->createLocaleMock(); |
||
92 | } |
||
93 | |||
94 | $localeFacadeMock->method('getAvailableLocales') |
||
0 ignored issues
–
show
|
|||
95 | ->willReturn($this->getAvailableLocales()); |
||
96 | |||
97 | return $this->getMockBuilder(CmsPageReader::class) |
||
98 | ->setMethods(['findCmsPageEntity']) |
||
99 | ->setConstructorArgs([$cmsQueryContainerMock, $cmsPageMapperMock, $localeFacadeMock]) |
||
100 | ->getMock(); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\Cms\Business\Page\CmsPageUrlBuilderInterface |
||
105 | */ |
||
106 | protected function createCmsUrlBuilderMock(): CmsPageUrlBuilderInterface |
||
107 | { |
||
108 | return $this->getMockBuilder(CmsPageUrlBuilderInterface::class) |
||
109 | ->getMock(); |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @return \Orm\Zed\Cms\Persistence\SpyCmsPage|\PHPUnit\Framework\MockObject\MockObject |
||
114 | */ |
||
115 | protected function buildCmsPageEntity(): SpyCmsPage |
||
116 | { |
||
117 | $cmsPageEntity = $this->createCmsPageEntityMock(); |
||
118 | $cmsPageEntity->setIdCmsPage(1); |
||
119 | |||
120 | $cmsTemplateEntity = new SpyCmsTemplate(); |
||
121 | $cmsTemplateEntity->setTemplateName('template name'); |
||
122 | $cmsPageEntity->setCmsTemplate($cmsTemplateEntity); |
||
123 | |||
124 | $urlEntity = new SpyUrl(); |
||
125 | $urlEntity->setUrl('/en/test'); |
||
126 | $cmsPageEntity->addSpyUrl($urlEntity); |
||
127 | |||
128 | $urlEntity = new SpyUrl(); |
||
129 | $urlEntity->setUrl('/de/test'); |
||
130 | $cmsPageEntity->addSpyUrl($urlEntity); |
||
131 | |||
132 | $cmsLocalizedPageAttributesEntity = new SpyCmsPageLocalizedAttributes(); |
||
133 | $localeEntity = new SpyLocale(); |
||
134 | $cmsLocalizedPageAttributesEntity->setLocale($localeEntity); |
||
135 | $cmsPageEntity->addSpyCmsPageLocalizedAttributes($cmsLocalizedPageAttributesEntity); |
||
136 | |||
137 | $cmsLocalizedPageAttributesEntity = new SpyCmsPageLocalizedAttributes(); |
||
138 | $localeEntity = new SpyLocale(); |
||
139 | $cmsLocalizedPageAttributesEntity->setLocale($localeEntity); |
||
140 | $cmsPageEntity->addSpyCmsPageLocalizedAttributes($cmsLocalizedPageAttributesEntity); |
||
141 | |||
142 | return $cmsPageEntity; |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * @return array<string> |
||
147 | */ |
||
148 | protected function getAvailableLocales(): array |
||
149 | { |
||
150 | return [ |
||
151 | 1 => 'en_US', |
||
152 | 2 => 'de_DE', |
||
153 | ]; |
||
154 | } |
||
155 | } |
||
156 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.