3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests
;
7 use PhpMyAdmin\Bookmark
;
8 use PhpMyAdmin\ConfigStorage\Features\BookmarkFeature
;
9 use PhpMyAdmin\Dbal\DatabaseName
;
10 use PhpMyAdmin\Dbal\TableName
;
13 * @covers \PhpMyAdmin\Bookmark
15 class BookmarkTest
extends AbstractTestCase
18 * Sets up the fixture, for example, opens a network connection.
19 * This method is called before a test is executed.
21 protected function setUp(): void
24 $GLOBALS['cfg']['Server']['user'] = 'root';
25 $GLOBALS['cfg']['Server']['pmadb'] = 'phpmyadmin';
26 $GLOBALS['cfg']['Server']['bookmarktable'] = 'pma_bookmark';
27 $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 1000;
28 $GLOBALS['cfg']['ServerDefault'] = 1;
29 $GLOBALS['server'] = 1;
33 * Tests for Bookmark::getList()
35 public function testGetList(): void
37 $this->dummyDbi
->addResult(
38 'SELECT * FROM `phpmyadmin`.`pma_bookmark` WHERE ( `user` = \'\' OR `user` = \'root\' )'
39 . ' AND dbase = \'sakila\' ORDER BY label ASC',
40 [['1', 'sakila', 'root', 'label', 'SELECT * FROM `actor` WHERE `actor_id` < 10;']],
41 ['id', 'dbase', 'user', 'label', 'query']
43 $actual = Bookmark
::getList(
44 new BookmarkFeature(DatabaseName
::fromValue('phpmyadmin'), TableName
::fromValue('pma_bookmark')),
46 $GLOBALS['cfg']['Server']['user'],
49 $this->assertContainsOnlyInstancesOf(Bookmark
::class, $actual);
50 $this->assertAllSelectsConsumed();
54 * Tests for Bookmark::get()
56 public function testGet(): void
58 $this->dummyDbi
->addSelectDb('phpmyadmin');
62 $GLOBALS['cfg']['Server']['user'],
67 $this->assertAllSelectsConsumed();
71 * Tests for Bookmark::save()
73 public function testSave(): void
76 'bkm_database' => 'phpmyadmin',
78 'bkm_sql_query' => 'SELECT "phpmyadmin"',
79 'bkm_label' => 'bookmark1',
82 $bookmark = Bookmark
::createBookmark($GLOBALS['dbi'], $bookmarkData);
83 $this->assertNotFalse($bookmark);
84 $this->dummyDbi
->addSelectDb('phpmyadmin');
85 $this->assertFalse($bookmark->save());
86 $this->assertAllSelectsConsumed();