diff --git a/libraries/legacy/categories/categories.php b/libraries/legacy/categories/categories.php index cc48525efeecb..c8650940a8739 100644 --- a/libraries/legacy/categories/categories.php +++ b/libraries/legacy/categories/categories.php @@ -106,6 +106,8 @@ public function __construct($options) $this->_statefield = (isset($options['statefield'])) ? $options['statefield'] : 'state'; $options['access'] = (isset($options['access'])) ? $options['access'] : 'true'; $options['published'] = (isset($options['published'])) ? $options['published'] : 1; + $options['countItems'] = (isset($options['countItems'])) ? $options['countItems'] : 0; + $options['currentlang'] = JLanguageMultilang::isEnabled() ? JFactory::getLanguage()->getTag() : 0; $this->_options = $options; return true; @@ -259,20 +261,21 @@ protected function _load($id) ->where('badcats.id is null'); // Note: i for item - if (isset($this->_options['countItems']) && $this->_options['countItems'] == 1) + if ($this->_options['currentlang'] !== 0 || $this->_options['countItems'] == 1) { + $queryjoin = $db->quoteName($this->_table) . ' AS i ON i.' . $db->quoteName($this->_field) . ' = c.id'; + if ($this->_options['published'] == 1) { - $query->join( - 'LEFT', - $db->quoteName($this->_table) . ' AS i ON i.' . $db->quoteName($this->_field) . ' = c.id AND i.' . $this->_statefield . ' = 1' - ); + $queryjoin .= ' AND i.' . $this->_statefield . ' = 1'; } - else + + if ($this->_options['currentlang'] !== 0) { - $query->join('LEFT', $db->quoteName($this->_table) . ' AS i ON i.' . $db->quoteName($this->_field) . ' = c.id'); + $queryjoin .= ' AND (i.language = ' . $db->quote('*') . ' OR i.language = ' . $db->quote($this->_options['currentlang']) . ')'; } + $query->join('LEFT', $queryjoin); $query->select('COUNT(i.' . $db->quoteName($this->_key) . ') AS numitems'); } diff --git a/tests/unit/suites/libraries/legacy/categories/JCategoriesTest.php b/tests/unit/suites/libraries/legacy/categories/JCategoriesTest.php index 2ed6677ffdaf8..799d35f5dcb41 100644 --- a/tests/unit/suites/libraries/legacy/categories/JCategoriesTest.php +++ b/tests/unit/suites/libraries/legacy/categories/JCategoriesTest.php @@ -32,16 +32,29 @@ class JCategoriesTest extends TestCaseDatabase * * @since 3.2 */ - protected function setUp() + public function setUp() { + parent::setUp(); + + // Add JApplication and JLanguage dependencies + $this->saveFactoryState(); + JFactory::$language = $this->getMockLanguage(); + JFactory::$application = $this->getMockCmsApp(); } /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. + * Overrides the parent tearDown method. + * + * @return void + * + * @see PHPUnit_Framework_TestCase::tearDown() + * @since 3.2 */ protected function tearDown() { + $this->restoreFactoryState(); + + parent::tearDown(); } /**