3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests
;
8 use function filemtime
;
10 class ThemeTest
extends AbstractTestCase
15 /** @var Theme backup for session theme */
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
25 parent
::defineVersionConstants();
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';
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
43 $GLOBALS['PMA_Theme'] = $this->backup
;
47 * Test for Theme::loadInfo
51 public function testCheckImgPathNotExisted(): void
53 $this->object->setPath('path/to/nowhere');
54 $this->assertFalse($this->object->loadInfo());
58 * Test for Theme::loadInfo
60 public function testCheckImgPathIncorrect(): void
62 $this->object->setPath(ROOT_PATH
. 'test/classes/_data/incorrect_theme');
64 $this->object->loadInfo(),
65 'Theme name is not properly set'
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());
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());
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
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
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&set_theme=&server=99&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
234 $this->object->getImgPath($file, $fallback),
240 * Provider for testGetImgPath
244 public function providerForGetImgPath(): array
255 './themes/pmahomme/img/screen.png',
260 './themes/pmahomme/img/arrow_ltr.png',
265 './themes/pmahomme/img/pma_logo.png',