diff --git a/tests/unit/suites/libraries/cms/component/router/rules/JComponentRouterRulesMenuTest.php b/tests/unit/suites/libraries/cms/component/router/rules/JComponentRouterRulesMenuTest.php index 6c40a9736a631..c4ea6c9957135 100644 --- a/tests/unit/suites/libraries/cms/component/router/rules/JComponentRouterRulesMenuTest.php +++ b/tests/unit/suites/libraries/cms/component/router/rules/JComponentRouterRulesMenuTest.php @@ -162,11 +162,23 @@ public function testPreprocess() $query = array('option' => 'com_content', 'view' => 'categories', 'id' => '42', 'Itemid' => '99'); $this->object->preprocess($query); $this->assertEquals(array('option' => 'com_content', 'view' => 'categories', 'id' => '42', 'Itemid' => '99'), $query); - + // Check if a query with existing Itemid that is the current active menu-item is correctly searched $query = array('option' => 'com_content', 'view' => 'categories', 'id' => '14', 'Itemid' => '49'); $this->object->preprocess($query); $this->assertEquals(array('option' => 'com_content', 'view' => 'categories', 'id' => '14', 'Itemid' => '48'), $query); + + // Test if the default Itemid is used if everything else fails + $router = $this->object->get('router'); + $router->menu->active = null; + $query = array(); + $this->object->preprocess($query); + $this->assertEquals(array('Itemid' => '47'), $query); + + // Test if the correct default item is used based on the language + $query = array('lang' => 'en-GB'); + $this->object->preprocess($query); + $this->assertEquals(array('lang' => 'en-GB', 'Itemid' => '51'), $query); } /** diff --git a/tests/unit/suites/libraries/cms/component/router/rules/stubs/MockJComponentRouterRulesMenuMenuObject.php b/tests/unit/suites/libraries/cms/component/router/rules/stubs/MockJComponentRouterRulesMenuMenuObject.php index c4fc4f4778d59..3b710d4eebce5 100644 --- a/tests/unit/suites/libraries/cms/component/router/rules/stubs/MockJComponentRouterRulesMenuMenuObject.php +++ b/tests/unit/suites/libraries/cms/component/router/rules/stubs/MockJComponentRouterRulesMenuMenuObject.php @@ -23,6 +23,13 @@ class MockJComponentRouterRulesMenuMenuObject */ protected $items = array(); + /** + * Active menuitem + * + * @var integer + */ + public $active = 49; + /** * Constructor for this object * @@ -163,7 +170,7 @@ public function getItems($attributes, $values) */ public function getActive() { - return $this->items[49]; + return (isset($this->items[$this->active]) ? $this->items[$this->active] : null); } /** @@ -176,12 +183,12 @@ public function getActive() */ public function getDefault($language = '*') { - if ($language = '*') + if ($language == '*') { return $this->items[47]; } - if ($language = 'en-GB') + if ($language == 'en-GB') { return $this->items[51]; }