1<?php
2/*
3 * vim:set softtabstop=4 shiftwidth=4 expandtab:
4 *
5 * LICENSE: GNU Affero General Public License, version 3 (AGPL-3.0-or-later)
6 * Copyright 2001 - 2020 Ampache.org
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20 *
21 */
22
23declare(strict_types=1);
24
25namespace Ampache\Gui\System;
26
27use Ampache\Config\ConfigContainerInterface;
28use Ampache\Config\ConfigurationKeyEnum;
29use Ampache\MockeryTestCase;
30use Mockery\MockInterface;
31
32class UpdateViewAdapterTest extends MockeryTestCase
33{
34    /** @var MockInterface|ConfigContainerInterface|null */
35    private ?MockInterface $configContainer;
36
37    private ?UpdateViewAdapter $subject;
38
39    public function setUp(): void
40    {
41        $this->configContainer = $this->mock(ConfigContainerInterface::class);
42
43        $this->subject = new UpdateViewAdapter(
44            $this->configContainer
45        );
46    }
47
48    public function testGetHtmlLanguageReturnsSetLang(): void
49    {
50        $lang = 'kl_KL';
51
52        $this->configContainer->shouldReceive('get')
53            ->with(ConfigurationKeyEnum::LANG)
54            ->once()
55            ->andReturn($lang);
56
57        $this->assertSame(
58            'kl-KL',
59            $this->subject->getHtmlLanguage()
60        );
61    }
62
63    public function testGetCharsetReturnsValue(): void
64    {
65        $value = 'some-charset';
66
67        $this->configContainer->shouldReceive('get')
68            ->with(ConfigurationKeyEnum::SITE_CHARSET)
69            ->once()
70            ->andReturn($value);
71
72        $this->assertSame(
73            $value,
74            $this->subject->getCharset()
75        );
76    }
77
78    public function testGetTitleReturnsValue(): void
79    {
80        $value = 'some-title';
81
82        $this->configContainer->shouldReceive('get')
83            ->with(ConfigurationKeyEnum::SITE_TITLE)
84            ->once()
85            ->andReturn($value);
86
87        $this->assertSame(
88            sprintf(
89                '%s - Update',
90                $value
91            ),
92            $this->subject->getTitle()
93        );
94    }
95
96    public function testGetInstallationTitleReturnsValue(): void
97    {
98        $this->assertSame(
99            'Ampache :: For the Love of Music - Installation',
100            $this->subject->getInstallationTitle()
101        );
102    }
103
104    public function testGetUpdateActionUrlReturnsValue(): void
105    {
106        $webPath = 'some-web-path';
107
108        $this->configContainer->shouldReceive('getWebPath')
109            ->withNoArgs()
110            ->once()
111            ->andReturn($webPath);
112
113        $this->assertSame(
114            sprintf(
115                '%s/update.php?action=update',
116                $webPath
117            ),
118            $this->subject->getUpdateActionUrl()
119        );
120    }
121
122    public function testGetWebPathReturnsValue(): void
123    {
124        $webPath = 'some-web-path';
125
126        $this->configContainer->shouldReceive('getWebPath')
127            ->withNoArgs()
128            ->once()
129            ->andReturn($webPath);
130
131        $this->assertSame(
132            $webPath,
133            $this->subject->getWebPath()
134        );
135    }
136}
137