Translated using Weblate (Lithuanian)
[phpmyadmin.git] / test / classes / BookmarkTest.php
blob588c77c956c5c12f34fc10c7a01cf6f97b505457
1 <?php
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;
12 /**
13 * @covers \PhpMyAdmin\Bookmark
15 class BookmarkTest extends AbstractTestCase
17 /**
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
23 parent::setUp();
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;
32 /**
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')),
45 $GLOBALS['dbi'],
46 $GLOBALS['cfg']['Server']['user'],
47 'sakila'
49 $this->assertContainsOnlyInstancesOf(Bookmark::class, $actual);
50 $this->assertAllSelectsConsumed();
53 /**
54 * Tests for Bookmark::get()
56 public function testGet(): void
58 $this->dummyDbi->addSelectDb('phpmyadmin');
59 $this->assertNull(
60 Bookmark::get(
61 $GLOBALS['dbi'],
62 $GLOBALS['cfg']['Server']['user'],
63 'phpmyadmin',
64 '1'
67 $this->assertAllSelectsConsumed();
70 /**
71 * Tests for Bookmark::save()
73 public function testSave(): void
75 $bookmarkData = [
76 'bkm_database' => 'phpmyadmin',
77 'bkm_user' => 'root',
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();