/** * Class constructor. * * @since 3.1 */ public function __construct() { // Run the parent constructor parent::__construct(); // Load and set the dispatcher $this->loadDispatcher(); // Enable sessions by default. if (is_null($this->config->get('session'))) { $this->config->set('session', true); } // Set the session default name. if (is_null($this->config->get('session_name'))) { $this->config->set('session_name', 'installation'); } // Create the session if a session name is passed. if ($this->config->get('session') !== false) { $this->loadSession(); // Register the session with JFactory JFactory::$session = $this->getSession(); } // Store the debug value to config based on the JDEBUG flag $this->config->set('debug', JDEBUG); // Register the config to JFactory JFactory::$config = $this->config; // Register the application to JFactory JFactory::$application = $this; // Set the root in the URI based on the application name JUri::root(null, str_ireplace('/installation', '', JUri::base(true))); }
/** * Constructor. * * @since 3.2 */ public function __construct() { parent::__construct(); // Overrides application config and set the configuration.php file so the send function will work JFactory::$config = null; JFactory::getConfig(JPATH_SITE . '/configuration.php'); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @return void */ protected function setUp() { $this->saveFactoryState(); JFactory::$application = $this->getMockCmsApp(); JFactory::$config = $this->getMockConfig(); parent::setUp(); }
/** * Class constructor. * * @since 3.1 */ public function __construct() { // Run the parent constructor parent::__construct(); // Load and set the dispatcher $this->loadDispatcher(); // Enable sessions by default. if (is_null($this->config->get('session'))) { $this->config->set('session', true); } // Set the session default name. if (is_null($this->config->get('session_name'))) { $this->config->set('session_name', 'installation'); } // Create the session if a session name is passed. if ($this->config->get('session') !== false) { $this->loadSession(); // Register the session with JFactory JFactory::$session = $this->getSession(); } // Store the debug value to config based on the JDEBUG flag $this->config->set('debug', JDEBUG); // Register the config to JFactory JFactory::$config = $this->config; // Register the application to JFactory JFactory::$application = $this; // Register the application name $this->_name = 'installation'; // Register the client ID $this->_clientId = 2; // Set the root in the URI one level up. $parts = explode('/', JUri::base(true)); array_pop($parts); JUri::root(null, implode('/', $parts)); }
/** * Constructor. * * @since 3.1 */ public function __construct() { parent::__construct(); // Overrides application config and set the configuration.php file so tokens and database works JFactory::$config = null; JFactory::getConfig(JPATH_SITE . '/configuration.php'); }
/** * Tests JHtml::calendar() method with and without 'readonly' attribute. */ public function testCalendar() { // Create a world for the test jimport('joomla.session.session'); jimport('joomla.application.application'); jimport('joomla.document.document'); $cfg = new JObject(); JFactory::$session = $this->getMock('JSession', array('_start')); JFactory::$application = $this->getMock('ApplicationMock'); JFactory::$config = $cfg; JFactory::$application->expects($this->any())->method('getTemplate')->will($this->returnValue('atomic')); $cfg->live_site = 'http://example.com'; $cfg->offset = 'Europe/Kiev'; $_SERVER['HTTP_USER_AGENT'] = 'Test Browser'; // two sets of test data $test_data = array('date' => '2010-05-28 00:00:00', 'friendly_date' => 'Friday, 28 May 2010', 'name' => 'cal1_name', 'id' => 'cal1_id', 'format' => '%Y-%m-%d', 'attribs' => array()); $test_data_ro = array_merge($test_data, array('attribs' => array('readonly' => 'readonly'))); foreach (array($test_data, $test_data_ro) as $data) { // Reset the document JFactory::$document = JDocument::getInstance('html', array('unique_key' => serialize($data))); $input = JHtml::calendar($data['date'], $data['name'], $data['id'], $data['format'], $data['attribs']); $this->assertEquals((string) $xml->input['title'], $data['friendly_date'], 'Line:' . __LINE__ . ' The calendar input should have `title == "' . $data['friendly_date'] . '"`'); $this->assertEquals((string) $xml->input['name'], $data['name'], 'Line:' . __LINE__ . ' The calendar input should have `name == "' . $data['name'] . '"`'); $this->assertEquals((string) $xml->input['id'], $data['id'], 'Line:' . __LINE__ . ' The calendar input should have `id == "' . $data['id'] . '"`'); $head_data = JFactory::getDocument()->getHeadData(); if (!isset($data['attribs']['readonly']) || !$data['attribs']['readonly'] === 'readonly') { $this->assertArrayHasKey('/media/system/js/calendar.js', $head_data['scripts'], 'Line:' . __LINE__ . ' JS file "calendar.js" should be loaded'); $this->assertArrayHasKey('/media/system/js/calendar-setup.js', $head_data['scripts'], 'Line:' . __LINE__ . ' JS file "calendar-setup.js" should be loaded'); } } }
/** * Return a config object populated with the config from the Joomlas config file */ public static function getConfig() { if (!self::$config) { self::$config = new FakeConfig(); } return self::$config; }
/** * Testing testEncrypt(). * * @param string $text The text to be encrypted * @param string $key The key to use * @param string $expected The expected result of encryption * * @return void * @dataProvider casesEncryption */ public function testEncrypt($text, $key, $expected) { $cfg = $this->getMock('JObject', array('get')); $cfg->expects($this->any())->method('get')->will($this->returnValue('')); JFactory::$config = $cfg; $this->object = new JSimpleCrypt($key); $this->assertThat($this->object->encrypt($text), $this->equalTo($expected)); }
/** * Tests the JFactory::getConfig method. * * @return void * * @since 11.3 * @covers JFactory::getConfig * @covers JFactory::createConfig */ function testGetConfig() { // Temporarily override the config cache in JFactory. $temp = JFactory::$config; JFactory::$config = null; $this->assertInstanceOf('JRegistry', JFactory::getConfig(JPATH_TESTS . '/config.php'), 'Line: ' . __LINE__); JFactory::$config = $temp; }
/** * Tests the JFactory::getConfig method. * * @return void * * @since 11.3 */ function testGetConfig() { // Temporarily override the config cache in JFactory. $temp = JFactory::$config; JFactory::$config = null; $this->assertThat(JFactory::getConfig(JPATH_TESTS . '/config.php'), $this->isInstanceOf('JRegistry')); JFactory::$config = $temp; }
/** * Testing JApplication::getHash * * @return void */ public function testGetHash() { // Temporarily override the config cache in JFactory. $temp = JFactory::$config; JFactory::$config = new JObject(array('secret' => 'foo')); $this->assertThat(JApplication::getHash('This is a test'), $this->equalTo(md5('foo' . 'This is a test')), 'Tests that the secret string is added to the hash.'); JFactory::$config = $temp; }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { $this->saveFactoryState(); $_SERVER['HTTP_HOST'] = 'localhost'; $_SERVER['SCRIPT_NAME'] = ''; JFactory::$application = $this->getMockApplication(); JFactory::$config = $this->getMockConfig(); $this->object = new JDocumentOpensearch(); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { $this->saveFactoryState(); $_SERVER['HTTP_HOST'] = 'localhost'; $_SERVER['SCRIPT_NAME'] = ''; JFactory::$application = $this->getMock('JApplication', array('get', 'getCfg', 'getRouter', 'getTemplate'), array(array('session' => false))); JFactory::$config = $this->getMock('JConfig', array('get')); $this->object = new JDocumentOpensearch(); }
/** * Get a configuration object * * Returns the global {@link JRegistry} object, only creating it * if it doesn't already exist. * * @param string The path to the configuration file * @param string The type of the configuration file * @return object JRegistry */ public static function getConfig($file = null, $type = 'PHP') { if (!is_object(JFactory::$config)) { if ($file === null) { $file = dirname(__FILE__) . DS . 'config.php'; } JFactory::$config = JFactory::_createConfig($file, $type); } return JFactory::$config; }
/** * Get a configuration object * * Returns the global {@link JRegistry} object, only creating it * if it doesn't already exist. * * @param string $file The path to the configuration file * @param string $type The type of the configuration file * * @return JRegistry object */ public static function getConfig($file = null, $type = 'PHP') { if (!self::$config) { if ($file === null) { $file = dirname(__FILE__) . DS . 'config.php'; } self::$config = self::_createConfig($file, $type); } return self::$config; }
/** * Get a configuration object * * Returns the global {@link JRegistry} object, only creating it * if it doesn't already exist. * * @param string $file The path to the configuration file * @param string $type The type of the configuration file * * @see JRegistry * * @return JRegistry object */ public static function getConfig($file = null, $type = 'PHP') { if (!self::$config) { if ($file === null) { $file = JPATH_PLATFORM . '/config.php'; } self::$config = self::_createConfig($file, $type); } return self::$config; }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @return void * * @since 3.1 */ protected function setUp() { $this->saveFactoryState(); parent::setUp(); JFactory::$application = $this->getMockCmsApp(); JFactory::$config = $this->getMockConfig(); JFactory::$document = $this->getMockDocument(); $this->backupServer = $_SERVER; $_SERVER['HTTP_HOST'] = 'example.com'; $_SERVER['SCRIPT_NAME'] = ''; }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @return void */ protected function setUp() { if (!defined('JPATH_COMPONENT')) { define('JPATH_COMPONENT', JPATH_BASE . '/components/com_foobar'); } $this->saveFactoryState(); JFactory::$application = $this->getMockCmsApp(); JFactory::$config = $this->getMockConfig(); $this->class = new JControllerLegacy(); parent::setUp(); }
/** * Sets up dependancies for the test. * * @return void */ protected function setUp() { jimport('joomla.environment.request'); require_once JPATH_PLATFORM . '/joomla/form/fields/rules.php'; include_once dirname(__DIR__) . '/inspectors.php'; $this->saveFactoryState(); $_SERVER['HTTP_HOST'] = 'localhost'; $_SERVER['SCRIPT_NAME'] = ''; JFactory::$application = $this->getMockApplication(); JFactory::$config = $this->getMockConfig(); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->saveFactoryState(); JFactory::$application = $this->getMock('JApplication', array('get', 'getCfg', 'getRouter')); JFactory::$application->expects($this->any())->method('getRouter')->will($this->returnValue(new JRouter())); JFactory::$config = $this->getMock('JConfig', array('get')); $_SERVER['REQUEST_METHOD'] = 'get'; JRequest::setVar('type', 'atom'); $this->object = new JDocumentFeed(); $_SERVER['HTTP_HOST'] = 'localhost'; $_SERVER['SCRIPT_NAME'] = ''; }
/** * Sets the Factory pointers * * @return void */ protected function restoreFactoryState() { \JFactory::$application = $this->savedFactoryState['application']; \JFactory::$config = $this->savedFactoryState['config']; \JFactory::$dates = $this->savedFactoryState['dates']; \JFactory::$session = $this->savedFactoryState['session']; \JFactory::$language = $this->savedFactoryState['language']; \JFactory::$document = $this->savedFactoryState['document']; \JFactory::$acl = $this->savedFactoryState['acl']; \JFactory::$database = $this->savedFactoryState['database']; \JFactory::$mailer = $this->savedFactoryState['mailer']; }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @return void * * @since 3.1 */ protected function setUp() { // Ensure the loaded states are reset JHtmlJqueryInspector::resetLoaded(); parent::setUp(); $this->saveFactoryState(); JFactory::$application = $this->getMockCmsApp(); JFactory::$config = $this->getMockConfig(); JFactory::$document = $this->getMockDocument(); $this->backupServer = $_SERVER; $_SERVER['HTTP_HOST'] = 'example.com'; $_SERVER['SCRIPT_NAME'] = ''; }
/** * Constructor: Deletes the default installation config file and recreates it with the good config file. * * @since 3.1 */ public function __construct() { // Overrides application config and set the configuration.php file so tokens and database works. JFactory::$config = null; JFactory::getConfig(JPATH_SITE . '/configuration.php'); /* * JFactory::getDbo() gets called during app bootup, and because of the "uniqueness" of the install app, the config doesn't get read * correctly at that point. So, we have to reset the factory database object here so that we can get a valid database configuration. * The day we have proper dependency injection will be a glorious one. */ JFactory::$database = null; parent::__construct(); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { // Store the factory state so we can mock the necessary objects $this->saveFactoryState(); JFactory::$application = $this->getMockApplication(); JFactory::$config = $this->getMockConfig(); JFactory::$session = $this->getMockSession(); // Set up our mock config $this->config = JFactory::getConfig(); $this->config->set('helpurl', 'http://help.joomla.org/proxy/index.php?option=com_help&keyref=Help{major}{minor}:{keyref}'); // Load the admin en-GB.ini language file JFactory::getLanguage()->load('', JPATH_ADMINISTRATOR); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @return void * * @since 3.1 */ protected function setUp() { parent::setUp(); $this->outputPath = __DIR__ . '/output'; if (!is_dir($this->outputPath)) { mkdir($this->outputPath, 0777); } if (!is_dir($this->outputPath)) { $this->markTestSkipped('We can not create the output dir, so skip all tests'); } $this->saveFactoryState(); // We need a configuration with a tmp_path set JFactory::$config = new Registry(['tmp_path' => __DIR__ . '/output']); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @TODO Once the coupling has been loosed, revisit and build a test harness we can use * * @access protected * * @return void */ protected function setUp() { parent::setUp(); $this->backupServer = $_SERVER; $this->markTestSkipped("Too tightly coupled to internals to be testable now"); $this->saveFactoryState(); JFactory::$application = $this->getMock('JApplication', array('get', 'getCfg', 'getRouter')); JFactory::$application->expects($this->any())->method('getRouter')->will($this->returnValue(new JRouter())); JFactory::$config = $this->getMock('JConfig', array('get')); $_SERVER['REQUEST_METHOD'] = 'get'; $input = JFactory::getApplication()->input; $input->set('type', 'rss'); $this->object = new JDocumentFeed(); $_SERVER['HTTP_HOST'] = 'localhost'; $_SERVER['SCRIPT_NAME'] = ''; }
/** * Test the JLoggerFormattedText::__construct method. */ public function testConstructor04() { // Temporarily override the config cache in JFactory. $temp = JFactory::$config; JFactory::$config = new JObject(array('log_path' => '/var/logs')); // Setup the basic configuration. $config = array('text_file_path' => '', 'text_file' => '', 'text_entry_format' => '{DATETIME} {PRIORITY} {MESSAGE}'); $logger = new JLoggerFormattedTextInspector($config); // Default format string. $this->assertEquals($logger->format, '{DATETIME} {PRIORITY} {MESSAGE}', 'Line: ' . __LINE__); // Default format string. $this->assertEquals($logger->fields, array('DATETIME', 'PRIORITY', 'MESSAGE'), 'Line: ' . __LINE__); // Default file name. $this->assertEquals($logger->path, '/var/logs/error.php', 'Line: ' . __LINE__); JFactory::$config = $temp; }
/** * Tests JHtml::calendar() method with and without 'readonly' attribute. */ public function testCalendar() { // Create a world for the test jimport('joomla.session.session'); jimport('joomla.application.application'); jimport('joomla.document.document'); $cfg = new JObject(); JFactory::$session = $this->getMock('JSession', array('_start')); JFactory::$application = $this->getMock('ApplicationMock'); JFactory::$config = $cfg; JFactory::$application->expects($this->any())->method('getTemplate')->will($this->returnValue('atomic')); $cfg->live_site = 'http://example.com'; $cfg->offset = 'Europe/Kiev'; $_SERVER['HTTP_USER_AGENT'] = 'Test Browser'; // two sets of test data $test_data = array('date' => '2010-05-28', 'friendly_date' => 'Friday, 28 May 2010', 'name' => 'cal1_name', 'id' => 'cal1_id', 'format' => '%Y-%m-%d', 'attribs' => array()); $test_data_ro = array_merge($test_data, array('attribs' => array('readonly' => 'readonly'))); foreach (array($test_data, $test_data_ro) as $data) { // Reset the document JFactory::$document = JDocument::getInstance('html', array('unique_key' => serialize($data))); $input = JHtml::calendar($data['date'], $data['name'], $data['id'], $data['format'], $data['attribs']); $this->assertThat(strlen($input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The calendar method should return something without error.'); $xml = new simpleXMLElement('<calendar>' . $input . '</calendar>'); $this->assertEquals((string) $xml->input['type'], 'text', 'Line:' . __LINE__ . ' The calendar input should have `type == "text"`'); $this->assertEquals((string) $xml->input['title'], $data['friendly_date'], 'Line:' . __LINE__ . ' The calendar input should have `title == "' . $data['friendly_date'] . '"`'); $this->assertEquals((string) $xml->input['name'], $data['name'], 'Line:' . __LINE__ . ' The calendar input should have `name == "' . $data['name'] . '"`'); $this->assertEquals((string) $xml->input['id'], $data['id'], 'Line:' . __LINE__ . ' The calendar input should have `id == "' . $data['id'] . '"`'); $this->assertEquals((string) $xml->input['value'], $data['date'], 'Line:' . __LINE__ . ' The calendar input should have `value == "' . $data['date'] . '"`'); $head_data = JFactory::getDocument()->getHeadData(); if (isset($data['attribs']['readonly']) && $data['attribs']['readonly'] === 'readonly') { $this->assertEquals((string) $xml->input['readonly'], $data['attribs']['readonly'], 'Line:' . __LINE__ . ' The readonly calendar input should have `readonly == "' . $data['attribs']['readonly'] . '"`'); $this->assertFalse(isset($xml->img), 'Line:' . __LINE__ . ' The readonly calendar input shouldn\'t have a calendar image'); $this->assertArrayNotHasKey('/media/system/js/calendar.js', $head_data['scripts'], 'Line:' . __LINE__ . ' JS file "calendar.js" shouldn\'t be loaded'); $this->assertArrayNotHasKey('/media/system/js/calendar-setup.js', $head_data['scripts'], 'Line:' . __LINE__ . ' JS file "calendar-setup.js" shouldn\'t be loaded'); $this->assertArrayNotHasKey('text/javascript', $head_data['script'], 'Line:' . __LINE__ . ' Inline JS for the calendar shouldn\'t be loaded'); } else { $this->assertFalse(isset($xml->input['readonly']), 'Line:' . __LINE__ . ' The calendar input shouldn\'t have readonly attribute'); $this->assertTrue(isset($xml->img), 'Line:' . __LINE__ . ' The calendar input should have a calendar image'); $this->assertEquals((string) $xml->img['id'], $data['id'] . '_img', 'Line:' . __LINE__ . ' The calendar image should have `id == "' . $data['id'] . '_img' . '"`'); $this->assertEquals((string) $xml->img['class'], 'calendar', 'Line:' . __LINE__ . ' The calendar image should have `class == "calendar"`'); $this->assertFileExists(JPATH_ROOT . $xml->img['src'], 'Line:' . __LINE__ . ' The calendar image source should point to an existent file'); $this->assertArrayHasKey('/media/system/js/calendar.js', $head_data['scripts'], 'Line:' . __LINE__ . ' JS file "calendar.js" should be loaded'); $this->assertArrayHasKey('/media/system/js/calendar-setup.js', $head_data['scripts'], 'Line:' . __LINE__ . ' JS file "calendar-setup.js" should be loaded'); $this->assertContains('DHTML Date/Time Selector', $head_data['script']['text/javascript'], 'Line:' . __LINE__ . ' Inline JS for the calendar should be loaded'); } } }
/** * Class constructor. * * @param JInput $input An optional argument to provide dependency injection for the application's * input object. If the argument is a JInput object that object will become * the application's input object, otherwise a default input object is created. * @param Registry $config An optional argument to provide dependency injection for the application's * config object. If the argument is a Registry object that object will become * the application's config object, otherwise a default config object is created. * @param JApplicationWebClient $client An optional argument to provide dependency injection for the application's * client object. If the argument is a JApplicationWebClient object that object will become * the application's client object, otherwise a default client object is created. * @param Container $container Dependency injection container. * * @since 3.1 */ public function __construct(JInput $input = null, Registry $config = null, JApplicationWebClient $client = null, Container $container = null) { // Register the application name. $this->name = 'installation'; // Register the client ID. $this->clientId = 2; // Run the parent constructor. parent::__construct($input, $config, $client, $container); // Store the debug value to config based on the JDEBUG flag. $this->config->set('debug', JDEBUG); // Register the config to JFactory. JFactory::$config = $this->config; // Set the root in the URI one level up. $parts = explode('/', JUri::base(true)); array_pop($parts); JUri::root(null, implode('/', $parts)); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @TODO Once the coupling has been loosed, revisit and build a test harness we can use * * @access protected */ protected function setUp() { $this->markTestSkipped("Too tightly coupled to internals to be testable now"); require_once JPATH_PLATFORM . '/joomla/application/router.php'; require_once JPATH_PLATFORM . '/joomla/environment/request.php'; require_once JPATH_PLATFORM . '/joomla/document/feed/feed.php'; require_once JPATH_PLATFORM . '/joomla/environment/response.php'; $this->saveFactoryState(); JFactory::$application = $this->getMock('JApplication', array('get', 'getCfg', 'getRouter')); JFactory::$application->expects($this->any())->method('getRouter')->will($this->returnValue(new JRouter())); JFactory::$config = $this->getMock('JConfig', array('get')); $_SERVER['REQUEST_METHOD'] = 'get'; JRequest::setVar('type', 'rss'); $this->object = new JDocumentFeed(); $_SERVER['HTTP_HOST'] = 'localhost'; $_SERVER['SCRIPT_NAME'] = ''; }