コード例 #1
0
 /**
  * Test for __construct
  *
  * @return void
  */
 public function testConstructor()
 {
     $parent = PMA_NodeFactory::getInstance('Node_Procedure_Container');
     $this->assertArrayHasKey('text', $parent->links);
     $this->assertContains('db_routines.php', $parent->links['text']);
     $this->assertEquals('procedures', $parent->real_name);
 }
コード例 #2
0
 /**
  * Test for __construct
  *
  * @return void
  */
 public function testConstructor()
 {
     $parent = PMA_NodeFactory::getInstance('Node_Database');
     $this->assertArrayHasKey('text', $parent->links);
     $this->assertContains('db_structure.php', $parent->links['text']);
     $this->assertContains('database', $parent->classes);
 }
コード例 #3
0
 /**
  * Test for __construct
  *
  * @return void
  */
 public function testConstructor()
 {
     $parent = PMA_NodeFactory::getInstance('Node_Index_Container');
     $this->assertArrayHasKey('text', $parent->links);
     $this->assertContains('tbl_structure.php', $parent->links['text']);
     $this->assertEquals('indexes', $parent->real_name);
 }
コード例 #4
0
 /**
  * Test for __construct
  *
  * @return void
  */
 public function testConstructor()
 {
     $parent = PMA_NodeFactory::getInstance('Node_Trigger_Container');
     $this->assertArrayHasKey('text', $parent->links);
     $this->assertContains('db_triggers.php', $parent->links['text']);
     $this->assertEquals('triggers', $parent->real_name);
 }
コード例 #5
0
 /**
  * Test for __construct
  *
  * @return void
  */
 public function testConstructor()
 {
     $parent = PMA_NodeFactory::getInstance('Node_View');
     $this->assertArrayHasKey('text', $parent->links);
     $this->assertContains('sql.php', $parent->links['text']);
     $this->assertContains('b_props', $parent->icon);
     $this->assertContains('view', $parent->classes);
 }
コード例 #6
0
 /**
  * Test for __construct
  *
  * @return void
  */
 public function testConstructor()
 {
     $parent = PMA_NodeFactory::getInstance('Node_View_Container');
     $this->assertArrayHasKey('text', $parent->links);
     $this->assertContains('db_structure.php', $parent->links['text']);
     $this->assertEquals('views', $parent->real_name);
     $this->assertContains('viewContainer', $parent->classes);
 }
