/** * Method to run the Web application routines. * * @return void */ protected function doExecute() { $this->loadDocument(); $document = $this->getDocument(); // Register the template to the config $this->set('theme', 'template'); $this->set('themeParams', new JRegistry()); // Inject the document object into the factory JFactory::$document = $document; switch ($document->getType()) { case 'html': // Set metadata $document->setTitle('Joomla! Guestbook'); break; default: break; } // Execute the task. try { $controller = $this->fetchController($this->input->getCmd('task', 'display')); $contents = $controller->execute(); } catch (RuntimeException $e) { echo $e->getMessage(); $this->close($e->getCode()); } $document->setBuffer($contents, 'component'); }
/** * 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'); } } }
/** * Register the API server. * * @throws \Exception * @return boolean */ public function register() { $uri = \JURI::getInstance(); if (!$this->isApi()) { return false; } $app = \JFactory::getApplication(); $input = $app->input; // Restore Joomla handler and using our Json handler. JsonResponse::registerErrorHandler(); // Authentication if (!$this->isUserOperation($uri) && $this->option['authorise']) { if (!Authentication::authenticate($input->get('session_key'))) { throw new \Exception(\JText::_('JERROR_ALERTNOAUTHOR'), 403); } } // Set Format to JSON $input->set('format', 'json'); // Store JDocumentJson to Factory \JFactory::$document = \JDocument::getInstance('json'); $router = $app::getRouter(); // Attach a hook to Router $router->attachParseRule(array($this, 'parseRule')); return true; }
/** * Dispatch the application * * @param string $component The component which is being rendered. * * @return void * * @since 3.2 */ public function dispatch($component = null) { if ($component === null) { $component = JAdministratorHelper::findOption(); } // Load the document to the API $this->loadDocument(); // Set up the params $document = JFactory::getDocument(); // Register the document object with JFactory JFactory::$document = $document; switch ($document->getType()) { case 'html': $document->setMetaData('keywords', $this->get('MetaKeys')); // Get the template $template = $this->getTemplate(true); // Store the template and its params to the config $this->set('theme', $template->template); $this->set('themeParams', $template->params); break; default: break; } $document->setTitle($this->get('sitename') . ' - ' . JText::_('JADMINISTRATION')); $document->setDescription($this->get('MetaDesc')); $document->setGenerator('Joomla! - Open Source Content Management'); $contents = JComponentHelper::renderComponent($component); $document->setBuffer($contents, 'component'); // Trigger the onAfterDispatch event. JPluginHelper::importPlugin('system'); $this->triggerEvent('onAfterDispatch'); }
/** * Sets up the fixture. * * This method is called before a test is executed. * * @return void */ protected function setUp() { JFactory::$application = $this->getMockApplication(); JFactory::$document = $this->getMockDocument(); $this->_instance = new JDocumentRendererMessage(JFactory::getDocument()); parent::setUp(); }
/** * Sets up the fixture. * * This method is called before a test is executed. */ protected function setUp() { parent::setUp(); $this->saveFactoryState(); JFactory::$application = $this->getMockCmsApp(); JFactory::$document = $this->getMockDocument(); JFactory::$session = $this->getMockSession(); $this->instance = new JDocumentRendererMessage(JFactory::getDocument()); }
/** * 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(); JFactory::$application = $this->getMockApplication(); 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 * * @since 3.1 */ protected function setUp() { // Ensure the loaded states are reset JHtmlJqueryInspector::resetLoaded(); $this->saveFactoryState(); JFactory::$application = $this->getMockApplication(); JFactory::$document = $this->getMockDocument(); $this->backupServer = $_SERVER; $_SERVER['HTTP_HOST'] = 'example.com'; $_SERVER['SCRIPT_NAME'] = ''; }
/** * Setup for testing. * * @return void * * @since 11.3 */ public function setUp() { parent::setUp(); $_SERVER['HTTP_HOST'] = self::TEST_HTTP_HOST; $_SERVER['HTTP_USER_AGENT'] = self::TEST_USER_AGENT; // Get a new JApplicationWebInspector instance. $this->inspector = new JApplicationWebInspector(); // We are only coupled to Document and Language in JFactory. $this->saveFactoryState(); JFactory::$document = $this->getMockDocument(); JFactory::$language = $this->getMockLanguage(); }
/** * 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']; }
/** * Setup for testing. * * @return void * * @since 3.6 */ public function setUp() { parent::setUp(); $this->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'; }
/** * 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->saveFactoryState(); JFactory::$application = $this->getMockCmsApp(); JFactory::$config = $this->getMockConfig(); JFactory::$document = $this->getMockDocument(); JFactory::$language = $this->getMockLanguage(); JFactory::$session = $this->getMockSession(); $this->backupServer = $_SERVER; $_SERVER['HTTP_HOST'] = 'example.com'; $_SERVER['SCRIPT_NAME'] = ''; }
/** * Prepares the environment before running a test. * * @return void * * @since 1.0 */ protected function setUp() { parent::setUp(); $_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'; // Get a new JApplicationWebInspector instance. $this->_instance = new WebServiceApplicationWebInspector(); // We are only coupled to Document and Language in JFactory. $this->saveFactoryState(); JFactory::$document = $this->getMockDocument(); JFactory::$language = $this->getMockLanguage(); }
/** * 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 JHtmlBehaviorInspector::resetLoaded(); parent::setUp(); $this->saveFactoryState(); JFactory::$application = $this->getMockCmsApp(); JFactory::$document = $this->getMockDocument(); JFactory::$session = $this->getMockSession(); // We generate a random template name so that we don't collide or hit anything JFactory::$application->expects($this->any())->method('getTemplate')->willReturn('mytemplate' . mt_rand(1, 10000)); $this->backupServer = $_SERVER; $_SERVER['HTTP_HOST'] = 'example.com'; $_SERVER['SCRIPT_NAME'] = ''; }
/** * 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'); } } }
/** * Setup for testing. * * @return void * * @since 3.2 */ public function setUp() { parent::setUp(); $_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 $config = new JRegistry(); $config->set('session', false); // Get a new JApplicationCmsInspector instance. $this->class = new JApplicationCmsInspector(null, $config); // We are coupled to Document and Language in JFactory. $this->saveFactoryState(); JFactory::$document = $this->getMockDocument(); JFactory::$language = $this->getMockLanguage(); }
/** * Setup for testing. * * @return void * * @since 3.2 */ public function setUp() { parent::setUp(); $this->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 $config = new Registry(); $config->set('session', false); // Get a new JApplicationSite instance. $this->class = new JApplicationSite($this->getMockInput(), $config); TestReflection::setValue('JApplicationCms', 'instances', array('site' => $this->class)); }
/** * Setup for testing. * * @return void * * @since 3.2 */ public function setUp() { parent::setUp(); $this->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 $config = new Registry(); $config->set('session', false); // Get a new JApplicationCmsInspector instance. $this->class = new JApplicationCmsInspector($this->getMockInput(), $config); $this->class->setSession(JFactory::$session); $this->class->setDispatcher($this->getMockDispatcher()); JFactory::$application = $this->class; }
/** * Tests JHtml::calendar() method with and without 'readonly' attribute. * * @return void * * @since 3.1 */ public function testCalendar() { $cfg = $this->getMockConfig(); $map = array(array('live_site', 'http://example.com'), array('offset', 'Europe/Kiev')); $cfg->expects($this->any())->method('get')->willReturnMap($map); JFactory::$session = $this->getMockSession(); JFactory::$config = $cfg; JFactory::$application->expects($this->any())->method('getTemplate')->will($this->returnValue('atomic')); // 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(), 'formattedDate' => '2010-05-28'); $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 = $this->getMockDocument(); $input = JHtml::calendar($data['date'], $data['name'], $data['id'], $data['format'], $data['attribs']); $this->assertGreaterThan(0, strlen($input), 'Line:' . __LINE__ . ' The calendar method should return something without error.'); $xml = new SimpleXMLElement('<calendar>' . $input . '</calendar>'); $this->assertEquals('text', (string) $xml->div->input['type'], 'Line:' . __LINE__ . ' The calendar input should have `type == "text"`'); $this->assertEquals($data['friendly_date'], (string) $xml->div->input['title'], 'Line:' . __LINE__ . ' The calendar input should have `title == "' . $data['friendly_date'] . '"`'); $this->assertEquals($data['name'], (string) $xml->div->input['name'], 'Line:' . __LINE__ . ' The calendar input should have `name == "' . $data['name'] . '"`'); $this->assertEquals($data['id'], (string) $xml->div->input['id'], 'Line:' . __LINE__ . ' The calendar input should have `id == "' . $data['id'] . '"`'); $this->assertEquals($data['formattedDate'], (string) $xml->div->input['value'], 'Line:' . __LINE__ . ' The calendar input should have `value == "' . $data['formattedDate'] . '"`'); if (isset($data['attribs']['readonly']) && $data['attribs']['readonly'] === 'readonly') { $this->assertEquals($data['attribs']['readonly'], (string) $xml->div->input['readonly'], 'Line:' . __LINE__ . ' The readonly calendar input should have `readonly == "' . $data['attribs']['readonly'] . '"`'); $this->assertTrue(isset($xml->div->button['style']), 'Line:' . __LINE__ . ' The calendar input should not have a visible button'); $this->assertArrayNotHasKey('/media/system/js/calendar.js', JFactory::getDocument()->_scripts, 'Line:' . __LINE__ . ' JS file "calendar.js" shouldn\'t be loaded'); $this->assertArrayNotHasKey('/media/system/js/calendar-setup.js', JFactory::getDocument()->_scripts, 'Line:' . __LINE__ . ' JS file "calendar-setup.js" shouldn\'t be loaded'); $this->assertArrayNotHasKey('text/javascript', JFactory::getDocument()->_script, 'Line:' . __LINE__ . ' Inline JS for the calendar shouldn\'t be loaded'); } else { $this->assertFalse(isset($xml->div->input['readonly']), 'Line:' . __LINE__ . ' The calendar input shouldn\'t have readonly attribute'); $this->assertFalse(isset($xml->div->button['style']), 'Line:' . __LINE__ . ' The calendar input should visible button'); $this->assertEquals($data['id'] . '_img', (string) $xml->div->button['id'], 'Line:' . __LINE__ . ' The calendar button should have `id == "' . $data['id'] . '_img' . '"`'); $this->assertArrayHasKey('/media/system/js/calendar.js', JFactory::getDocument()->_scripts, 'Line:' . __LINE__ . ' JS file "calendar.js" should be loaded'); $this->assertArrayHasKey('/media/system/js/calendar-setup.js', JFactory::getDocument()->_scripts, 'Line:' . __LINE__ . ' JS file "calendar-setup.js" should be loaded'); $this->assertContains('jQuery(document).ready(function($) {Calendar.setup({', JFactory::getDocument()->_script['text/javascript'], 'Line:' . __LINE__ . ' Inline JS for the calendar should be loaded'); } } }
/** * Get a document object. * * Returns the global {@link JDocument} object, only creating it if it doesn't already exist. * * @return JDocument object * * @see JDocument * @since 11.1 */ public static function getDocument() { if (!self::$document) { self::$document = self::createDocument(); } return self::$document; }
/** * Setup for testing. * * @return void * * @since 11.3 */ public function setUp() { parent::setUp(); $this->saveFactoryState(); JFactory::$document = $this->getMockDocument(); JFactory::$language = $this->getMockLanguage(); $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'; // Get a new JApplicationWebInspector instance. $this->class = new JApplicationWebInspector(); }
/** * Allows the application to load a custom or default document. * * The logic and options for creating this object are adequately generic for default cases * but for many applications it will make sense to override this method and create a document, * if required, based on more specific needs. * * @param JDocument $document An optional document object. If omitted, the factory document is created. * * @return InstallationApplicationWeb This method is chainable. * * @since 3.2 */ public function loadDocument(JDocument $document = null) { if ($document === null) { $lang = JFactory::getLanguage(); $type = $this->input->get('format', 'html', 'word'); $attributes = array('charset' => 'utf-8', 'lineend' => 'unix', 'tab' => ' ', 'language' => $lang->getTag(), 'direction' => $lang->isRtl() ? 'rtl' : 'ltr'); $document = JDocument::getInstance($type, $attributes); // Register the instance to JFactory. JFactory::$document = $document; } $this->document = $document; return $this; }
/** * Method to send the application response to the client. All headers will be sent prior to the main * application output data. * * @return void * * @since 1.5 */ public function render() { $documentOptions = array('absoluteHrefs' => $this->options->get('absoluteHrefs', false), 'documentFormat' => 'json'); $body = $this->getBody(); JFactory::$document = new RApiPaymentDocumentDocument($documentOptions); $body = $this->triggerFunction('prepareBody', $body); // Push results into the document. JFactory::$document->setApiObject($this)->setBuffer($body)->render(false); }
/** * Method to send the application response to the client. All headers will be sent prior to the main * application output data. * * @return void * * @since 1.4 */ public function render() { $documentOptions = array('absoluteHrefs' => $this->options->get('absoluteHrefs', false), 'documentFormat' => 'xml'); if ($this->operation == 'wsdl') { // Needed for formatting $dom = dom_import_simplexml($this->wsdl)->ownerDocument; $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $body = $dom->saveXML(); } else { // Add error faults if they exist if ($this->webservice->statusCode >= 300) { // We must have status of 200 for SOAP communication even if it is fault $this->setStatusCode(200); $faultResponse = $this->prepareFaultResponseMessage($this->webservice); $body = RApiSoapHelper::createSoapFaultResponse($faultResponse); } else { $body = $this->getBody(); } } JFactory::$document = new RApiSoapDocumentDocument($documentOptions, $this->operation == 'wsdl' ? 'xml' : 'soap+xml'); $body = $this->triggerFunction('prepareBody', $body); // Push results into the document. JFactory::$document->setApiObject($this)->setBuffer($body)->render(false); }
/** * Tests JHtml::calendar() method with and without 'readonly' attribute. * * @return void * * @since 3.1 */ public function testCalendar() { // @TODO - Test currently failing, fix this later $this->markTestSkipped('Skipping failing test'); $cfg = new JObject(); JFactory::$session = $this->getMockSession(); JFactory::$config = $cfg; JFactory::$application->expects($this->any())->method('getTemplate')->will($this->returnValue('atomic')); $cfg->live_site = 'http://example.com'; $cfg->offset = 'Europe/Kiev'; // 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->assertGreaterThan(strlen($input), 0, 'Line:' . __LINE__ . ' The calendar method should return something without error.'); $xml = new SimpleXMLElement('<calendar>' . $input . '</calendar>'); $this->assertEquals('text', (string) $xml->input['type'], 'Line:' . __LINE__ . ' The calendar input should have `type == "text"`'); // @todo We can't test this yet due to dependency on language strings $this->assertEquals($data['friendly_date'], (string) $xml->input['title'], 'Line:' . __LINE__ . ' The calendar input should have `title == "' . $data['friendly_date'] . '"`'); $this->assertEquals($data['name'], (string) $xml->input['name'], 'Line:' . __LINE__ . ' The calendar input should have `name == "' . $data['name'] . '"`'); $this->assertEquals($data['id'], (string) $xml->input['id'], 'Line:' . __LINE__ . ' The calendar input should have `id == "' . $data['id'] . '"`'); $this->assertEquals($data['date'], (string) $xml->input['value'], '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($data['attribs']['readonly'], (string) $xml->input['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($data['id'] . '_img', (string) $xml->img['id'], 'Line:' . __LINE__ . ' The calendar image should have `id == "' . $data['id'] . '_img' . '"`'); $this->assertEquals('calendar', (string) $xml->img['class'], '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'); } } }
/** * Dispatch the application * * @param string $component The component which is being rendered. * * @return void * * @since 3.2 */ public function dispatch($component = null) { // Get the component if not set. if (!$component) { $component = $this->input->getCmd('option', null); } // Load the document to the API $this->loadDocument(); // Set up the params $document = $this->getDocument(); $router = static::getRouter(); $params = $this->getParams(); // Register the document object with JFactory JFactory::$document = $document; switch ($document->getType()) { case 'html': // Get language $lang_code = $this->getLanguage()->getTag(); $languages = JLanguageHelper::getLanguages('lang_code'); // Set metadata if (isset($languages[$lang_code]) && $languages[$lang_code]->metakey) { $document->setMetaData('keywords', $languages[$lang_code]->metakey); } else { $document->setMetaData('keywords', $this->get('MetaKeys')); } $document->setMetaData('rights', $this->get('MetaRights')); if ($router->getMode() == JROUTER_MODE_SEF) { $document->setBase(htmlspecialchars(JUri::current())); } // Get the template $template = $this->getTemplate(true); // Store the template and its params to the config $this->set('theme', $template->template); $this->set('themeParams', $template->params); break; case 'feed': $document->setBase(htmlspecialchars(JUri::current())); break; } $document->setTitle($params->get('page_title')); $document->setDescription($params->get('page_description')); // Add version number or not based on global configuration if ($this->get('MetaVersion', 0)) { $document->setGenerator('Joomla! - Open Source Content Management - Version ' . JVERSION); } else { $document->setGenerator('Joomla! - Open Source Content Management'); } $contents = JComponentHelper::renderComponent($component); $document->setBuffer($contents, 'component'); // Trigger the onAfterDispatch event. JPluginHelper::importPlugin('system'); $this->triggerEvent('onAfterDispatch'); }
/** * Method to send the application response to the client. All headers will be sent prior to the main * application output data. * * @return void * * @since 1.2 */ public function render() { // Set token to uri if used in that way $token = $this->options->get('accessToken', ''); $client = $this->options->get('webserviceClient', ''); $format = $this->options->get('format', 'json'); if (!empty($token)) { $this->setUriParams(RBootstrap::getConfig('oauth2_token_param_name', 'access_token'), $token); } if ($client == 'administrator') { $this->setUriParams('webserviceClient', $client); } $this->setUriParams('api', 'Hal'); if ($format == 'doc') { // This is already in HTML format echo $this->documentation; } else { $documentOptions = array('absoluteHrefs' => $this->options->get('absoluteHrefs', false), 'documentFormat' => $format, 'uriParams' => $this->uriParams); JFactory::$document = new RApiHalDocumentDocument($documentOptions); $body = $this->getBody(); $body = $this->triggerFunction('prepareBody', $body); // Push results into the document. JFactory::$document->setHal($this)->setBuffer($body)->render(false); } }
/** * Method to test backbone(). * * @return void * * @covers Windwalker\Script\CoreScript::backbone */ public function testBackbone() { $bakDoc = \JFactory::getDocument(); \JFactory::$document = $this->doc; TestHelper::setValue('JHtmlJquery', 'loaded', array()); CoreScript::backbone(false); $url = \JUri::root(true) . '/libraries/windwalker/resource/asset/js/core/backbone.js'; $this->assertEquals($url, $this->doc->getLastScript()); $this->assertEquals(5, count($this->doc->_scripts)); $js = <<<JS ; _.templateSettings = { interpolate: /\\{\\{(.+?)\\}\\}/g };; ; var underscore = _.noConflict();; JS; $this->assertStringDataEquals($js, $this->doc->_script['text/javascript']); CoreScript::backbone(true); $url = \JUri::root(true) . '/libraries/windwalker/resource/asset/js/core/backbone.js'; $this->assertEquals($url, $this->doc->getLastScript()); $this->assertEquals(5, count($this->doc->_scripts)); $js = <<<JS ; _.templateSettings = { interpolate: /\\{\\{(.+?)\\}\\}/g };; ; var underscore = _.noConflict();; ; var backbone = Backbone.noConflict();; JS; $this->assertStringDataEquals($js, $this->doc->_script['text/javascript']); \JFactory::$document = $bakDoc; }
/** * Get a document object. * * Returns the global {@link JDocument} object, only creating it if it doesn't already exist. * * @return JDocument object * * @see JDocument * @since 11.1 */ public static function getDocument() { if (class_exists('\\App')) { if (\App::has('document')) { return \App::get('document'); } } if (!self::$document) { self::$document = self::createDocument(); } return self::$document; }
/** * Get a document object * * Returns the global {@link JDocument} object, only creating it * if it doesn't already exist. * * @return object JDocument */ public static function getDocument() { if (!is_object(JFactory::$document)) { JFactory::$document = JFactory::_createDocument(); } return JFactory::$document; }