/** * Test... * * @todo Implement testRender(). * * @return void */ public function testRender() { $this->object = new JDocumentRaw; JResponse::clearHeaders(); $this->object->setBuffer('Unit Test Buffer'); $this->assertThat( $this->object->render(), $this->equalTo('Unit Test Buffer') ); $headers = JResponse::getHeaders(); foreach ($headers as $head) { if ($head['name'] == 'Expires') { $this->assertThat( $head['value'], $this->stringContains('GMT') ); } } }
/** * Test Render * * @todo Implement testRender(). * * @return void */ public function testRender() { JResponse::clearHeaders(); $this->object->setBuffer('Unit Test Buffer'); $this->assertThat($this->object->render(), $this->equalTo('Unit Test Buffer'), 'We did not get the buffer back properly'); $headers = JResponse::getHeaders(); $disposition = false; foreach ($headers as $head) { if ($head['name'] == 'Content-disposition') { $this->assertThat($head['value'], $this->stringContains('.xml'), 'The content disposition did not include json extension'); $disposition = true; } } $this->assertThat($disposition, $this->equalTo(true), 'No Content-disposition headers'); }
/** * Test... * * @todo Implement testRender(). * * @return void */ public function testRender() { JResponse::clearHeaders(); JResponse::allowCache(true); $this->object->setBuffer('Unit Test Buffer'); $this->assertThat( $this->object->render(), $this->equalTo('Unit Test Buffer'), 'We did not get the buffer back properly' ); $headers = JResponse::getHeaders(); $expires = false; $disposition = false; foreach ($headers as $head) { if ($head['name'] == 'Expires') { $this->assertThat( $head['value'], $this->stringContains('GMT'), 'The expires header was not set properly (was parent::render called?)' ); $expires = true; } if ($head['name'] == 'Content-disposition') { $this->assertThat( $head['value'], $this->stringContains('.json'), 'The content disposition did not include json extension' ); $disposition = true; } } $this->assertThat( JResponse::allowCache(), $this->isFalse(), 'Caching was not disabled' ); }
protected static function _createShurl($nonSefUrl) { if (empty($nonSefUrl)) { return ''; } // only create a shURL if current page returns a 200 $headers = JResponse::getHeaders(); // check if we have a status foreach ($headers as $header) { if (strtolower($header['name']) == 'status' && $header['value'] != 200) { // error or redirection, don't shurl that return ''; } } // check various conditions, to avoid overloading ourselves with shURL // not on homepage if (shIsHomepage($nonSefUrl)) { return ''; } // not for format = raw, format = pdf or printing $format = shGetURLVar($nonSefUrl, 'format'); if (in_array(strtolower($format), array('raw', 'pdf'))) { return ''; } $print = shGetURLVar($nonSefUrl, 'print'); if ($print == 1) { return ''; } // not if tmpl not empty or not index $tmpl = shGetURLVar($nonSefUrl, 'tmpl'); if (!empty($tmpl) && $tmpl != 'index') { return ''; } // force global setting shMustCreatePageId('set', true); // get a model and create shURL $model =& JModel::getInstance('Pageids', 'Sh404sefModel'); $shURL = $model->createPageId('', $nonSefUrl); return $shURL; }
/** * Set the disposition to inline for JSON requests */ public function onAfterRender() { if (JFactory::getDocument()->getType() !== 'json') { return; } $headers = JResponse::getHeaders(); foreach ($headers as $key => $header) { if ($header['name'] === 'Content-disposition') { $string = $header['value']; if (strpos($string, 'attachment; ') !== false) { $string = str_replace($string, 'attachment; ', 'inline; '); JResponse::setHeader('Content-disposition', $string, true); break; } } } }
/** * Test... * * @covers JDocument::render * * @return void */ public function testRender() { $this->object = new JDocument; $this->object->render(); $headers = JResponse::getHeaders(); $lastMod = false; $contentType = false; foreach ($headers as $header) { if ($header['name'] == 'Last-Modified') { $lastMod = $header; } if ($header['name'] == 'Content-Type') { $contentType = $header; } } $this->assertThat( $lastMod, $this->equalTo(false) ); $this->assertThat( $contentType['value'], $this->equalTo('; charset=utf-8') ); $this->object->setModifiedDate('My date'); $this->object->setMimeEncoding('MyMimeType'); $this->object->setCharset('MyCharset'); $this->object->render(); $headers = JResponse::getHeaders(); $lastMod = false; $contentType = false; foreach ($headers as $header) { if ($header['name'] == 'Last-Modified') { $lastMod = $header; } if ($header['name'] == 'Content-Type') { $contentType = $header; } } $this->assertThat( $lastMod['value'], $this->equalTo('My date') ); $this->assertThat( $contentType['value'], $this->equalTo('mymimetype; charset=MyCharset') ); }
/** * Test... * * @return void */ public function testClearHeaders() { JResponse::setHeader('somename', 'somevalue'); JResponse::clearHeaders(); $this->assertThat(count(JResponse::getHeaders()), $this->equalTo(0)); }
static function onAfterRenderLast() { if (!defined('_MJ')) { return; } $MobileJoomla_Settings =& MobileJoomla::getConfig(); if ($MobileJoomla_Settings['httpcaching']) { JResponse::allowCache(true); JResponse::setHeader('Vary', 'Cookie'); } JResponse::setHeader('Cache-Control', 'no-transform'); //remove Content-Type duplicates $headers = JResponse::getHeaders(); JResponse::clearHeaders(); $found = false; foreach ($headers as $header) { if (strtolower($header['name']) != 'content-type') { JResponse::setHeader($header['name'], $header['value']); } elseif (!$found) { JResponse::setHeader($header['name'], $header['value']); $found = true; } } }
/** * Create workarounded data to be cached * * @param string $data Cached data * @param array $options Array of options * * @return string Data to be cached * * @since 11.1 */ public static function setWorkarounds($data, $options = array()) { $loptions = array('nopathway' => 0, 'nohead' => 0, 'nomodules' => 0, 'modulemode' => 0); if (isset($options['nopathway'])) { $loptions['nopathway'] = $options['nopathway']; } if (isset($options['nohead'])) { $loptions['nohead'] = $options['nohead']; } if (isset($options['nomodules'])) { $loptions['nomodules'] = $options['nomodules']; } if (isset($options['modulemode'])) { $loptions['modulemode'] = $options['modulemode']; } $app = JFactory::getApplication(); $document = JFactory::getDocument(); if ($loptions['nomodules'] != 1) { // Get the modules buffer before component execution. $buffer1 = $document->getBuffer(); if (!is_array($buffer1)) { $buffer1 = array(); } // Make sure the module buffer is an array. if (!isset($buffer1['module']) || !is_array($buffer1['module'])) { $buffer1['module'] = array(); } } // View body data $cached['body'] = $data; // Document head data if ($loptions['nohead'] != 1 && method_exists($document, 'getHeadData')) { if ($loptions['modulemode'] == 1) { $headnow = $document->getHeadData(); $unset = array('title', 'description', 'link', 'links', 'metaTags'); foreach ($unset as $un) { unset($headnow[$un]); unset($options['headerbefore'][$un]); } $cached['head'] = array(); // Only store what this module has added foreach ($headnow as $now => $value) { if (isset($options['headerbefore'][$now])) { // We have to serialize the content of the arrays because the may contain other arrays which is a notice in PHP 5.4 and newer $nowvalue = array_map('serialize', $headnow[$now]); $beforevalue = array_map('serialize', $options['headerbefore'][$now]); $newvalue = array_diff_assoc($nowvalue, $beforevalue); $newvalue = array_map('unserialize', $newvalue); } else { $newvalue = $headnow[$now]; } if (!empty($newvalue)) { $cached['head'][$now] = $newvalue; } } } else { $cached['head'] = $document->getHeadData(); } } // Pathway data if ($app->isSite() && $loptions['nopathway'] != 1) { $pathway = $app->getPathWay(); $cached['pathway'] = isset($data['pathway']) ? $data['pathway'] : $pathway->getPathway(); } if ($loptions['nomodules'] != 1) { // @todo Check if the following is needed, seems like it should be in page cache // Get the module buffer after component execution. $buffer2 = $document->getBuffer(); if (!is_array($buffer2)) { $buffer2 = array(); } // Make sure the module buffer is an array. if (!isset($buffer2['module']) || !is_array($buffer2['module'])) { $buffer2['module'] = array(); } // Compare the second module buffer against the first buffer. $cached['module'] = array_diff_assoc($buffer2['module'], $buffer1['module']); } // Headers data if (isset($options['headers']) && $options['headers']) { $cached['headers'] = JResponse::getHeaders(); } return $cached; }