Completed
Push — develop ( a0b39d...6e6eeb )
by Tino
07:33
created

TitleTest::setUpTitleConfigurator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright (c) by the ACP3 Developers.
5
 * See the LICENSE file at the top-level module directory for licensing details.
6
 */
7
8
namespace ACP3\Modules\ACP3\System\Test\Core\Breadcrumb;
9
10
use ACP3\Core\Http\Request;
11
use ACP3\Core\Settings\SettingsInterface;
12
use ACP3\Modules\ACP3\System\Core\Breadcrumb\Title;
13
use ACP3\Modules\ACP3\System\Core\Breadcrumb\TitleConfigurator;
14
15
class TitleTest extends \ACP3\Core\Test\Breadcrumb\TitleTest
16
{
17
    /**
18
     * @var Title
19
     */
20
    protected $title;
21
    /**
22
     * @var TitleConfigurator
23
     */
24
    private $titleConfigurator;
25
    /**
26
     * @var \PHPUnit_Framework_MockObject_MockObject
27
     */
28
    private $configMock;
29
    /**
30
     * @var \PHPUnit_Framework_MockObject_MockObject
31
     */
32
    private $requestMock;
33
34
    protected function setUp()
35
    {
36
        $this->initializeMockObjects();
37
        $this->setUpTitleConfigurator();
38
39
        $this->title = new Title(
40
            $this->requestMock,
41
            $this->stepsMock,
42
            $this->eventDispatcherMock,
43
            $this->configMock
44
        );
45
    }
46
47
    protected function initializeMockObjects()
48
    {
49
        parent::initializeMockObjects();
50
51
        $this->requestMock = $this->createMock(Request::class);
52
        $this->configMock = $this->createMock(SettingsInterface::class);
53
    }
54
55
    private function setUpTitleConfigurator()
56
    {
57
        $this->titleConfigurator = new TitleConfigurator($this->configMock);
58
    }
59
60
    public function testGetSiteAndPageTitleWithNoCustomSiteTitle()
61
    {
62
        $this->setUpStepsExpectations(1);
63
64
        $this->setUpConfigMockExpectations('SEO Title', '', 1, 0);
65
        $this->titleConfigurator->configure($this->title);
66
67
        $this->assertEquals('Foo | SEO Title', $this->title->getSiteAndPageTitle());
68
    }
69
70
    /**
71
     * @param string $siteTitle
72
     * @param string $siteSubtitle
73
     * @param int    $subtitleMode
74
     * @param int    $subtitleHomepageMode
75
     */
76
    private function setUpConfigMockExpectations(
77
        string $siteTitle,
78
        string $siteSubtitle,
79
        int $subtitleMode,
80
        int $subtitleHomepageMode)
81
    {
82
        $this->configMock->expects($this->atLeastOnce())
83
            ->method('getSettings')
84
            ->with('system')
85
            ->willReturn([
86
                'site_title' => $siteTitle,
87
                'site_subtitle' => $siteSubtitle,
88
                'site_subtitle_homepage_mode' => $subtitleHomepageMode,
89
                'site_subtitle_mode' => $subtitleMode,
90
            ]);
91
    }
92
93
    public function testGetSiteAndPageTitleWithSubtitle()
94
    {
95
        $this->setUpStepsExpectations(1);
96
97
        $this->setUpConfigMockExpectations('SEO Title', 'Subtitle', 1, 0);
98
        $this->titleConfigurator->configure($this->title);
99
100
        $this->assertEquals('Foo | SEO Title - Subtitle', $this->title->getSiteAndPageTitle());
101
    }
102
103
    public function testGetSiteAndPageTitleForHomepageWithOverride()
104
    {
105
        $this->setUpStepsExpectations(0);
106
107
        $this->requestMock->expects($this->once())
108
            ->method('isHomepage')
109
            ->willReturn(true);
110
111
        $this->setUpConfigMockExpectations('SEO Title', 'Subtitle', 1, 1);
112
        $this->titleConfigurator->configure($this->title);
113
114
        $this->assertEquals('Subtitle | SEO Title', $this->title->getSiteAndPageTitle());
115
    }
116
117
    public function testGetSiteAndPageTitleForNotHomepage()
118
    {
119
        $this->setUpStepsExpectations(1);
120
121
        $this->requestMock->expects($this->once())
122
            ->method('isHomepage')
123
            ->willReturn(false);
124
125
        $this->setUpConfigMockExpectations('SEO Title', 'Subtitle', 2, 1);
126
        $this->titleConfigurator->configure($this->title);
127
128
        $this->assertEquals('Foo | SEO Title', $this->title->getSiteAndPageTitle());
129
    }
130
}
131