コード例 #7
0
 /**
  * Tests getHtmlForControlButtons() method
  *
  * @return void
  * @test
  */
 public function testGetHtmlForControlButtons()
 {
     $parent = PMA_NodeFactory::getInstance('Node_Database', '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);
 }
コード例 #8
0
 /**
  * Initialises the class
  *
  * @param string $name An identifier for the new node
  *
  * @return Node_Database_Container
  */
 public function __construct($name)
 {
     parent::__construct($name, Node::CONTAINER);
     $new = PMA_NodeFactory::getInstance('Node', _pgettext('Create new database', 'New'));
     $new->isNew = $GLOBALS['is_create_db_priv'];
     $new->icon = PMA_Util::getImage('b_newdb.png', '');
     $new->links = array('text' => 'server_databases.php?server=' . $GLOBALS['server'] . '&amp;token=' . $GLOBALS['token'], 'icon' => 'server_databases.php?server=' . $GLOBALS['server'] . '&amp;token=' . $GLOBALS['token']);
     $new->classes = 'new_database italics';
     $this->addChild($new);
 }
コード例 #9
0
 /**
  * Initialises the class
  *
  * @return Node_Index_Container
  */
 public function __construct()
 {
     parent::__construct(__('Indexes'), Node::CONTAINER);
     $this->icon = PMA_Util::getImage('b_index.png', '');
     $this->links = array('text' => 'tbl_structure.php?server=' . $GLOBALS['server'] . '&amp;db=%2$s&amp;table=%1$s' . '&amp;token=' . $GLOBALS['token'], 'icon' => 'tbl_structure.php?server=' . $GLOBALS['server'] . '&amp;db=%2$s&amp;table=%1$s' . '&amp;token=' . $GLOBALS['token']);
     $this->real_name = 'indexes';
     $new = PMA_NodeFactory::getInstance('Node', _pgettext('Create new index', 'New'));
     $new->isNew = true;
     $new->icon = PMA_Util::getImage('b_index_add.png', '');
     $new->links = array('text' => 'tbl_indexes.php?server=' . $GLOBALS['server'] . '&amp;create_index=1&amp;added_fields=2' . '&amp;db=%3$s&amp;table=%2$s&amp;token=' . $GLOBALS['token'], 'icon' => 'tbl_indexes.php?server=' . $GLOBALS['server'] . '&amp;create_index=1&amp;added_fields=2' . '&amp;db=%3$s&amp;table=%2$s&amp;token=' . $GLOBALS['token']);
     $new->classes = 'new_index italics';
     $this->addChild($new);
 }
コード例 #10
0
 /**
  * Initialises the class
  *
  * @return Node_Event_Container
  */
 public function __construct()
 {
     parent::__construct(__('Events'), Node::CONTAINER);
     $this->icon = PMA_Util::getImage('b_events.png', '');
     $this->links = array('text' => 'db_events.php?server=' . $GLOBALS['server'] . '&amp;db=%1$s&amp;token=' . $_SESSION[' PMA_token '], 'icon' => 'db_events.php?server=' . $GLOBALS['server'] . '&amp;db=%1$s&amp;token=' . $_SESSION[' PMA_token ']);
     $this->real_name = 'events';
     $new = PMA_NodeFactory::getInstance('Node', _pgettext('Create new event', 'New'));
     $new->isNew = true;
     $new->icon = PMA_Util::getImage('b_event_add.png', '');
     $new->links = array('text' => 'db_events.php?server=' . $GLOBALS['server'] . '&amp;db=%2$s&amp;token=' . $_SESSION[' PMA_token '] . '&add_item=1', 'icon' => 'db_events.php?server=' . $GLOBALS['server'] . '&amp;db=%2$s&amp;token=' . $_SESSION[' PMA_token '] . '&add_item=1');
     $new->classes = 'new_event italics';
     $this->addChild($new);
 }
コード例 #11
0
 /**
  * Initialises the class
  *
  * @return Node_Column_Container
  */
 public function __construct()
 {
     parent::__construct(__('Columns'), Node::CONTAINER);
     $this->icon = PMA_Util::getImage('pause.png', '');
     $this->links = array('text' => 'tbl_structure.php?server=' . $GLOBALS['server'] . '&amp;db=%2$s&amp;table=%1$s' . '&amp;token=' . $GLOBALS['token'], 'icon' => 'tbl_structure.php?server=' . $GLOBALS['server'] . '&amp;db=%2$s&amp;table=%1$s' . '&amp;token=' . $GLOBALS['token']);
     $this->real_name = 'columns';
     $new = PMA_NodeFactory::getInstance('Node', _pgettext('Create new column', 'New'));
     $new->isNew = true;
     $new->icon = PMA_Util::getImage('b_column_add.png', '');
     $new->links = array('text' => 'tbl_addfield.php?server=' . $GLOBALS['server'] . '&amp;db=%3$s&amp;table=%2$s' . '&amp;field_where=last&after_field=' . '&amp;token=' . $GLOBALS['token'], 'icon' => 'tbl_addfield.php?server=' . $GLOBALS['server'] . '&amp;db=%3$s&amp;table=%2$s' . '&amp;field_where=last&after_field=' . '&amp;token=' . $GLOBALS['token']);
     $new->classes = 'new_column italics';
     $this->addChild($new);
 }
コード例 #12
0
 /**
  * Initialises the class
  *
  * @return Node_View_Container
  */
 public function __construct()
 {
     parent::__construct(__('Views'), Node::CONTAINER);
     $this->icon = PMA_Util::getImage('b_views.png', '');
     $this->links = array('text' => 'db_structure.php?server=' . $GLOBALS['server'] . '&amp;db=%1$s&amp;token=' . $GLOBALS['token'], 'icon' => 'db_structure.php?server=' . $GLOBALS['server'] . '&amp;db=%1$s&amp;token=' . $GLOBALS['token']);
     $this->real_name = 'views';
     $new = PMA_NodeFactory::getInstance('Node', _pgettext('Create new view', 'New'));
     $new->isNew = true;
     $new->icon = PMA_Util::getImage('b_view_add.png', '');
     $new->links = array('text' => 'view_create.php?server=' . $GLOBALS['server'] . '&amp;db=%2$s&amp;token=' . $GLOBALS['token'], 'icon' => 'view_create.php?server=' . $GLOBALS['server'] . '&amp;db=%2$s&amp;token=' . $GLOBALS['token']);
     $new->classes = 'new_view italics';
     $this->addChild($new);
 }
コード例 #13
0
 /**
  * Initialises the class
  *
  * @return Node_Column_Container
  */
 public function __construct()
 {
     parent::__construct(__('Functions'), Node::CONTAINER);
     $this->icon = PMA_Util::getImage('b_routines.png');
     $this->links = array('text' => 'db_routines.php?server=' . $GLOBALS['server'] . '&amp;db=%1$s&amp;token=' . $GLOBALS['token'], 'icon' => 'db_routines.php?server=' . $GLOBALS['server'] . '&amp;db=%1$s&amp;token=' . $GLOBALS['token']);
     $this->real_name = 'functions';
     $new = PMA_NodeFactory::getInstance('Node', _pgettext('Create new function', 'New'));
     $new->isNew = true;
     $new->icon = PMA_Util::getImage('b_routine_add.png', '');
     $new->links = array('text' => 'db_routines.php?server=' . $GLOBALS['server'] . '&amp;db=%2$s&amp;token=' . $GLOBALS['token'] . '&add_item=1&amp;item_type=FUNCTION', 'icon' => 'db_routines.php?server=' . $GLOBALS['server'] . '&amp;db=%2$s&amp;token=' . $GLOBALS['token'] . '&add_item=1&amp;item_type=FUNCTION');
     $new->classes = 'new_function italics';
     $this->addChild($new);
 }
コード例 #14
0
 /**
  * Initialises the class
  *
  * @return Node_Procedure_Container
  */
 public function __construct()
 {
     parent::__construct(__('Procedures'), Node::CONTAINER);
     $this->icon = PMA_Util::getImage('b_routines.png', __('Procedures'));
     $this->links = array('text' => 'db_routines.php?server=' . $GLOBALS['server'] . '&amp;db=%1$s&amp;token=' . $_SESSION[' PMA_token '] . '&amp;type=PROCEDURE', 'icon' => 'db_routines.php?server=' . $GLOBALS['server'] . '&amp;db=%1$s&amp;token=' . $_SESSION[' PMA_token '] . '&amp;type=PROCEDURE');
     $this->real_name = 'procedures';
     $new_label = _pgettext('Create new procedure', 'New');
     $new = PMA_NodeFactory::getInstance('Node', $new_label);
     $new->isNew = true;
     $new->icon = PMA_Util::getImage('b_routine_add.png', $new_label);
     $new->links = array('text' => 'db_routines.php?server=' . $GLOBALS['server'] . '&amp;db=%2$s&amp;token=' . $_SESSION[' PMA_token '] . '&add_item=1', 'icon' => 'db_routines.php?server=' . $GLOBALS['server'] . '&amp;db=%2$s&amp;token=' . $_SESSION[' PMA_token '] . '&add_item=1');
     $new->classes = 'new_procedure italics';
     $this->addChild($new);
 }
コード例 #15
0
 /**
  * Initialises the class
  */
 public function __construct()
 {
     parent::__construct(__('Tables'), Node::CONTAINER);
     $this->icon = PMA_Util::getImage('b_browse.png', __('Tables'));
     $this->links = array('text' => 'db_structure.php?server=' . $GLOBALS['server'] . '&amp;db=%1$s&amp;tbl_type=table' . '&amp;token=' . $_SESSION[' PMA_token '], 'icon' => 'db_structure.php?server=' . $GLOBALS['server'] . '&amp;db=%1$s&amp;tbl_type=table' . '&amp;token=' . $_SESSION[' PMA_token ']);
     $this->real_name = 'tables';
     $this->classes = 'tableContainer subContainer';
     $new_label = _pgettext('Create new table', 'New');
     $new = PMA_NodeFactory::getInstance('Node', $new_label);
     $new->isNew = true;
     $new->icon = PMA_Util::getImage('b_table_add.png', $new_label);
     $new->links = array('text' => 'tbl_create.php?server=' . $GLOBALS['server'] . '&amp;db=%2$s&amp;token=' . $_SESSION[' PMA_token '], 'icon' => 'tbl_create.php?server=' . $GLOBALS['server'] . '&amp;db=%2$s&amp;token=' . $_SESSION[' PMA_token ']);
     $new->classes = 'new_table italics';
     $this->addChild($new);
 }
コード例 #16
0
 /**
  * Initialises the class
  *
  * @return Node_Table_Container
  */
 public function __construct()
 {
     parent::__construct(__('Tables'), Node::CONTAINER);
     $this->icon = PMA_Util::getImage('b_browse.png', '');
     $this->links = array('text' => 'db_structure.php?server=' . $GLOBALS['server'] . '&amp;db=%1$s&amp;token=' . $GLOBALS['token'], 'icon' => 'db_structure.php?server=' . $GLOBALS['server'] . '&amp;db=%1$s&amp;token=' . $GLOBALS['token']);
     if ($GLOBALS['cfg']['NavigationTreeEnableGrouping']) {
         $this->separator = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
         $this->separator_depth = (int) $GLOBALS['cfg']['NavigationTreeTableLevel'];
     }
     $this->real_name = 'tables';
     $new = PMA_NodeFactory::getInstance('Node', _pgettext('Create new table', 'New'));
     $new->isNew = true;
     $new->icon = PMA_Util::getImage('b_table_add.png', '');
     $new->links = array('text' => 'tbl_create.php?server=' . $GLOBALS['server'] . '&amp;db=%2$s&amp;token=' . $GLOBALS['token'], 'icon' => 'tbl_create.php?server=' . $GLOBALS['server'] . '&amp;db=%2$s&amp;token=' . $GLOBALS['token']);
     $new->classes = 'new_table italics';
     $this->addChild($new);
 }
コード例 #17
0
 /**
  * Initialises the class
  *
  * @return Node_View_Container
  */
 public function __construct()
 {
     parent::__construct(__('Views'), Node::CONTAINER);
     $this->icon = PMA_Util::getImage('b_views.png', __('Views'));
     $this->links = array('text' => 'db_structure.php?server=' . $GLOBALS['server'] . '&amp;db=%1$s&amp;tbl_type=view' . '&amp;token=' . $_SESSION[' PMA_token '], 'icon' => 'db_structure.php?server=' . $GLOBALS['server'] . '&amp;db=%1$s&amp;tbl_type=view' . '&amp;token=' . $_SESSION[' PMA_token ']);
     if ($GLOBALS['cfg']['NavigationTreeEnableGrouping']) {
         $this->separator = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
         $this->separator_depth = (int) $GLOBALS['cfg']['NavigationTreeTableLevel'];
     }
     $this->classes = 'viewContainer subContainer';
     $this->real_name = 'views';
     $new_label = _pgettext('Create new view', 'New');
     $new = PMA_NodeFactory::getInstance('Node', $new_label);
     $new->isNew = true;
     $new->icon = PMA_Util::getImage('b_view_add.png', $new_label);
     $new->links = array('text' => 'view_create.php?server=' . $GLOBALS['server'] . '&amp;db=%2$s&amp;token=' . $_SESSION[' PMA_token '], 'icon' => 'view_create.php?server=' . $GLOBALS['server'] . '&amp;db=%2$s&amp;token=' . $_SESSION[' PMA_token ']);
     $new->classes = 'new_view italics';
     $this->addChild($new);
 }
コード例 #18
0
 /**
  * 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 = PMA_NodeFactory::getInstance();
     // test with no search clause
     $dbi = $this->getMockBuilder('PMA_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_DatabaseInterface')->disableOriginalConstructor()->getMock();
     $dbi->expects($this->once())->method('tryQuery')->with("SHOW DATABASES WHERE TRUE AND `Database` LIKE '%dbname%' ");
     $GLOBALS['dbi'] = $dbi;
     $node->getPresence('', 'dbname');
 }
コード例 #19
0
 /**
  * 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 $child) {
                 if (array_key_exists($child->name, $prefixes)) {
                     $prefixes[$child->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]++;
             }
         }
     }
     foreach ($prefixes as $key => $value) {
         if ($value == 1) {
             unset($prefixes[$key]);
         } else {
             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;
             }
         }
     }
     if (count($prefixes)) {
         $groups = array();
         foreach ($prefixes as $key => $value) {
             $groups[$key] = new Node($key, Node::CONTAINER, true);
             $groups[$key]->separator = $node->separator;
             $groups[$key]->separator_depth = $node->separator_depth - 1;
             $groups[$key]->icon = PMA_Util::getImage('b_group.png');
             $groups[$key]->pos2 = $node->pos2;
             $groups[$key]->pos3 = $node->pos3;
             if ($node instanceof Node_Table_Container || $node instanceof Node_View_Container) {
                 $tblGroup = '&amp;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);
                     $new_child = PMA_NodeFactory::getInstance($class, mb_substr($child->name, $keySeparatorLength));
                     if ($new_child instanceof Node_Database && $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";
         }
     }
 }
コード例 #20
0
 /**
  * Tests the getPresence method
  *
  * @return void
  * @test
  */
 public function testGetPresence()
 {
     if (!isset($GLOBALS['cfg'])) {
         $GLOBALS['cfg'] = array();
     }
     if (!isset($GLOBALS['cfg']['Servers'])) {
         $GLOBALS['cfg']['Servers'] = array();
     }
     if (!isset($GLOBALS['cfg']['Servers'][0])) {
         $GLOBALS['cfg']['Servers'][0] = array();
     }
     $GLOBALS['cfg']['NavigationTreeDbSeparator'] = '_';
     $query = "select COUNT(*) ";
     $query .= "from ( ";
     $query .= "SELECT distinct SUBSTRING_INDEX(SCHEMA_NAME, '_', 1) ";
     $query .= "DB_first_level ";
     $query .= "FROM INFORMATION_SCHEMA.SCHEMATA ";
     $query .= "WHERE TRUE ";
     $query .= ") t ";
     // It would have been better to mock _getWhereClause method
     // but strangely, mocking private methods is not supported in PHPUnit
     $node = PMA_NodeFactory::getInstance();
     $dbi = $this->getMockBuilder('PMA_DatabaseInterface')->disableOriginalConstructor()->getMock();
     $dbi->expects($this->once())->method('fetchValue')->with($query);
     $GLOBALS['dbi'] = $dbi;
     $node->getPresence();
 }
コード例 #21
0
 /**
  * Recursively groups tree nodes given a sperarator
  *
  * @param Node $node The node to group
  *
  * @return void
  */
 public function groupNode($node)
 {
     if ($node->type == Node::CONTAINER) {
         $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 = strpos($child->name, $separator);
                     if ($sep_pos != false && $sep_pos != strlen($child->name) && $sep_pos != 0 && ($prefix_pos == false || $sep_pos < $prefix_pos)) {
                         $prefix_pos = $sep_pos;
                     }
                 }
                 if ($prefix_pos !== false) {
                     $prefix = substr($child->name, 0, $prefix_pos);
                     if (!isset($prefixes[$prefix])) {
                         $prefixes[$prefix] = 1;
                     } else {
                         $prefixes[$prefix]++;
                     }
                 }
             }
         }
         foreach ($prefixes as $key => $value) {
             if ($value == 1) {
                 unset($prefixes[$key]);
             }
         }
         if (count($prefixes)) {
             $groups = array();
             foreach ($prefixes as $key => $value) {
                 $groups[$key] = new Node($key, Node::CONTAINER, true);
                 $groups[$key]->separator = $node->separator;
                 $groups[$key]->separator_depth = $node->separator_depth - 1;
                 $groups[$key]->icon = '';
                 if (in_array($GLOBALS['cfg']['TableNavigationLinksMode'], array('icons', 'both'))) {
                     $groups[$key]->icon = PMA_Util::getImage('b_group.png');
                 }
                 $groups[$key]->pos2 = $node->pos2;
                 $groups[$key]->pos3 = $node->pos3;
                 $node->addChild($groups[$key]);
                 foreach ($separators as $separator) {
                     // FIXME: this could be more efficient
                     foreach ($node->children as $child) {
                         $name_substring = substr($child->name, 0, strlen($key) + strlen($separator));
                         if ($name_substring == $key . $separator && $child->type == Node::OBJECT) {
                             $class = get_class($child);
                             $new_child = PMA_NodeFactory::getInstance($class, substr($child->name, strlen($key) + strlen($separator)));
                             $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";
             }
         }
     }
 }
コード例 #22
0
ファイル: PMA_Node_test.php プロジェクト: roccivic/phpmyadmin
 /**
  * Tests the getPresence method
  *
  * @return void
  * @test
  */
 public function testGetPresence()
 {
     if (!isset($GLOBALS['cfg'])) {
         $GLOBALS['cfg'] = array();
     }
     if (!isset($GLOBALS['cfg']['Servers'])) {
         $GLOBALS['cfg']['Servers'] = array();
     }
     if (!isset($GLOBALS['cfg']['Servers'][0])) {
         $GLOBALS['cfg']['Servers'][0] = array();
     }
     $query = "SELECT COUNT(*) ";
     $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` ";
     $query .= "WHERE TRUE ";
     // It would have been better to mock _getWhereClause method
     // but strangely, mocking private methods is not supported in PHPUnit
     $node = PMA_NodeFactory::getInstance();
     $dbi = $this->getMockBuilder('PMA_DatabaseInterface')->disableOriginalConstructor()->getMock();
     $dbi->expects($this->once())->method('fetchValue')->with($query);
     $GLOBALS['dbi'] = $dbi;
     $node->getPresence();
 }
コード例 #23
0
 /**
  * Test for setHiddenCount and getHiddenCount
  *
  * @return void
  */
 public function testHiddenCount()
 {
     $parent = PMA_NodeFactory::getInstance('Node_Database');
     $parent->setHiddenCount(3);
     $this->assertEquals(3, $parent->getHiddenCount());
 }
コード例 #24
0
 /**
  * Test for PMA_NodeFactory::getInstance
  *
  * @return void
  */
 public function testConstructor()
 {
     $parent = PMA_NodeFactory::getInstance('Node_Column');
     $this->assertArrayHasKey('text', $parent->links);
     $this->assertContains('tbl_structure.php', $parent->links['text']);
 }
コード例 #25
0
 /**
  * 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']['NavigationTreeDisableDatabaseExpansion']) {
         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 = strpos($child->name, $separator);
                 if ($sep_pos != false && $sep_pos != strlen($child->name) && $sep_pos != 0 && ($prefix_pos == false || $sep_pos < $prefix_pos)) {
                     $prefix_pos = $sep_pos;
                 }
             }
             if ($prefix_pos !== false) {
                 $prefix = 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 $child) {
                 if (array_key_exists($child->name, $prefixes)) {
                     $prefixes[$child->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]++;
             }
         }
     }
     foreach ($prefixes as $key => $value) {
         if ($value == 1) {
             unset($prefixes[$key]);
         }
     }
     if (count($prefixes)) {
         $groups = array();
         foreach ($prefixes as $key => $value) {
             $groups[$key] = new Node($key, Node::CONTAINER, true);
             $groups[$key]->separator = $node->separator;
             $groups[$key]->separator_depth = $node->separator_depth - 1;
             $groups[$key]->icon = '';
             if (PMA_Util::showIcons('TableNavigationLinksMode')) {
                 $groups[$key]->icon = PMA_Util::getImage('b_group.png');
             }
             $groups[$key]->pos2 = $node->pos2;
             $groups[$key]->pos3 = $node->pos3;
             if ($node instanceof Node_Table_Container || $node instanceof Node_View_Container) {
                 $tblGroup = '&amp;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) {
                 // FIXME: this could be more efficient
                 foreach ($node->children as $child) {
                     $name_substring = substr($child->name, 0, strlen($key) + strlen($separator));
                     if ($name_substring != $key . $separator && $child->name != $key || $child->type != Node::OBJECT) {
                         continue;
                     }
                     $class = get_class($child);
                     $new_child = PMA_NodeFactory::getInstance($class, substr($child->name, strlen($key) + strlen($separator)));
                     $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";
         }
     }
 }
コード例 #26
0
 /**
  * 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 = PMA_NodeFactory::getInstance('Node_Table');
     $this->assertContains($imageName, $node->icon[0]);
 }
コード例 #27
0
 /**
  * Test for __construct
  *
  * @return void
  */
 public function testConstructor()
 {
     $parent = PMA_NodeFactory::getInstance('Node_Function');
     $this->assertArrayHasKey('text', $parent->links);
     $this->assertContains('db_routines.php', $parent->links['text']);
 }
コード例 #28
0
 /**
  * Test for PMA_NodeFactory::getInstance
  *
  * @return void
  */
 public function testClassNameError()
 {
     $this->setExpectedException('PHPUnit_Framework_Error');
     PMA_NodeFactory::getInstance('Invalid');
 }