diff --git a/libraries/cms/language/multilang.php b/libraries/cms/language/multilang.php index f19b01d3cfd7a..00e00c234ac34 100644 --- a/libraries/cms/language/multilang.php +++ b/libraries/cms/language/multilang.php @@ -20,11 +20,13 @@ class JLanguageMultilang * Method to determine if the language filter plugin is enabled. * This works for both site and administrator. * + * @param JApplicationCms $app The application object + * * @return boolean True if site is supporting multiple languages; false otherwise. * * @since 2.5.4 */ - public static function isEnabled() + public static function isEnabled(JApplicationCms $app = null) { // Flag to avoid doing multiple database queries. static $tested = false; @@ -32,8 +34,11 @@ public static function isEnabled() // Status of language filter plugin. static $enabled = false; - // Get application object. - $app = JFactory::getApplication(); + // Get application object if not injected. + if (!$app) + { + $app = JFactory::getApplication(); + } // If being called from the front-end, we can avoid the database query. if ($app->isSite()) @@ -60,6 +65,6 @@ public static function isEnabled() $tested = true; } - return $enabled; + return (bool) $enabled; } } diff --git a/tests/unit/suites/libraries/cms/language/JLanguageMultilangTest.php b/tests/unit/suites/libraries/cms/language/JLanguageMultilangTest.php new file mode 100644 index 0000000000000..a00389addc79e --- /dev/null +++ b/tests/unit/suites/libraries/cms/language/JLanguageMultilangTest.php @@ -0,0 +1,155 @@ +saveFactoryState(); + + JFactory::$document = $this->getMockDocument(); + JFactory::$language = $this->getMockLanguage(); + JFactory::$session = $this->getMockSession(); + + $this->backupServer = $_SERVER; + + $_SERVER['HTTP_HOST'] = self::TEST_HTTP_HOST; + $_SERVER['HTTP_USER_AGENT'] = self::TEST_USER_AGENT; + $_SERVER['REQUEST_URI'] = self::TEST_REQUEST_URI; + $_SERVER['SCRIPT_NAME'] = '/index.php'; + + // Set the config for the app + $this->config = new Registry; + $this->config->set('session', false); + } + + /** + * Overrides the parent tearDown method. + * + * @return void + * + * @see PHPUnit_Framework_TestCase::tearDown() + * @since 3.2 + */ + protected function tearDown() + { + // Reset the dispatcher instance. + TestReflection::setValue('JEventDispatcher', 'instance', null); + + $_SERVER = $this->backupServer; + $this->restoreFactoryState(); + + parent::tearDown(); + } + + + /** + * Gets the data set to be loaded into the database during setup + * + * @return PHPUnit_Extensions_Database_DataSet_CsvDataSet + * + * @since 3.4 + */ + protected function getDataSet() + { + $dataSet = new PHPUnit_Extensions_Database_DataSet_CsvDataSet(',', "'", '\\'); + + $dataSet->addTable('jos_extensions', JPATH_TEST_DATABASE . '/jos_extensions.csv'); + + return $dataSet; + } + + /** + * @testdox Ensure isEnabled() proxies correctly to JApplicationSite + * + * @covers JLanguageMultiLang::isEnabled + * @uses JApplicationSite + */ + public function testIsEnabledWithSiteApp() + { + $app = new JApplicationSite($this->getMockInput(), $this->config); + + $this->assertFalse( + JLanguageMultilang::isEnabled($app) + ); + } + + /** + * @testdox Ensure isEnabled() database query works correctly + * + * @covers JLanguageMultiLang::isEnabled + * @uses JApplicationAdministrator + */ + public function testIsEnabledWithAdminApp() + { + $app = new JApplicationAdministrator($this->getMockInput(), $this->config); + + $this->assertFalse( + JLanguageMultilang::isEnabled($app) + ); + } +}