Translated using Weblate (Slovenian)
[phpmyadmin.git] / test / classes / ThemeTest.php
blob66efdf0b7a5b966dee8524f11f50b466812b1501
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin\Tests;
7 use PhpMyAdmin\Theme;
8 use function filemtime;
10 class ThemeTest extends AbstractTestCase
12 /** @var Theme */
13 protected $object;
15 /** @var Theme backup for session theme */
16 protected $backup;
18 /**
19 * Sets up the fixture, for example, opens a network connection.
20 * This method is called before a test is executed.
22 protected function setUp(): void
24 parent::setUp();
25 parent::defineVersionConstants();
26 parent::setTheme();
27 $this->object = new Theme();
28 $this->backup = $GLOBALS['PMA_Theme'];
29 $GLOBALS['PMA_Theme'] = $this->object;
30 parent::setGlobalConfig();
31 $GLOBALS['PMA_Config']->enableBc();
32 $GLOBALS['text_dir'] = 'ltr';
33 $GLOBALS['server'] = '99';
36 /**
37 * Tears down the fixture, for example, closes a network connection.
38 * This method is called after a test is executed.
40 protected function tearDown(): void
42 parent::tearDown();
43 $GLOBALS['PMA_Theme'] = $this->backup;
46 /**
47 * Test for Theme::loadInfo
49 * @group medium
51 public function testCheckImgPathNotExisted(): void
53 $this->object->setPath('path/to/nowhere');
54 $this->assertFalse($this->object->loadInfo());
57 /**
58 * Test for Theme::loadInfo
60 public function testCheckImgPathIncorrect(): void
62 $this->object->setPath(ROOT_PATH . 'test/classes/_data/incorrect_theme');
63 $this->assertFalse(
64 $this->object->loadInfo(),
65 'Theme name is not properly set'
69 /**
70 * Test for Theme::getName, getVersion
72 public function testCheckImgPathFull(): void
74 $this->object->setFsPath(ROOT_PATH . 'test/classes/_data/gen_version_info/');
75 $this->assertTrue($this->object->loadInfo());
76 $this->assertEquals('Test Theme', $this->object->getName());
77 $this->assertEquals('5.1', $this->object->getVersion());
80 /**
81 * Test for Theme::loadInfo
83 public function testLoadInfo(): void
85 $this->object->setFsPath(ROOT_PATH . 'themes/original/');
86 $infofile = $this->object->getFsPath() . 'theme.json';
87 $this->assertTrue($this->object->loadInfo());
89 $this->assertEquals(
90 filemtime($infofile),
91 $this->object->mtimeInfo
94 $this->object->setPath(ROOT_PATH . 'themes/original');
95 $this->object->mtimeInfo = filemtime($infofile);
96 $this->assertTrue($this->object->loadInfo());
97 $this->assertEquals('Original', $this->object->getName());
101 * Test for Theme::load
103 public function testLoad(): void
105 $newTheme = Theme::load('./themes/original', ROOT_PATH . 'themes/original');
106 $this->assertNotNull($newTheme);
110 * Test for Theme::load
112 public function testLoadNotExisted(): void
114 $this->assertFalse(Theme::load('/path/to/nowhere', '/path/to/nowhere'));
118 * Test fir Theme::checkImgPath
120 public function testCheckImgPathFallback(): void
122 $this->object->setPath('path/to/nowhere');
123 $this->assertTrue($this->object->checkImgPath());
127 * Test for Theme::checkImgPath
129 public function testCheckImgPath(): void
131 $this->object->setPath(ROOT_PATH . 'themes/original');
132 $this->assertTrue($this->object->checkImgPath());
136 * Test for Theme::getPath
138 public function testGetSetPath(): void
140 $this->assertEmpty($this->object->getPath());
141 $this->object->setPath(ROOT_PATH . 'themes/original');
143 $this->assertEquals(ROOT_PATH . 'themes/original', $this->object->getPath());
147 * Test for Theme::checkVersion
149 * @depends testLoadInfo
151 public function testGetSetCheckVersion(): void
153 $this->assertEquals(
154 '0.0.0.0',
155 $this->object->getVersion(),
156 'Version 0.0.0.0 by default'
159 $this->object->setVersion('1.2.3.4');
160 $this->assertEquals('1.2.3.4', $this->object->getVersion());
162 $this->assertFalse($this->object->checkVersion('0.0.1.1'));
163 $this->assertTrue($this->object->checkVersion('2.0.1.1'));
167 * Test for Theme::getName
169 public function testGetSetName(): void
171 $this->assertEmpty($this->object->getName(), 'Name is empty by default');
172 $this->object->setName('New Theme Name');
174 $this->assertEquals('New Theme Name', $this->object->getName());
178 * Test for Theme::getId
180 public function testGetSetId(): void
182 $this->assertEmpty($this->object->getId(), 'ID is empty by default');
183 $this->object->setId('NewID');
185 $this->assertEquals('NewID', $this->object->getId());
189 * Test for Theme::getImgPath
191 public function testGetSetImgPath(): void
193 $this->assertEmpty(
194 $this->object->getImgPath(),
195 'ImgPath is empty by default'
197 $this->object->setImgPath('/new/path');
199 $this->assertEquals('/new/path', $this->object->getImgPath());
203 * Test for getPrintPreview().
205 public function testGetPrintPreview(): void
207 parent::setLanguage();
208 $this->assertStringContainsString(
209 '<h2>' . "\n" . ' (0.0.0.0)',
210 $this->object->getPrintPreview()
212 $this->assertStringContainsString(
213 'name="" href="index.php?route=/set-theme&amp;set_theme=&amp;server=99&amp;lang=en">',
214 $this->object->getPrintPreview()
216 $this->assertStringContainsString(
217 'No preview available.',
218 $this->object->getPrintPreview()
223 * Test for getImgPath
225 * @param string|null $file file name for image
226 * @param string|null $fallback fallback image
227 * @param string $output expected output
229 * @dataProvider providerForGetImgPath
231 public function testGetImgPath(?string $file, ?string $fallback, string $output): void
233 $this->assertEquals(
234 $this->object->getImgPath($file, $fallback),
235 $output
240 * Provider for testGetImgPath
242 * @return array
244 public function providerForGetImgPath(): array
246 return [
248 null,
249 null,
253 'screen.png',
254 null,
255 './themes/pmahomme/img/screen.png',
258 'arrow_ltr.png',
259 null,
260 './themes/pmahomme/img/arrow_ltr.png',
263 'logo_right.png',
264 'pma_logo.png',
265 './themes/pmahomme/img/pma_logo.png',