Skip to content
Browse files

Merge branch 'web' of https://github.com/LouisLandry/joomla-platform

…into web2
  • Loading branch information...
2 parents 7708c99 + 4065699 commit 056f0c8a3164d21f63b3f19ad5bb18a8a4fe55ae @eddieajau eddieajau committed Sep 20, 2011
View
46 libraries/joomla/application/web.php
@@ -1127,53 +1127,47 @@ protected function loadSession()
/**
* Method to load the system URI strings for the application.
*
+ * @param string $requestUri An optional request URI to use instead of detecting one from the
+ * server environment variables.
+ *
* @return void
*
* @since 11.3
*/
- protected function loadSystemUris()
+ protected function loadSystemUris($requestUri = null)
{
// Set the request URI.
- $this->set('uri.request', $this->detectRequestUri());
+ // @codeCoverageIgnoreStart
+ if (!empty($requestUri))
+ {
+ $this->set('uri.request', $requestUri);
+ }
+ else
+ {
+ $this->set('uri.request', $this->detectRequestUri());
+ }
+ // @codeCoverageIgnoreEnd
// Check to see if an explicit site URI has been set.
$siteUri = trim($this->get('site_uri'));
if ($siteUri != '')
{
- // Parse the site URI and set the host and path segments of the URI.
$uri = JUri::getInstance($siteUri);
-
- $host = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
- $path = rtrim($uri->toString(array('path')), '/\\');
}
-
- /*
- * No explicit site URL was set so we will do our best to determine the base URIs from
- * the requested URI and the server environment variables.
- */
+ // No explicit site URI was set so use the system one.
else
{
- // Parse the request URI to determine the base.
$uri = JUri::getInstance($this->get('uri.request'));
-
- $host = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
-
- // Apache CGI
- if (strpos(php_sapi_name(), 'cgi') !== false && !empty($_SERVER['REQUEST_URI']))
- {
- $path = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
- }
- // Others
- else
- {
- $path = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\');
- }
}
+ // Get the host and path from the URI.
+ $host = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
+ $path = rtrim($uri->toString(array('path')), '/\\');
+
// Set the base URI both as just a path and as the full URI.
$this->set('uri.base.full', $host . $path . '/');
$this->set('uri.base.host', $host);
- $this->set('uri.base.path', $path);
+ $this->set('uri.base.path', $path . '/');
// Get an explicitly set media URI is present.
$mediaURI = trim($this->get('media_uri'));
View
232 tests/suite/joomla/application/JWebTest.php
@@ -965,7 +965,63 @@ public function testInitialiseWithFalse()
*/
public function testInitialiseWithInjection()
{
- $this->markTestIncomplete();
+ $mockSession = $this->getMock('JSession', array('test'), array(), '', false);
+ $mockSession
+ ->expects($this->any())
+ ->method('test')
+ ->will(
+ $this->returnValue('JSession')
+ );
+
+ $mockDocument = $this->getMock('JDocument', array('test'), array(), '', false);
+ $mockDocument
+ ->expects($this->any())
+ ->method('test')
+ ->will(
+ $this->returnValue('JDocument')
+ );
+
+ $mockLanguage = $this->getMock('JLanguage', array('test'), array(), '', false);
+ $mockLanguage
+ ->expects($this->any())
+ ->method('test')
+ ->will(
+ $this->returnValue('JLanguage')
+ );
+
+ $mockDispatcher = $this->getMock('JDispatcher', array('test'), array(), '', false);
+ $mockDispatcher
+ ->expects($this->any())
+ ->method('test')
+ ->will(
+ $this->returnValue('JDispatcher')
+ );
+
+ $this->inspector->initialise($mockSession, $mockDocument, $mockLanguage, $mockDispatcher);
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('session')->test(),
+ $this->equalTo('JSession'),
+ 'Tests session injection.'
+ );
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('document')->test(),
+ $this->equalTo('JDocument'),
+ 'Tests document injection.'
+ );
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('language')->test(),
+ $this->equalTo('JLanguage'),
+ 'Tests language injection.'
+ );
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('dispatcher')->test(),
+ $this->equalTo('JDispatcher'),
+ 'Tests dispatcher injection.'
+ );
}
/**
@@ -1085,9 +1141,179 @@ public function testLoadSession()
*
* @since 11.3
*/
- public function testLoadSystemUris()
+ public function testLoadSystemUrisWithSiteUriSet()
{
- $this->markTestIncomplete();
+ // Set the site_uri value in the configuration.
+ $config = new JRegistry(array('site_uri' => 'http://test.joomla.org/path/'));
+ $this->inspector->setClassProperty('config', $config);
+
+ $this->inspector->loadSystemUris();
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.base.full'),
+ $this->equalTo('http://test.joomla.org/path/'),
+ 'Checks the full base uri.'
+ );
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.base.host'),
+ $this->equalTo('http://test.joomla.org'),
+ 'Checks the base uri host.'
+ );
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.base.path'),
+ $this->equalTo('/path/'),
+ 'Checks the base uri path.'
+ );
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.media.full'),
+ $this->equalTo('http://test.joomla.org/path/media/'),
+ 'Checks the full media uri.'
+ );
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.media.path'),
+ $this->equalTo('/path/media/'),
+ 'Checks the media uri path.'
+ );
+ }
+
+ /**
+ * Tests the JWeb::loadSystemUris method.
+ *
+ * @return void
+ *
+ * @since 11.3
+ */
+ public function testLoadSystemUrisWithoutSiteUriSet()
+ {
+ $this->inspector->loadSystemUris('http://joom.la/application');
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.base.full'),
+ $this->equalTo('http://joom.la/application/'),
+ 'Checks the full base uri.'
+ );
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.base.host'),
+ $this->equalTo('http://joom.la'),
+ 'Checks the base uri host.'
+ );
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.base.path'),
+ $this->equalTo('/application/'),
+ 'Checks the base uri path.'
+ );
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.media.full'),
+ $this->equalTo('http://joom.la/application/media/'),
+ 'Checks the full media uri.'
+ );
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.media.path'),
+ $this->equalTo('/application/media/'),
+ 'Checks the media uri path.'
+ );
+ }
+
+ /**
+ * Tests the JWeb::loadSystemUris method.
+ *
+ * @return void
+ *
+ * @since 11.3
+ */
+ public function testLoadSystemUrisWithoutSiteUriWithMediaUriSet()
+ {
+ // Set the media_uri value in the configuration.
+ $config = new JRegistry(array('media_uri' => 'http://cdn.joomla.org/media/'));
+ $this->inspector->setClassProperty('config', $config);
+
+ $this->inspector->loadSystemUris('http://joom.la/application');
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.base.full'),
+ $this->equalTo('http://joom.la/application/'),
+ 'Checks the full base uri.'
+ );
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.base.host'),
+ $this->equalTo('http://joom.la'),
+ 'Checks the base uri host.'
+ );
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.base.path'),
+ $this->equalTo('/application/'),
+ 'Checks the base uri path.'
+ );
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.media.full'),
+ $this->equalTo('http://cdn.joomla.org/media/'),
+ 'Checks the full media uri.'
+ );
+
+ // Since this is on a different domain we need the full url for this too.
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.media.path'),
+ $this->equalTo('http://cdn.joomla.org/media/'),
+ 'Checks the media uri path.'
+ );
+ }
+
+ /**
+ * Tests the JWeb::loadSystemUris method.
+ *
+ * @return void
+ *
+ * @since 11.3
+ */
+ public function testLoadSystemUrisWithoutSiteUriWithRelativeMediaUriSet()
+ {
+ // Set the media_uri value in the configuration.
+ $config = new JRegistry(array('media_uri' => '/media/'));
+ $this->inspector->setClassProperty('config', $config);
+
+ $this->inspector->loadSystemUris('http://joom.la/application');
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.base.full'),
+ $this->equalTo('http://joom.la/application/'),
+ 'Checks the full base uri.'
+ );
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.base.host'),
+ $this->equalTo('http://joom.la'),
+ 'Checks the base uri host.'
+ );
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.base.path'),
+ $this->equalTo('/application/'),
+ 'Checks the base uri path.'
+ );
+
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.media.full'),
+ $this->equalTo('http://joom.la/media/'),
+ 'Checks the full media uri.'
+ );
+
+ // Since this is on a different domain we need the full url for this too.
+ $this->assertThat(
+ $this->inspector->getClassProperty('config')->get('uri.media.path'),
+ $this->equalTo('/media/'),
+ 'Checks the media uri path.'
+ );
}
/**
View
7 tests/suite/joomla/application/TestStubs/JWeb_Inspector.php
@@ -255,13 +255,16 @@ public function loadSession()
/**
* Allows public access to protected method.
*
+ * @param string $requestUri An optional request URI to use instead of detecting one from the
+ * server environment variables.
+ *
* @return void
*
* @since 11.3
*/
- public function loadSystemUris()
+ public function loadSystemUris($requestUri = null)
{
- return parent::loadSystemUris();
+ return parent::loadSystemUris($requestUri);
}
/**

0 comments on commit 056f0c8

Please sign in to comment.
Something went wrong with that request. Please try again.