Extract dependency on Relation from the Node classes
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
parent
20f88ecf22
commit
96ec170157
@ -41,7 +41,7 @@ class Navigation
|
||||
|
||||
public function __construct(private Template $template, private Relation $relation, private DatabaseInterface $dbi)
|
||||
{
|
||||
$this->tree = new NavigationTree($this->template, $this->dbi);
|
||||
$this->tree = new NavigationTree($this->template, $this->dbi, $this->relation);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -8,6 +8,8 @@ declare(strict_types=1);
|
||||
namespace PhpMyAdmin\Navigation;
|
||||
|
||||
use PhpMyAdmin\CheckUserPrivileges;
|
||||
use PhpMyAdmin\ConfigStorage\Relation;
|
||||
use PhpMyAdmin\ConfigStorage\RelationParameters;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Html\Generator;
|
||||
use PhpMyAdmin\Navigation\Nodes\Node;
|
||||
@ -136,8 +138,11 @@ class NavigationTree
|
||||
*/
|
||||
private bool $largeGroupWarning = false;
|
||||
|
||||
public function __construct(private Template $template, private DatabaseInterface $dbi)
|
||||
private RelationParameters $relationParameters;
|
||||
|
||||
public function __construct(private Template $template, private DatabaseInterface $dbi, Relation $relation)
|
||||
{
|
||||
$this->relationParameters = $relation->getRelationParameters();
|
||||
$checkUserPrivileges = new CheckUserPrivileges($this->dbi);
|
||||
$checkUserPrivileges->getPrivileges();
|
||||
|
||||
@ -307,8 +312,8 @@ class NavigationTree
|
||||
$retval = $this->tree;
|
||||
|
||||
// Add all databases unconditionally
|
||||
$data = $this->tree->getData('databases', $this->pos, $this->searchClause);
|
||||
$hiddenCounts = $this->tree->getNavigationHidingData();
|
||||
$data = $this->tree->getData($this->relationParameters, 'databases', $this->pos, $this->searchClause);
|
||||
$hiddenCounts = $this->tree->getNavigationHidingData($this->relationParameters->navigationItemsHidingFeature);
|
||||
foreach ($data as $db) {
|
||||
$node = NodeFactory::getInstance(NodeDatabase::class, $db);
|
||||
if (isset($hiddenCounts[$db])) {
|
||||
@ -381,7 +386,7 @@ class NavigationTree
|
||||
}
|
||||
|
||||
if (count($container->children) <= 1) {
|
||||
$dbData = $db->getData($container->realName, $pos2, $this->searchClause2);
|
||||
$dbData = $db->getData($this->relationParameters, $container->realName, $pos2, $this->searchClause2);
|
||||
foreach ($dbData as $item) {
|
||||
switch ($container->realName) {
|
||||
case 'events':
|
||||
@ -454,7 +459,7 @@ class NavigationTree
|
||||
return false;
|
||||
}
|
||||
|
||||
$tableData = $table->getData($container->realName, $pos3);
|
||||
$tableData = $table->getData($this->relationParameters, $container->realName, $pos3);
|
||||
foreach ($tableData as $item) {
|
||||
switch ($container->realName) {
|
||||
case 'indexes':
|
||||
@ -558,7 +563,7 @@ class NavigationTree
|
||||
private function addDbContainers(NodeDatabase $db, string $type, int $pos2): array
|
||||
{
|
||||
// Get items to hide
|
||||
$hidden = $db->getHiddenItems('group');
|
||||
$hidden = $db->getHiddenItems($this->relationParameters, 'group');
|
||||
if (! $GLOBALS['cfg']['NavigationTreeShowTables'] && ! in_array('tables', $hidden)) {
|
||||
$hidden[] = 'tables';
|
||||
}
|
||||
@ -1108,7 +1113,7 @@ class NavigationTree
|
||||
];
|
||||
}
|
||||
|
||||
$controlButtons .= $node->getHtmlForControlButtons();
|
||||
$controlButtons .= $node->getHtmlForControlButtons($this->relationParameters->navigationItemsHidingFeature);
|
||||
$wrap = true;
|
||||
} else {
|
||||
$node->visible = true;
|
||||
|
||||
@ -7,7 +7,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Navigation\Nodes;
|
||||
|
||||
use PhpMyAdmin\ConfigStorage\Relation;
|
||||
use PhpMyAdmin\ConfigStorage\Features\NavigationItemsHidingFeature;
|
||||
use PhpMyAdmin\ConfigStorage\RelationParameters;
|
||||
use PhpMyAdmin\Dbal\Connection;
|
||||
use PhpMyAdmin\Html\Generator;
|
||||
use PhpMyAdmin\Util;
|
||||
@ -115,8 +116,6 @@ class Node
|
||||
*/
|
||||
public int $pos3 = 0;
|
||||
|
||||
protected Relation $relation;
|
||||
|
||||
/** @var string $displayName display name for the navigation tree */
|
||||
public string|null $displayName = null;
|
||||
|
||||
@ -142,7 +141,6 @@ class Node
|
||||
}
|
||||
|
||||
$this->isGroup = $isGroup;
|
||||
$this->relation = new Relation($GLOBALS['dbi']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -352,8 +350,12 @@ class Node
|
||||
*
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function getData(string $type, int $pos, string $searchClause = ''): array
|
||||
{
|
||||
public function getData(
|
||||
RelationParameters $relationParameters,
|
||||
string $type,
|
||||
int $pos,
|
||||
string $searchClause = '',
|
||||
): array {
|
||||
if (isset($GLOBALS['cfg']['Server']['DisableIS']) && ! $GLOBALS['cfg']['Server']['DisableIS']) {
|
||||
return $this->getDataFromInfoSchema($pos, $searchClause);
|
||||
}
|
||||
@ -544,7 +546,7 @@ class Node
|
||||
*
|
||||
* @return string HTML for control buttons
|
||||
*/
|
||||
public function getHtmlForControlButtons(): string
|
||||
public function getHtmlForControlButtons(NavigationItemsHidingFeature|null $navigationItemsHidingFeature): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
@ -602,9 +604,8 @@ class Node
|
||||
*
|
||||
* @return mixed[]|null array containing the count of hidden elements for each database
|
||||
*/
|
||||
public function getNavigationHidingData(): array|null
|
||||
public function getNavigationHidingData(NavigationItemsHidingFeature|null $navigationItemsHidingFeature): array|null
|
||||
{
|
||||
$navigationItemsHidingFeature = $this->relation->getRelationParameters()->navigationItemsHidingFeature;
|
||||
if ($navigationItemsHidingFeature !== null) {
|
||||
$navTable = Util::backquote($navigationItemsHidingFeature->database)
|
||||
. '.' . Util::backquote($navigationItemsHidingFeature->navigationHiding);
|
||||
|
||||
@ -7,6 +7,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Navigation\Nodes;
|
||||
|
||||
use PhpMyAdmin\ConfigStorage\Features\NavigationItemsHidingFeature;
|
||||
use PhpMyAdmin\ConfigStorage\RelationParameters;
|
||||
use PhpMyAdmin\Dbal\Connection;
|
||||
use PhpMyAdmin\Html\Generator;
|
||||
use PhpMyAdmin\Url;
|
||||
@ -257,8 +259,12 @@ class NodeDatabase extends Node
|
||||
*
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function getData(string $type, int $pos, string $searchClause = ''): array
|
||||
{
|
||||
public function getData(
|
||||
RelationParameters $relationParameters,
|
||||
string $type,
|
||||
int $pos,
|
||||
string $searchClause = '',
|
||||
): array {
|
||||
$retval = [];
|
||||
switch ($type) {
|
||||
case 'tables':
|
||||
@ -281,9 +287,8 @@ class NodeDatabase extends Node
|
||||
}
|
||||
|
||||
// Remove hidden items so that they are not displayed in navigation tree
|
||||
$relationParameters = $this->relation->getRelationParameters();
|
||||
if ($relationParameters->navigationItemsHidingFeature !== null) {
|
||||
$hiddenItems = $this->getHiddenItems(substr($type, 0, -1));
|
||||
$hiddenItems = $this->getHiddenItems($relationParameters, substr($type, 0, -1));
|
||||
foreach ($retval as $key => $item) {
|
||||
if (! in_array($item, $hiddenItems)) {
|
||||
continue;
|
||||
@ -304,9 +309,8 @@ class NodeDatabase extends Node
|
||||
*
|
||||
* @return mixed[] Array containing hidden items of given type
|
||||
*/
|
||||
public function getHiddenItems(string $type): array
|
||||
public function getHiddenItems(RelationParameters $relationParameters, string $type): array
|
||||
{
|
||||
$relationParameters = $this->relation->getRelationParameters();
|
||||
if ($relationParameters->navigationItemsHidingFeature === null || $relationParameters->user === null) {
|
||||
return [];
|
||||
}
|
||||
@ -564,11 +568,10 @@ class NodeDatabase extends Node
|
||||
*
|
||||
* @return string HTML for control buttons
|
||||
*/
|
||||
public function getHtmlForControlButtons(): string
|
||||
public function getHtmlForControlButtons(NavigationItemsHidingFeature|null $navigationItemsHidingFeature): string
|
||||
{
|
||||
$ret = '';
|
||||
$relationParameters = $this->relation->getRelationParameters();
|
||||
if ($relationParameters->navigationItemsHidingFeature !== null) {
|
||||
if ($navigationItemsHidingFeature !== null) {
|
||||
if ($this->hiddenCount > 0) {
|
||||
$params = ['showUnhideDialog' => true, 'dbName' => $this->realName];
|
||||
$ret = '<span class="dbItemControls">'
|
||||
|
||||
@ -7,6 +7,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Navigation\Nodes;
|
||||
|
||||
use PhpMyAdmin\ConfigStorage\Features\NavigationItemsHidingFeature;
|
||||
use PhpMyAdmin\Html\Generator;
|
||||
use PhpMyAdmin\Url;
|
||||
|
||||
@ -31,11 +32,10 @@ abstract class NodeDatabaseChild extends Node
|
||||
*
|
||||
* @return string HTML for control buttons
|
||||
*/
|
||||
public function getHtmlForControlButtons(): string
|
||||
public function getHtmlForControlButtons(NavigationItemsHidingFeature|null $navigationItemsHidingFeature): string
|
||||
{
|
||||
$ret = '';
|
||||
$relationParameters = $this->relation->getRelationParameters();
|
||||
if ($relationParameters->navigationItemsHidingFeature !== null) {
|
||||
if ($navigationItemsHidingFeature !== null) {
|
||||
$params = [
|
||||
'hideNavItem' => true,
|
||||
'itemType' => $this->getItemType(),
|
||||
|
||||
@ -7,6 +7,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Navigation\Nodes;
|
||||
|
||||
use PhpMyAdmin\ConfigStorage\RelationParameters;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
@ -146,8 +147,12 @@ class NodeTable extends NodeDatabaseChild
|
||||
*
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function getData(string $type, int $pos, string $searchClause = ''): array
|
||||
{
|
||||
public function getData(
|
||||
RelationParameters $relationParameters,
|
||||
string $type,
|
||||
int $pos,
|
||||
string $searchClause = '',
|
||||
): array {
|
||||
$maxItems = $GLOBALS['cfg']['MaxNavigationItems'];
|
||||
$retval = [];
|
||||
$db = $this->realParent()->realName;
|
||||
|
||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Tests\Navigation;
|
||||
|
||||
use PhpMyAdmin\ConfigStorage\Relation;
|
||||
use PhpMyAdmin\Navigation\NavigationTree;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Tests\AbstractTestCase;
|
||||
@ -39,7 +40,7 @@ class NavigationTreeTest extends AbstractTestCase
|
||||
$GLOBALS['db'] = 'db';
|
||||
$GLOBALS['table'] = '';
|
||||
|
||||
$this->object = new NavigationTree(new Template(), $GLOBALS['dbi']);
|
||||
$this->object = new NavigationTree(new Template(), $GLOBALS['dbi'], new Relation($GLOBALS['dbi']));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,7 +106,7 @@ class NavigationTreeTest extends AbstractTestCase
|
||||
$dbi = $this->createDatabaseInterface($dummyDbi);
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$object = new NavigationTree(new Template(), $dbi);
|
||||
$object = new NavigationTree(new Template(), $dbi, new Relation($dbi));
|
||||
$result = $object->renderState();
|
||||
$this->assertStringContainsString('<li class="first navGroup">', $result);
|
||||
$this->assertStringContainsString('functions' . "\n", $result);
|
||||
|
||||
@ -13,17 +13,6 @@ use PHPUnit\Framework\Attributes\CoversClass;
|
||||
#[CoversClass(NodeFactory::class)]
|
||||
class NodeFactoryTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$GLOBALS['server'] = 0;
|
||||
}
|
||||
|
||||
public function testDefaultNode(): void
|
||||
{
|
||||
$node = NodeFactory::getInstance(Node::class);
|
||||
|
||||
@ -11,17 +11,6 @@ use PHPUnit\Framework\Attributes\CoversClass;
|
||||
#[CoversClass(NodeColumnContainer::class)]
|
||||
class NodeColumnContainerTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$GLOBALS['server'] = 0;
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$parent = new NodeColumnContainer();
|
||||
|
||||
@ -14,8 +14,6 @@ final class NodeColumnTest extends AbstractTestCase
|
||||
{
|
||||
public function testColumnNode(): void
|
||||
{
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
|
||||
$nodeColumn = new NodeColumn([
|
||||
'name' => 'actor_id',
|
||||
'key' => 'PRI',
|
||||
@ -47,8 +45,6 @@ final class NodeColumnTest extends AbstractTestCase
|
||||
|
||||
public function testColumnNodeWithTruncatedDefaultValue(): void
|
||||
{
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
|
||||
$nodeColumn = new NodeColumn([
|
||||
'name' => 'last_update',
|
||||
'key' => '',
|
||||
@ -62,8 +58,6 @@ final class NodeColumnTest extends AbstractTestCase
|
||||
|
||||
public function testColumnNodeWithTruncatedDefaultValue2(): void
|
||||
{
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
|
||||
$nodeColumn = new NodeColumn([
|
||||
'name' => 'email',
|
||||
'key' => 'UNI',
|
||||
@ -77,8 +71,6 @@ final class NodeColumnTest extends AbstractTestCase
|
||||
|
||||
public function testColumnNodeWithoutTruncatedDefaultValue(): void
|
||||
{
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
|
||||
$nodeColumn = new NodeColumn([
|
||||
'name' => 'email',
|
||||
'key' => '',
|
||||
|
||||
@ -36,7 +36,6 @@ class NodeDatabaseChildTest extends AbstractTestCase
|
||||
|
||||
parent::setLanguage();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$GLOBALS['cfg']['DefaultTabDatabase'] = 'structure';
|
||||
$GLOBALS['server'] = 1;
|
||||
$GLOBALS['cfg']['ServerDefault'] = 1;
|
||||
@ -69,12 +68,18 @@ class NodeDatabaseChildTest extends AbstractTestCase
|
||||
*/
|
||||
public function testGetHtmlForControlButtons(): void
|
||||
{
|
||||
$relationParameters = RelationParameters::fromArray([
|
||||
'db' => 'pmadb',
|
||||
'navwork' => true,
|
||||
'navigationhiding' => 'navigationhiding',
|
||||
]);
|
||||
|
||||
$parent = new NodeDatabase('parent');
|
||||
$parent->addChild($this->object);
|
||||
$this->object->expects($this->once())
|
||||
->method('getItemType')
|
||||
->will($this->returnValue('itemType'));
|
||||
$html = $this->object->getHtmlForControlButtons();
|
||||
$html = $this->object->getHtmlForControlButtons($relationParameters->navigationItemsHidingFeature);
|
||||
|
||||
$this->assertStringStartsWith('<span class="navItemControls">', $html);
|
||||
$this->assertStringEndsWith('</span>', $html);
|
||||
|
||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Tests\Navigation\Nodes;
|
||||
|
||||
use PhpMyAdmin\ConfigStorage\RelationParameters;
|
||||
use PhpMyAdmin\Navigation\Nodes\NodeDatabase;
|
||||
use PhpMyAdmin\Tests\AbstractTestCase;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
@ -11,21 +12,6 @@ use PHPUnit\Framework\Attributes\CoversClass;
|
||||
#[CoversClass(NodeDatabase::class)]
|
||||
class NodeDatabaseTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['cfg']['DefaultTabDatabase'] = 'structure';
|
||||
$GLOBALS['cfg']['MaxNavigationItems'] = 250;
|
||||
$GLOBALS['cfg']['Server'] = [];
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*/
|
||||
@ -48,6 +34,9 @@ class NodeDatabaseTest extends AbstractTestCase
|
||||
*/
|
||||
public function testGetPresence(): void
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = true;
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
|
||||
$parent = new NodeDatabase('default');
|
||||
$this->assertEquals(
|
||||
2,
|
||||
@ -76,21 +65,30 @@ class NodeDatabaseTest extends AbstractTestCase
|
||||
*/
|
||||
public function testGetData(): void
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = true;
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
|
||||
$relationParameters = RelationParameters::fromArray([
|
||||
'db' => 'pmadb',
|
||||
'navwork' => true,
|
||||
'navigationhiding' => 'navigationhiding',
|
||||
]);
|
||||
|
||||
$parent = new NodeDatabase('default');
|
||||
|
||||
$tables = $parent->getData('tables', 0);
|
||||
$tables = $parent->getData($relationParameters, 'tables', 0);
|
||||
$this->assertContains('test1', $tables);
|
||||
$this->assertContains('test2', $tables);
|
||||
|
||||
$views = $parent->getData('views', 0);
|
||||
$views = $parent->getData($relationParameters, 'views', 0);
|
||||
$this->assertEmpty($views);
|
||||
|
||||
$functions = $parent->getData('functions', 0);
|
||||
$functions = $parent->getData($relationParameters, 'functions', 0);
|
||||
$this->assertContains('testFunction', $functions);
|
||||
$this->assertCount(1, $functions);
|
||||
|
||||
$this->assertEmpty($parent->getData('procedures', 0));
|
||||
$this->assertEmpty($parent->getData('events', 0));
|
||||
$this->assertEmpty($parent->getData($relationParameters, 'procedures', 0));
|
||||
$this->assertEmpty($parent->getData($relationParameters, 'events', 0));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -11,17 +11,6 @@ use PHPUnit\Framework\Attributes\CoversClass;
|
||||
#[CoversClass(NodeEventContainer::class)]
|
||||
class NodeEventContainerTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$GLOBALS['server'] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*/
|
||||
|
||||
@ -11,17 +11,6 @@ use PHPUnit\Framework\Attributes\CoversClass;
|
||||
#[CoversClass(NodeEvent::class)]
|
||||
class NodeEventTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$GLOBALS['server'] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*/
|
||||
|
||||
@ -11,17 +11,6 @@ use PHPUnit\Framework\Attributes\CoversClass;
|
||||
#[CoversClass(NodeFunctionContainer::class)]
|
||||
class NodeFunctionContainerTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$GLOBALS['server'] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*/
|
||||
|
||||
@ -11,17 +11,6 @@ use PHPUnit\Framework\Attributes\CoversClass;
|
||||
#[CoversClass(NodeFunction::class)]
|
||||
class NodeFunctionTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$GLOBALS['server'] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*/
|
||||
|
||||
@ -11,17 +11,6 @@ use PHPUnit\Framework\Attributes\CoversClass;
|
||||
#[CoversClass(NodeIndexContainer::class)]
|
||||
class NodeIndexContainerTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$GLOBALS['server'] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*/
|
||||
|
||||
@ -11,17 +11,6 @@ use PHPUnit\Framework\Attributes\CoversClass;
|
||||
#[CoversClass(NodeIndex::class)]
|
||||
class NodeIndexTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$GLOBALS['server'] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*/
|
||||
|
||||
@ -11,17 +11,6 @@ use PHPUnit\Framework\Attributes\CoversClass;
|
||||
#[CoversClass(NodeProcedureContainer::class)]
|
||||
class NodeProcedureContainerTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$GLOBALS['server'] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*/
|
||||
|
||||
@ -11,17 +11,6 @@ use PHPUnit\Framework\Attributes\CoversClass;
|
||||
#[CoversClass(NodeProcedure::class)]
|
||||
class NodeProcedureTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$GLOBALS['server'] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*/
|
||||
|
||||
@ -11,21 +11,6 @@ use PHPUnit\Framework\Attributes\CoversClass;
|
||||
#[CoversClass(NodeTableContainer::class)]
|
||||
class NodeTableContainerTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['cfg']['NavigationTreeEnableGrouping'] = true;
|
||||
$GLOBALS['cfg']['NavigationTreeDbSeparator'] = '_';
|
||||
$GLOBALS['cfg']['NavigationTreeTableSeparator'] = '__';
|
||||
$GLOBALS['cfg']['NavigationTreeTableLevel'] = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*/
|
||||
|
||||
@ -12,31 +12,14 @@ use PHPUnit\Framework\Attributes\DataProvider;
|
||||
#[CoversClass(NodeTable::class)]
|
||||
class NodeTableTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['cfg']['NavigationTreeDefaultTabTable'] = 'search';
|
||||
$GLOBALS['cfg']['NavigationTreeDefaultTabTable2'] = 'insert';
|
||||
$GLOBALS['cfg']['DefaultTabTable'] = 'browse';
|
||||
$GLOBALS['cfg']['MaxNavigationItems'] = 250;
|
||||
$GLOBALS['cfg']['NavigationTreeEnableGrouping'] = true;
|
||||
$GLOBALS['cfg']['NavigationTreeDbSeparator'] = '_';
|
||||
$GLOBALS['cfg']['NavigationTreeTableSeparator'] = '__';
|
||||
$GLOBALS['cfg']['NavigationTreeTableLevel'] = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*/
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$GLOBALS['cfg']['NavigationTreeDefaultTabTable'] = 'search';
|
||||
$GLOBALS['cfg']['NavigationTreeDefaultTabTable2'] = 'insert';
|
||||
|
||||
$parent = new NodeTable('default');
|
||||
$this->assertEquals(
|
||||
[
|
||||
|
||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Tests\Navigation\Nodes;
|
||||
|
||||
use PhpMyAdmin\ConfigStorage\RelationParameters;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Navigation\Nodes\Node;
|
||||
use PhpMyAdmin\Tests\AbstractTestCase;
|
||||
@ -14,18 +15,6 @@ use ReflectionMethod;
|
||||
#[CoversClass(Node::class)]
|
||||
class NodeTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* SetUp for AddNode
|
||||
*/
|
||||
@ -240,6 +229,7 @@ class NodeTest extends AbstractTestCase
|
||||
*/
|
||||
public function testGetWhereClause(): void
|
||||
{
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$method = new ReflectionMethod(Node::class, 'getWhereClause');
|
||||
|
||||
// Vanilla case
|
||||
@ -315,6 +305,12 @@ class NodeTest extends AbstractTestCase
|
||||
$expectedSql .= "CONCAT(SCHEMA_NAME, '_')) ";
|
||||
$expectedSql .= 'ORDER BY SCHEMA_NAME ASC';
|
||||
|
||||
$relationParameters = RelationParameters::fromArray([
|
||||
'db' => 'pmadb',
|
||||
'navwork' => true,
|
||||
'navigationhiding' => 'navigationhiding',
|
||||
]);
|
||||
|
||||
// It would have been better to mock _getWhereClause method
|
||||
// but strangely, mocking private methods is not supported in PHPUnit
|
||||
$node = new Node('default');
|
||||
@ -328,7 +324,7 @@ class NodeTest extends AbstractTestCase
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$node->getData('', $pos);
|
||||
$node->getData($relationParameters, '', $pos);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -349,6 +345,12 @@ class NodeTest extends AbstractTestCase
|
||||
$expectedSql .= 'ORDER BY `SCHEMA_NAME` ';
|
||||
$expectedSql .= 'LIMIT ' . $pos . ', ' . $limit;
|
||||
|
||||
$relationParameters = RelationParameters::fromArray([
|
||||
'db' => 'pmadb',
|
||||
'navwork' => true,
|
||||
'navigationhiding' => 'navigationhiding',
|
||||
]);
|
||||
|
||||
// It would have been better to mock _getWhereClause method
|
||||
// but strangely, mocking private methods is not supported in PHPUnit
|
||||
$node = new Node('default');
|
||||
@ -363,7 +365,7 @@ class NodeTest extends AbstractTestCase
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$node->getData('', $pos);
|
||||
$node->getData($relationParameters, '', $pos);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -380,6 +382,12 @@ class NodeTest extends AbstractTestCase
|
||||
$GLOBALS['cfg']['FirstLevelNavigationItems'] = $limit;
|
||||
$GLOBALS['cfg']['NavigationTreeDbSeparator'] = '_';
|
||||
|
||||
$relationParameters = RelationParameters::fromArray([
|
||||
'db' => 'pmadb',
|
||||
'navwork' => true,
|
||||
'navigationhiding' => 'navigationhiding',
|
||||
]);
|
||||
|
||||
$node = new Node('default');
|
||||
|
||||
$resultStub = $this->createMock(DummyResult::class);
|
||||
@ -410,7 +418,7 @@ class NodeTest extends AbstractTestCase
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$node->getData('', $pos, 'db');
|
||||
$node->getData($relationParameters, '', $pos, 'db');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -11,17 +11,6 @@ use PHPUnit\Framework\Attributes\CoversClass;
|
||||
#[CoversClass(NodeTriggerContainer::class)]
|
||||
class NodeTriggerContainerTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$GLOBALS['server'] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*/
|
||||
|
||||
@ -11,17 +11,6 @@ use PHPUnit\Framework\Attributes\CoversClass;
|
||||
#[CoversClass(NodeTrigger::class)]
|
||||
class NodeTriggerTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$GLOBALS['server'] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*/
|
||||
|
||||
@ -11,21 +11,6 @@ use PHPUnit\Framework\Attributes\CoversClass;
|
||||
#[CoversClass(NodeViewContainer::class)]
|
||||
class NodeViewContainerTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['cfg']['NavigationTreeEnableGrouping'] = true;
|
||||
$GLOBALS['cfg']['NavigationTreeDbSeparator'] = '_';
|
||||
$GLOBALS['cfg']['NavigationTreeTableSeparator'] = '__';
|
||||
$GLOBALS['cfg']['NavigationTreeTableLevel'] = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*/
|
||||
|
||||
@ -11,17 +11,6 @@ use PHPUnit\Framework\Attributes\CoversClass;
|
||||
#[CoversClass(NodeView::class)]
|
||||
class NodeViewTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* SetUp for test cases
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
$GLOBALS['server'] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for __construct
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user