Fix Display\ResultsTest test on Windows
[phpmyadmin.git] / test / classes / UserPreferencesHeaderTest.php
blobf079aa0d8a60ce040e2e194771e62c8514fe63a3
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * tests for methods under PhpMyAdmin\UserPreferencesHeader class
6 * @package PhpMyAdmin-test
7 */
8 declare(strict_types=1);
10 namespace PhpMyAdmin\Tests;
12 use PhpMyAdmin\Config\ConfigFile;
13 use PhpMyAdmin\DatabaseInterface;
14 use PhpMyAdmin\Relation;
15 use PhpMyAdmin\Template;
16 use PhpMyAdmin\Tests\PmaTestCase;
17 use PhpMyAdmin\UserPreferences;
18 use PhpMyAdmin\UserPreferencesHeader;
19 use Throwable;
20 use Twig_Error_Loader;
21 use Twig_Error_Runtime;
22 use Twig_Error_Syntax;
24 /**
25 * tests for methods under PhpMyAdmin\UserPreferencesHeader class
27 * @package PhpMyAdmin-test
29 class UserPreferencesHeaderTest extends PmaTestCase
31 /**
32 * Setup various pre conditions
34 * @return void
36 protected function setUp(): void
39 global $cfg;
40 include ROOT_PATH . 'libraries/config.default.php';
42 $GLOBALS['server'] = 0;
43 $GLOBALS['PMA_PHP_SELF'] = '/prefs_forms.php';
46 /**
47 * Test for getContent with selected tab
49 * @return void
50 * @throws Throwable
51 * @throws Twig_Error_Loader
52 * @throws Twig_Error_Runtime
53 * @throws Twig_Error_Syntax
55 public function testGetContentWithSelectedTab(): void
57 $dbi = $this->getMockBuilder(DatabaseInterface::class)
58 ->disableOriginalConstructor()
59 ->getMock();
61 $GLOBALS['dbi'] = $dbi;
62 $_GET['form'] = 'Features';
64 $template = new Template();
65 $content = UserPreferencesHeader::getContent($template, new Relation($dbi, $template));
67 $this->assertStringContainsString(
68 '<li class="active">',
69 $content
71 $this->assertStringContainsString(
72 '<a href="prefs_forms.php?form=Features&amp;server=0&amp;lang=en" class="tabactive">',
73 $content
75 $this->assertStringContainsString(
76 '<img src="themes/dot.gif" title="Features" alt="Features" class="icon ic_b_tblops">&nbsp;Features',
77 $content
81 /**
82 * Test for getContent with "saved" get parameter
84 * @return void
85 * @throws Throwable
86 * @throws Twig_Error_Loader
87 * @throws Twig_Error_Runtime
88 * @throws Twig_Error_Syntax
90 public function testGetContentAfterSave(): void
92 $dbi = $this->getMockBuilder(DatabaseInterface::class)
93 ->disableOriginalConstructor()
94 ->getMock();
96 $GLOBALS['dbi'] = $dbi;
97 $_GET['saved'] = true;
99 $template = new Template();
100 $this->assertStringContainsString(
101 'Configuration has been saved.',
102 UserPreferencesHeader::getContent($template, new Relation($dbi, $template))
107 * Test for getContent with session storage
109 * @return void
110 * @throws Throwable
111 * @throws Twig_Error_Loader
112 * @throws Twig_Error_Runtime
113 * @throws Twig_Error_Syntax
115 public function testGetContentWithSessionStorage(): void
117 $dbi = $this->getMockBuilder(DatabaseInterface::class)
118 ->disableOriginalConstructor()
119 ->getMock();
121 $GLOBALS['dbi'] = $dbi;
123 $template = new Template();
124 $this->assertStringContainsString(
125 'Your preferences will be saved for current session only. Storing them permanently requires',
126 UserPreferencesHeader::getContent($template, new Relation($dbi, $template))