/** * Test for __construct * * @return void */ public function testConstructor() { $parent = NodeFactory::getInstance('NodeEventContainer'); $this->assertArrayHasKey('text', $parent->links); $this->assertContains('db_events.php', $parent->links['text']); $this->assertEquals('events', $parent->real_name); }
/** * Test for PMA\libraries\navigation\NodeFactory::__construct * * @return void */ public function testConstructor() { $parent = NodeFactory::getInstance('NodeColumnContainer'); $this->assertArrayHasKey('text', $parent->links); $this->assertContains('tbl_structure.php', $parent->links['text']); $this->assertEquals('columns', $parent->real_name); }
/** * Test for __construct * * @return void */ public function testConstructor() { $parent = NodeFactory::getInstance('NodeViewContainer'); $this->assertArrayHasKey('text', $parent->links); $this->assertContains('db_structure.php', $parent->links['text']); $this->assertEquals('views', $parent->real_name); $this->assertContains('viewContainer', $parent->classes); }
/** * Test for __construct * * @return void */ public function testConstructor() { $parent = NodeFactory::getInstance('NodeView'); $this->assertArrayHasKey('text', $parent->links); $this->assertContains('sql.php', $parent->links['text']); $this->assertContains('b_props', $parent->icon); $this->assertContains('view', $parent->classes); }
/** * Tests getHtmlForControlButtons() method * * @return void * @test */ public function testGetHtmlForControlButtons() { $parent = NodeFactory::getInstance('NodeDatabase', 'parent'); $parent->addChild($this->object); $this->object->expects($this->once())->method('getItemType')->will($this->returnValue('itemType')); $html = $this->object->getHtmlForControlButtons(); $this->assertStringStartsWith('<span class="navItemControls">', $html); $this->assertStringEndsWith('</span>', $html); $this->assertContains('<a href="navigation.php' . PMA_URL_getCommon() . '&hideNavItem=true&itemType=itemType&itemName=child' . '&dbName=parent" class="hideNavItem ajax">', $html); }
/** * Initialises the class * * @param string $name An identifier for the new node */ public function __construct($name) { parent::__construct($name, Node::CONTAINER); if ($GLOBALS['is_create_db_priv'] && $GLOBALS['cfg']['ShowCreateDb'] !== false) { $new = NodeFactory::getInstance('Node', _pgettext('Create new database', 'New')); $new->isNew = true; $new->icon = PMA\libraries\Util::getImage('b_newdb.png', ''); $new->links = array('text' => 'server_databases.php?server=' . $GLOBALS['server'], 'icon' => 'server_databases.php?server=' . $GLOBALS['server']); $new->classes = 'new_database italics'; $this->addChild($new); } }
/** * Initialises the class */ public function __construct() { parent::__construct(__('Triggers'), Node::CONTAINER); $this->icon = PMA\libraries\Util::getImage('b_triggers.png'); $this->links = array('text' => 'db_triggers.php?server=' . $GLOBALS['server'] . '&db=%2$s&table=%1$s&token=' . $_SESSION[' PMA_token '], 'icon' => 'db_triggers.php?server=' . $GLOBALS['server'] . '&db=%2$s&table=%1$s&token=' . $_SESSION[' PMA_token ']); $this->real_name = 'triggers'; $new = NodeFactory::getInstance('Node', _pgettext('Create new trigger', 'New')); $new->isNew = true; $new->icon = PMA\libraries\Util::getImage('b_trigger_add.png', ''); $new->links = array('text' => 'db_triggers.php?server=' . $GLOBALS['server'] . '&db=%3$s&token=' . $_SESSION[' PMA_token '] . '&add_item=1', 'icon' => 'db_triggers.php?server=' . $GLOBALS['server'] . '&db=%3$s&token=' . $_SESSION[' PMA_token '] . '&add_item=1'); $new->classes = 'new_trigger italics'; $this->addChild($new); }
/** * Initialises the class */ public function __construct() { parent::__construct(__('Events'), Node::CONTAINER); $this->icon = PMA\libraries\Util::getImage('b_events.png', ''); $this->links = array('text' => 'db_events.php?server=' . $GLOBALS['server'] . '&db=%1$s', 'icon' => 'db_events.php?server=' . $GLOBALS['server'] . '&db=%1$s'); $this->real_name = 'events'; $new = NodeFactory::getInstance('Node', _pgettext('Create new event', 'New')); $new->isNew = true; $new->icon = PMA\libraries\Util::getImage('b_event_add.png', ''); $new->links = array('text' => 'db_events.php?server=' . $GLOBALS['server'] . '&db=%2$s&add_item=1', 'icon' => 'db_events.php?server=' . $GLOBALS['server'] . '&db=%2$s&add_item=1'); $new->classes = 'new_event italics'; $this->addChild($new); }
/** * Initialises the class */ public function __construct() { parent::__construct(__('Functions'), Node::CONTAINER); $this->icon = PMA\libraries\Util::getImage('b_routines.png', __('Functions')); $this->links = array('text' => 'db_routines.php?server=' . $GLOBALS['server'] . '&db=%1$s&token=' . $_SESSION[' PMA_token '] . '&type=FUNCTION', 'icon' => 'db_routines.php?server=' . $GLOBALS['server'] . '&db=%1$s&token=' . $_SESSION[' PMA_token '] . '&type=FUNCTION'); $this->real_name = 'functions'; $new_label = _pgettext('Create new function', 'New'); $new = NodeFactory::getInstance('Node', $new_label); $new->isNew = true; $new->icon = PMA\libraries\Util::getImage('b_routine_add.png', $new_label); $new->links = array('text' => 'db_routines.php?server=' . $GLOBALS['server'] . '&db=%2$s&token=' . $_SESSION[' PMA_token '] . '&add_item=1&item_type=FUNCTION', 'icon' => 'db_routines.php?server=' . $GLOBALS['server'] . '&db=%2$s&token=' . $_SESSION[' PMA_token '] . '&add_item=1&item_type=FUNCTION'); $new->classes = 'new_function italics'; $this->addChild($new); }
/** * Initialises the class */ public function __construct() { parent::__construct(__('Indexes'), Node::CONTAINER); $this->icon = PMA\libraries\Util::getImage('b_index.png', __('Indexes')); $this->links = array('text' => 'tbl_structure.php?server=' . $GLOBALS['server'] . '&db=%2$s&table=%1$s' . '&token=' . $_SESSION[' PMA_token '], 'icon' => 'tbl_structure.php?server=' . $GLOBALS['server'] . '&db=%2$s&table=%1$s' . '&token=' . $_SESSION[' PMA_token ']); $this->real_name = 'indexes'; $new_label = _pgettext('Create new index', 'New'); $new = NodeFactory::getInstance('Node', $new_label); $new->isNew = true; $new->icon = PMA\libraries\Util::getImage('b_index_add.png', $new_label); $new->links = array('text' => 'tbl_indexes.php?server=' . $GLOBALS['server'] . '&create_index=1&added_fields=2' . '&db=%3$s&table=%2$s&token=' . $_SESSION[' PMA_token '], 'icon' => 'tbl_indexes.php?server=' . $GLOBALS['server'] . '&create_index=1&added_fields=2' . '&db=%3$s&table=%2$s&token=' . $_SESSION[' PMA_token ']); $new->classes = 'new_index italics'; $this->addChild($new); }
/** * Initialises the class */ public function __construct() { parent::__construct(__('Columns'), Node::CONTAINER); $this->icon = Util::getImage('pause.png', __('Columns')); $this->links = array('text' => 'tbl_structure.php?server=' . $GLOBALS['server'] . '&db=%2$s&table=%1$s' . '&token=' . $_SESSION[' PMA_token '], 'icon' => 'tbl_structure.php?server=' . $GLOBALS['server'] . '&db=%2$s&table=%1$s' . '&token=' . $_SESSION[' PMA_token ']); $this->real_name = 'columns'; $new_label = _pgettext('Create new column', 'New'); $new = NodeFactory::getInstance('Node', $new_label); $new->isNew = true; $new->icon = Util::getImage('b_column_add.png', $new_label); $new->links = array('text' => 'tbl_addfield.php?server=' . $GLOBALS['server'] . '&db=%3$s&table=%2$s' . '&field_where=last&after_field=' . '&token=' . $_SESSION[' PMA_token '], 'icon' => 'tbl_addfield.php?server=' . $GLOBALS['server'] . '&db=%3$s&table=%2$s' . '&field_where=last&after_field=' . '&token=' . $_SESSION[' PMA_token ']); $new->classes = 'new_column italics'; $this->addChild($new); }
/** * Initialises the class */ public function __construct() { parent::__construct(__('Procedures'), Node::CONTAINER); $this->icon = PMA\libraries\Util::getImage('b_routines.png', __('Procedures')); $this->links = array('text' => 'db_routines.php?server=' . $GLOBALS['server'] . '&db=%1$s&type=PROCEDURE', 'icon' => 'db_routines.php?server=' . $GLOBALS['server'] . '&db=%1$s&type=PROCEDURE'); $this->real_name = 'procedures'; $new_label = _pgettext('Create new procedure', 'New'); $new = NodeFactory::getInstance('Node', $new_label); $new->isNew = true; $new->icon = PMA\libraries\Util::getImage('b_routine_add.png', $new_label); $new->links = array('text' => 'db_routines.php?server=' . $GLOBALS['server'] . '&db=%2$s&add_item=1', 'icon' => 'db_routines.php?server=' . $GLOBALS['server'] . '&db=%2$s&add_item=1'); $new->classes = 'new_procedure italics'; $this->addChild($new); }
/** * Initialises the class */ public function __construct() { parent::__construct(__('Tables'), Node::CONTAINER); $this->icon = PMA\libraries\Util::getImage('b_browse.png', __('Tables')); $this->links = array('text' => 'db_structure.php?server=' . $GLOBALS['server'] . '&db=%1$s&tbl_type=table' . '&token=' . $_SESSION[' PMA_token '], 'icon' => 'db_structure.php?server=' . $GLOBALS['server'] . '&db=%1$s&tbl_type=table' . '&token=' . $_SESSION[' PMA_token ']); $this->real_name = 'tables'; $this->classes = 'tableContainer subContainer'; $new_label = _pgettext('Create new table', 'New'); $new = NodeFactory::getInstance('Node', $new_label); $new->isNew = true; $new->icon = PMA\libraries\Util::getImage('b_table_add.png', $new_label); $new->links = array('text' => 'tbl_create.php?server=' . $GLOBALS['server'] . '&db=%2$s&token=' . $_SESSION[' PMA_token '], 'icon' => 'tbl_create.php?server=' . $GLOBALS['server'] . '&db=%2$s&token=' . $_SESSION[' PMA_token ']); $new->classes = 'new_table italics'; $this->addChild($new); }
/** * Initialises the class */ public function __construct() { parent::__construct(__('Views'), Node::CONTAINER); $this->icon = PMA\libraries\Util::getImage('b_views.png', __('Views')); $this->links = array('text' => 'db_structure.php?server=' . $GLOBALS['server'] . '&db=%1$s&tbl_type=view', 'icon' => 'db_structure.php?server=' . $GLOBALS['server'] . '&db=%1$s&tbl_type=view'); $this->classes = 'viewContainer subContainer'; $this->real_name = 'views'; $new_label = _pgettext('Create new view', 'New'); $new = NodeFactory::getInstance('Node', $new_label); $new->isNew = true; $new->icon = PMA\libraries\Util::getImage('b_view_add.png', $new_label); $new->links = array('text' => 'view_create.php?server=' . $GLOBALS['server'] . '&db=%2$s', 'icon' => 'view_create.php?server=' . $GLOBALS['server'] . '&db=%2$s'); $new->classes = 'new_view italics'; $this->addChild($new); }
/** * Test for __construct * * @return void */ public function testConstructor() { $parent = NodeFactory::getInstance('NodeIndex'); $this->assertArrayHasKey('text', $parent->links); $this->assertContains('tbl_indexes.php', $parent->links['text']); }
/** * Test for PMA\libraries\navigation\NodeFactory::getInstance * * @return void */ public function testClassNameError() { $this->setExpectedException('PHPUnit_Framework_Error'); NodeFactory::getInstance('Invalid'); }
/** * Test for __construct * * @return void */ public function testConstructor() { $parent = NodeFactory::getInstance('NodeTrigger'); $this->assertArrayHasKey('text', $parent->links); $this->assertContains('db_triggers.php', $parent->links['text']); }
/** * Tests the getPresence method when DisableIS is true * * @return void * @test */ public function testGetPresenceWithDisabledIS() { $GLOBALS['cfg']['Server']['DisableIS'] = true; $GLOBALS['dbs_to_test'] = false; $GLOBALS['cfg']['NavigationTreeEnableGrouping'] = true; $node = NodeFactory::getInstance(); // test with no search clause $dbi = $this->getMockBuilder('PMA\\libraries\\DatabaseInterface')->disableOriginalConstructor()->getMock(); $dbi->expects($this->once())->method('tryQuery')->with("SHOW DATABASES WHERE TRUE "); $GLOBALS['dbi'] = $dbi; $node->getPresence(); // test with a search clause $dbi = $this->getMockBuilder('PMA\\libraries\\DatabaseInterface')->disableOriginalConstructor()->getMock(); $dbi->expects($this->once())->method('tryQuery')->with("SHOW DATABASES WHERE TRUE AND `Database` LIKE '%dbname%' "); $GLOBALS['dbi'] = $dbi; $node->getPresence('', 'dbname'); }
/** * Recursively groups tree nodes given a separator * * @param Node $node The node to group * * @return void */ public function groupNode($node) { if ($node->type != Node::CONTAINER || !$GLOBALS['cfg']['NavigationTreeEnableExpansion']) { return; } $separators = array(); if (is_array($node->separator)) { $separators = $node->separator; } else { if (strlen($node->separator)) { $separators[] = $node->separator; } } $prefixes = array(); if ($node->separator_depth > 0) { foreach ($node->children as $child) { $prefix_pos = false; foreach ($separators as $separator) { $sep_pos = mb_strpos($child->name, $separator); if ($sep_pos != false && $sep_pos != mb_strlen($child->name) && $sep_pos != 0 && ($prefix_pos == false || $sep_pos < $prefix_pos)) { $prefix_pos = $sep_pos; } } if ($prefix_pos !== false) { $prefix = mb_substr($child->name, 0, $prefix_pos); if (!isset($prefixes[$prefix])) { $prefixes[$prefix] = 1; } else { $prefixes[$prefix]++; } } //Bug #4375: Check if prefix is the name of a DB, to create a group. foreach ($node->children as $otherChild) { if (array_key_exists($otherChild->name, $prefixes)) { $prefixes[$otherChild->name]++; } } } //Check if prefix is the name of a DB, to create a group. foreach ($node->children as $child) { if (array_key_exists($child->name, $prefixes)) { $prefixes[$child->name]++; } } } // It is not a group if it has only one item foreach ($prefixes as $key => $value) { if ($value == 1) { unset($prefixes[$key]); } } // rfe #1634 Don't group if there's only one group and no other items if (count($prefixes) == 1) { $keys = array_keys($prefixes); $key = $keys[0]; if ($prefixes[$key] == count($node->children) - 1) { unset($prefixes[$key]); } } if (count($prefixes)) { /** @var Node[] $groups */ $groups = array(); foreach ($prefixes as $key => $value) { // warn about large groups if ($value > 500 && !$this->_largeGroupWarning) { trigger_error(__('There are large item groups in navigation panel which ' . 'may affect the performance. Consider disabling item ' . 'grouping in the navigation panel.'), E_USER_WARNING); $this->_largeGroupWarning = true; } $groups[$key] = new Node($key, Node::CONTAINER, true); $groups[$key]->separator = $node->separator; $groups[$key]->separator_depth = $node->separator_depth - 1; $groups[$key]->icon = Util::getImage('b_group.png'); $groups[$key]->pos2 = $node->pos2; $groups[$key]->pos3 = $node->pos3; if ($node instanceof NodeTableContainer || $node instanceof NodeViewContainer) { $tblGroup = '&tbl_group=' . urlencode($key); $groups[$key]->links = array('text' => $node->links['text'] . $tblGroup, 'icon' => $node->links['icon'] . $tblGroup); } $node->addChild($groups[$key]); foreach ($separators as $separator) { $separatorLength = strlen($separator); // FIXME: this could be more efficient foreach ($node->children as $child) { $keySeparatorLength = mb_strlen($key) + $separatorLength; $name_substring = mb_substr($child->name, 0, $keySeparatorLength); if ($name_substring != $key . $separator && $child->name != $key || $child->type != Node::OBJECT) { continue; } $class = get_class($child); $className = substr($class, strrpos($class, '\\') + 1); unset($class); $new_child = NodeFactory::getInstance($className, mb_substr($child->name, $keySeparatorLength)); if ($new_child instanceof NodeDatabase && $child->getHiddenCount() > 0) { $new_child->setHiddenCount($child->getHiddenCount()); } $new_child->real_name = $child->real_name; $new_child->icon = $child->icon; $new_child->links = $child->links; $new_child->pos2 = $child->pos2; $new_child->pos3 = $child->pos3; $groups[$key]->addChild($new_child); foreach ($child->children as $elm) { $new_child->addChild($elm); } $node->removeChild($child->name); } } } foreach ($prefixes as $key => $value) { $this->groupNode($groups[$key]); $groups[$key]->classes = "navGroup"; } } }
/** * Test for __construct * * @return void */ public function testConstructor() { $parent = NodeFactory::getInstance('NodeProcedure'); $this->assertArrayHasKey('text', $parent->links); $this->assertContains('db_routines.php', $parent->links['text']); }
/** * Test for setHiddenCount and getHiddenCount * * @return void */ public function testHiddenCount() { $parent = NodeFactory::getInstance('NodeDatabase'); $parent->setHiddenCount(3); $this->assertEquals(3, $parent->getHiddenCount()); }
/** * Tests whether the node icon is properly set based on the icon target. * * @param string $target target of the icon * @param string $imageName name of the image that should be set * * @return void * @dataProvider providerForTestIcon */ public function testIcon($target, $imageName) { $GLOBALS['cfg']['NavigationTreeDefaultTabTable'] = $target; $node = NodeFactory::getInstance('NodeTable'); $this->assertContains($imageName, $node->icon[0]); }