Merge pull request #308 from wernerkrauss/feature-alternateabsolutelink-action

alternateAbsoluteLink() respects action parameter
This commit is contained in:
Daniel Hensby 2017-09-08 12:13:33 +01:00 committed by GitHub
commit 60b259ebb5
3 changed files with 40 additions and 8 deletions

View File

@ -27,11 +27,11 @@ before_script:
- phpenv rehash - phpenv rehash
- phpenv config-rm xdebug.ini - phpenv config-rm xdebug.ini
- echo 'memory_limit = 2G' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - echo 'memory_limit = 2G' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- composer validate
- composer install --prefer-dist - composer require silverstripe/recipe-cms 1.0.x-dev --no-update
- composer require silverstripe/recipe-cms 1.0.x-dev --no-update --prefer-dist - if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.0.x-dev; fi
- if [[ $DB == PGSQL ]]; then composer require --prefer-dist --no-update silverstripe/postgresql:2.0.x-dev; fi - composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
- composer update - echo "SS_BASE_URL=http://localhost:8080/" >> .env
# Bootstrap cms / mysite folder # Bootstrap cms / mysite folder
- php ./cms/tests/bootstrap/mysite.php - php ./cms/tests/bootstrap/mysite.php

View File

@ -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. // Generate the existing absolute URL and replace the domain with the subsite domain.
// This helps deal with Link() returning an absolute URL. // 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) { if ($this->owner->SubsiteID) {
$url = preg_replace('/\/\/[^\/]+\//', '//' . $this->owner->Subsite()->domain() . '/', $url); $url = preg_replace('/\/\/[^\/]+\//', '//' . $this->owner->Subsite()->domain() . '/', $url);
} }

View File

@ -3,7 +3,6 @@
namespace SilverStripe\Subsites\Tests; namespace SilverStripe\Subsites\Tests;
use Page; use Page;
use SilverStripe\Assets\FileNameFilter;
use SilverStripe\CMS\Controllers\CMSMain; use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\CMS\Controllers\ModelAsController; use SilverStripe\CMS\Controllers\ModelAsController;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
@ -399,4 +398,33 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
'Themes should be modified when Subsite has theme defined' '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);
}
} }