3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests
;
7 use PhpMyAdmin\ConfigStorage\RelationParameters
;
8 use PhpMyAdmin\DatabaseInterface
;
9 use PhpMyAdmin\SystemDatabase
;
10 use PhpMyAdmin\Tests\Stubs\DummyResult
;
13 * @covers \PhpMyAdmin\SystemDatabase
15 class SystemDatabaseTest
extends AbstractTestCase
18 * SystemDatabase instance
25 * Setup function for test cases
27 protected function setUp(): void
31 * SET these to avoid undefine d index error
33 $GLOBALS['server'] = 1;
34 $GLOBALS['cfg']['Server']['pmadb'] = '';
36 $resultStub = $this->createMock(DummyResult
::class);
38 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
39 ->disableOriginalConstructor()
42 $dbi->expects($this->any())
44 ->will($this->returnValue($resultStub));
46 $_SESSION['relation'] = [];
47 $_SESSION['relation'][$GLOBALS['server']] = RelationParameters
::fromArray([
48 'table_coords' => 'table_name',
49 'displaywork' => true,
50 'db' => 'information_schema',
51 'table_info' => 'table_info',
56 'column_info' => 'column_info',
57 'relation' => 'relation',
60 $this->sysDb
= new SystemDatabase($dbi);
64 * Tests for PMA_getExistingTransformationData() method.
66 public function testPMAGetExistingTransformationData(): void
69 $ret = $this->sysDb
->getExistingTransformationData($db);
71 //validate that is the same as $dbi->tryQuery
72 $this->assertInstanceOf(DummyResult
::class, $ret);
76 * Tests for PMA_getNewTransformationDataSql() method.
78 public function testPMAGetNewTransformationDataSql(): void
80 $resultStub = $this->createMock(DummyResult
::class);
82 $resultStub->expects($this->any())
83 ->method('fetchAssoc')
87 'table_name' => 'table_name',
88 'column_name' => 'column_name',
89 'comment' => 'comment',
90 'mimetype' => 'mimetype',
91 'transformation' => 'transformation',
92 'transformation_options' => 'transformation_options',
100 'table_name' => 'table_name',
101 'refering_column' => 'column_name',
104 $view_name = 'view_name';
106 $ret = $this->sysDb
->getNewTransformationDataSql(
113 $sql = 'INSERT INTO `information_schema`.`column_info` '
114 . '(`db_name`, `table_name`, `column_name`, `comment`, `mimetype`, '
115 . '`transformation`, `transformation_options`) VALUES '
116 . "('PMA_db', 'view_name', 'column_name', 'comment', 'mimetype', "
117 . "'transformation', 'transformation_options')";
119 $this->assertEquals($sql, $ret);