Issues (3641)

Zed/Cms/Business/Page/CmsPageActivatorTest.php (1 issue)

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 Spryker\Zed\Cms\Business\Page\CmsPageActivator;
12
use Spryker\Zed\Cms\Business\Template\TemplateReaderInterface;
13
use Spryker\Zed\Cms\Dependency\Facade\CmsToTouchFacadeInterface;
14
use Spryker\Zed\Cms\Persistence\CmsQueryContainerInterface;
15
use SprykerTest\Zed\Cms\Business\CmsMocks;
16
17
/**
18
 * Auto-generated group annotations
19
 *
20
 * @group SprykerTest
21
 * @group Zed
22
 * @group Cms
23
 * @group Business
24
 * @group Page
25
 * @group CmsPageActivatorTest
26
 * Add your own group annotations below this line
27
 */
28
class CmsPageActivatorTest extends CmsMocks
29
{
30
    /**
31
     * @return void
32
     */
33
    public function testActivatePageShouldPersistActiveFlagAndTriggerTouch(): void
34
    {
35
        $cmsPageEntityMock = $this->createCmsPageEntityMock();
36
        $cmsPageEntityMock->expects($this->once())
37
            ->method('save');
38
        $cmsPageEntityMock->method('getVirtualColumn')->willReturn('');
39
40
        $touchFacadeMock = $this->createTouchFacadeMock();
41
        $touchFacadeMock->expects($this->once())
42
            ->method('touchActive');
43
44
        $cmsPageActivatorMock = $this->createCmsPageActivateMock($cmsPageEntityMock, null, $touchFacadeMock);
45
46
        $cmsPageActivatorMock->method('countNumberOfGlossaryKeysForIdCmsPage')->willReturn(5);
47
48
        $cmsPageEntityMock->setIdCmsPage(1);
49
        $cmsPageActivatorMock->activate(1);
50
51
        $this->assertTrue($cmsPageEntityMock->getIsActive());
52
    }
53
54
    /**
55
     * @return void
56
     */
57
    public function testDeActivatePageShouldPersistInActiveFlagAndTriggerTouch(): void
58
    {
59
        $cmsPageEntityMock = $this->createCmsPageEntityMock();
60
        $cmsPageEntityMock->expects($this->once())
61
            ->method('save');
62
63
        $touchFacadeMock = $this->createTouchFacadeMock();
64
        $touchFacadeMock->expects($this->once())
65
            ->method('touchActive');
66
67
        $cmsPageActivatorMock = $this->createCmsPageActivateMock($cmsPageEntityMock, null, $touchFacadeMock);
68
69
        $cmsPageEntityMock->setIdCmsPage(1);
70
        $cmsPageActivatorMock->deactivate(1);
71
72
        $this->assertFalse($cmsPageEntityMock->getIsActive());
73
    }
74
75
    /**
76
     * @param \Orm\Zed\Cms\Persistence\SpyCmsPage $cmsPageEntity
77
     * @param \Spryker\Zed\Cms\Persistence\CmsQueryContainerInterface|null $cmsQueryContainerMock
78
     * @param \Spryker\Zed\Cms\Dependency\Facade\CmsToTouchFacadeInterface|null $touchFacadeMock
79
     * @param \Spryker\Zed\Cms\Business\Template\TemplateReaderInterface|null $templateReader
80
     *
81
     * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\Cms\Business\Page\CmsPageActivator
82
     */
83
    protected function createCmsPageActivateMock(
84
        SpyCmsPage $cmsPageEntity,
85
        ?CmsQueryContainerInterface $cmsQueryContainerMock = null,
86
        ?CmsToTouchFacadeInterface $touchFacadeMock = null,
87
        ?TemplateReaderInterface $templateReader = null
88
    ): CmsPageActivator {
89
        if ($cmsQueryContainerMock === null) {
90
            $cmsQueryContainerMock = $this->createCmsQueryContainerMock();
91
        }
92
93
        if ($touchFacadeMock === null) {
94
            $touchFacadeMock = $this->createTouchFacadeMock();
95
        }
96
97
        if ($templateReader === null) {
98
            $templateReader = $this->createTemplateReaderMock();
99
            $templateReader->method('getPlaceholdersByTemplatePath')
0 ignored issues
show
The method method() does not exist on Spryker\Zed\Cms\Business...TemplateReaderInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

99
            $templateReader->/** @scrutinizer ignore-call */ 
100
                             method('getPlaceholdersByTemplatePath')

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.

Loading history...
100
                ->willReturn(['title', 'content']);
101
        }
102
103
        $cmsPageActivatorMock = $this->getMockBuilder(CmsPageActivator::class)
104
            ->setMethods(['getCmsPageEntity', 'countNumberOfGlossaryKeysForIdCmsPage', 'getCmsPageEntityWithTemplatesAndUrl'])
105
            ->setConstructorArgs([$cmsQueryContainerMock, $touchFacadeMock, [], $templateReader])
106
            ->getMock();
107
108
        $cmsPageActivatorMock->method('getCmsPageEntity')
109
            ->willReturn($cmsPageEntity);
110
111
        $cmsPageActivatorMock->method('getCmsPageEntityWithTemplatesAndUrl')
112
            ->willReturn($cmsPageEntity);
113
114
        return $cmsPageActivatorMock;
115
    }
116
}
117