/**
  * Tests the getPath() method
  *
  * @return  void
  *
  * @since   3.4
  * @covers  JComponentRouterView::getPath
  */
 public function testGetPath()
 {
     // This test requires an application registered to JFactory
     $this->saveFactoryState();
     JFactory::$application = $this->object->app;
     $views = $this->getComContentViews();
     $this->object->set('name', 'unittest');
     foreach ($views as $view) {
         $this->object->registerView($view);
     }
     // No view, so we don't have a path to return.
     $query = array('task' => 'edit');
     $this->assertEquals(array(), $this->object->getPath($query));
     // View without any parents and children
     $query = array('view' => 'form');
     $this->assertEquals(array('form' => true), $this->object->getPath($query));
     // View without any parents, but with children
     $query = array('view' => 'categories');
     $this->assertEquals(array('categories' => true), $this->object->getPath($query));
     // View with parent and children
     $query = array('view' => 'category', 'id' => '9');
     $this->assertEquals(array('category' => array('9:uncategorised'), 'categories' => true), $this->object->getPath($query));
     //View with parent, no children
     $query = array('view' => 'article', 'id' => '42:question-for-everything', 'catid' => '9');
     $this->assertEquals(array('article' => array('42:question-for-everything'), 'category' => array('9:uncategorised'), 'categories' => true), $this->object->getPath($query));
     //View with parent, no children and nested view
     $query = array('view' => 'article', 'id' => '42:question-for-everything', 'catid' => '20');
     $this->assertEquals(array('article' => array('42:question-for-everything'), 'category' => array('20:extensions', '19:joomla', '14:sample-data-articles'), 'categories' => true), $this->object->getPath($query));
     $this->restoreFactoryState();
 }
 /**
  * Tests the getPath() method
  *
  * @return  void
  *
  * @dataProvider  casesGetPath
  * @since   3.5
  * @covers  JComponentRouterView::getPath
  */
 public function testGetPath($input, $result)
 {
     // This test requires an application registered to JFactory
     $this->saveFactoryState();
     JFactory::$application = $this->object->app;
     $views = $this->getComContentViews();
     $this->object->set('name', 'unittest');
     foreach ($views as $view) {
         $this->object->registerView($view);
     }
     $this->assertEquals($result, $this->object->getPath($input));
     $this->restoreFactoryState();
 }
예제 #3
0
 /**
  * Build a standard URL
  *
  * @param   array  &$query     The vars that should be converted
  * @param   array  &$segments  The URL segments to create
  *
  * @return  void
  *
  * @since   3.4
  */
 public function build(&$query, &$segments)
 {
     // Get the menu item belonging to the Itemid that has been found
     $item = $this->router->menu->getItem($query['Itemid']);
     if (!isset($query['view'])) {
         return;
     }
     // Get all views for this component
     $views = $this->router->getViews();
     // Return directly when the URL of the Itemid is identical with the URL to build
     if (isset($item->query['view']) && $item->query['view'] == $query['view']) {
         $view = $views[$query['view']];
         if (isset($item->query[$view->key]) && $item->query[$view->key] == (int) $query[$view->key]) {
             unset($query[$view->key]);
             while ($view) {
                 unset($query[$view->parent_key]);
                 $view = $view->parent;
             }
             unset($query['view']);
             if (isset($item->query['layout']) && isset($query['layout']) && $item->query['layout'] == $query['layout']) {
                 unset($query['layout']);
             }
             return;
         }
         if (!$view->key) {
             if (isset($item->query['layout']) && isset($query['layout']) && $item->query['layout'] == $query['layout']) {
                 unset($query['view']);
                 unset($query['layout']);
                 return;
             }
         }
     }
     // Get the path from the view of the current URL and parse it to the menu item
     $path = array_reverse($this->router->getPath($query), true);
     $found = false;
     $found2 = false;
     for ($i = 0, $j = count($path); $i < $j; $i++) {
         reset($path);
         $view = key($path);
         if ($found) {
             $ids = array_shift($path);
             if ($views[$view]->nestable) {
                 foreach (array_reverse($ids, true) as $id => $segment) {
                     if ($found2) {
                         $segments[] = str_replace(':', '-', $segment);
                     } else {
                         if ((int) $item->query[$views[$view]->key] == (int) $id) {
                             $found2 = true;
                         }
                     }
                 }
             } else {
                 if (is_bool($ids)) {
                     $segments[] = $views[$view]->name;
                 } else {
                     $segments[] = str_replace(':', '-', array_shift($ids));
                 }
             }
         } else {
             if ($item->query['view'] != $view) {
                 array_shift($path);
             } else {
                 if (!$views[$view]->nestable) {
                     array_shift($path);
                 } else {
                     $i--;
                     $found2 = false;
                 }
                 $found = true;
             }
         }
         unset($query[$views[$view]->parent_key]);
     }
     if ($found) {
         unset($query['layout']);
         unset($query[$views[$query['view']]->key]);
         unset($query['view']);
     }
 }