2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * tests for methods under PhpMyAdmin\UserPreferencesHeader class
6 * @package PhpMyAdmin-test
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
;
20 use Twig_Error_Loader
;
21 use Twig_Error_Runtime
;
22 use Twig_Error_Syntax
;
25 * tests for methods under PhpMyAdmin\UserPreferencesHeader class
27 * @package PhpMyAdmin-test
29 class UserPreferencesHeaderTest
extends PmaTestCase
32 * Setup various pre conditions
36 protected function setUp(): void
40 include ROOT_PATH . 'libraries/config.default.php';
42 $GLOBALS['server'] = 0;
43 $GLOBALS['PMA_PHP_SELF'] = '/prefs_forms.php';
47 * Test for getContent with selected tab
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()
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">',
71 $this->assertStringContainsString(
72 '<a href="prefs_forms.php?form=Features&server=0&lang=en" class="tabactive">',
75 $this->assertStringContainsString(
76 '<img src="themes/dot.gif" title="Features" alt="Features" class="icon ic_b_tblops"> Features',
82 * Test for getContent with "saved" get parameter
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()
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
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()
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))