diff --git a/.travis.yml b/.travis.yml index 15337f0..d417249 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,11 +27,11 @@ before_script: - phpenv rehash - phpenv config-rm xdebug.ini - echo 'memory_limit = 2G' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - - - composer install --prefer-dist - - composer require silverstripe/recipe-cms 1.0.x-dev --no-update --prefer-dist - - if [[ $DB == PGSQL ]]; then composer require --prefer-dist --no-update silverstripe/postgresql:2.0.x-dev; fi - - composer update + - composer validate + - composer require silverstripe/recipe-cms 1.0.x-dev --no-update + - if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.0.x-dev; fi + - composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile + - echo "SS_BASE_URL=http://localhost:8080/" >> .env # Bootstrap cms / mysite folder - php ./cms/tests/bootstrap/mysite.php diff --git a/code/extensions/SiteTreeSubsites.php b/code/extensions/SiteTreeSubsites.php index abfbd2e..7df6d24 100644 --- a/code/extensions/SiteTreeSubsites.php +++ b/code/extensions/SiteTreeSubsites.php @@ -347,11 +347,15 @@ class SiteTreeSubsites extends DataExtension } } - public function alternateAbsoluteLink() + /** + * @param null $action + * @return string + */ + public function alternateAbsoluteLink($action = null) { // Generate the existing absolute URL and replace the domain with the subsite domain. // This helps deal with Link() returning an absolute URL. - $url = Director::absoluteURL($this->owner->Link()); + $url = Director::absoluteURL($this->owner->Link($action)); if ($this->owner->SubsiteID) { $url = preg_replace('/\/\/[^\/]+\//', '//' . $this->owner->Subsite()->domain() . '/', $url); } diff --git a/tests/php/SiteTreeSubsitesTest.php b/tests/php/SiteTreeSubsitesTest.php index b72ceb0..0366f8c 100644 --- a/tests/php/SiteTreeSubsitesTest.php +++ b/tests/php/SiteTreeSubsitesTest.php @@ -3,7 +3,6 @@ namespace SilverStripe\Subsites\Tests; use Page; -use SilverStripe\Assets\FileNameFilter; use SilverStripe\CMS\Controllers\CMSMain; use SilverStripe\CMS\Controllers\ModelAsController; use SilverStripe\CMS\Model\SiteTree; @@ -399,4 +398,33 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest 'Themes should be modified when Subsite has theme defined' ); } + + protected function provideAlternateAbsoluteLink() + { + return [ + ['home', null, 'http://localhost/'], + ['home', 'myaction', 'http://localhost/home/myaction'], + ['contact', null, 'http://localhost/contact-us/'], + ['contact', 'myaction', 'http://localhost/contact-us/myaction'], + ['subsite1_home', null, 'http://subsite1.localhost/'], + ['subsite1_home', 'myaction', 'http://subsite1.localhost/home/myaction'], + ['subsite1_contactus', null, 'http://subsite1.localhost/contact-us/'], + ['subsite1_contactus', 'myaction', 'http://subsite1.localhost/contact-us/myaction'] + ]; + } + + /** + * @dataProvider provideAlternateAbsoluteLink + * @param $fixture + * @param $expected + */ + public function testAlternateAbsoluteLink($pageFixtureName, $action, $expectedAbsoluteLink) + { + /** @var Page $page */ + $page = $this->objFromFixture('Page', $pageFixtureName); + + $result = $page->AbsoluteLink($action); + + $this->assertEquals($expectedAbsoluteLink, $result); + } }