2011-03-18 04:37:22 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2011-03-22 10:47:26 +01:00
|
|
|
* @package cms
|
2011-03-18 04:37:22 +01:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class MigrateSiteTreeLinkingTaskTest extends SapphireTest {
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
protected static $fixture_file = 'MigrateSiteTreeLinkingTaskTest.yml';
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
protected static $use_draft_site = true;
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:37:22 +01:00
|
|
|
public function testLinkingMigration() {
|
|
|
|
ob_start();
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:37:22 +01:00
|
|
|
$task = new MigrateSiteTreeLinkingTask();
|
|
|
|
$task->run(null);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:37:22 +01:00
|
|
|
$this->assertEquals (
|
|
|
|
"Rewrote 9 link(s) on 5 page(s) to use shortcodes.\n",
|
|
|
|
ob_get_contents(),
|
|
|
|
'Rewritten links are correctly reported'
|
|
|
|
);
|
|
|
|
ob_end_clean();
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:37:22 +01:00
|
|
|
$homeID = $this->idFromFixture('SiteTree', 'home');
|
|
|
|
$aboutID = $this->idFromFixture('SiteTree', 'about');
|
|
|
|
$staffID = $this->idFromFixture('SiteTree', 'staff');
|
|
|
|
$actionID = $this->idFromFixture('SiteTree', 'action');
|
|
|
|
$hashID = $this->idFromFixture('SiteTree', 'hash_link');
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:37:22 +01:00
|
|
|
$homeContent = sprintf (
|
2014-08-15 02:04:48 +02:00
|
|
|
'<a href="[sitetree_link,id=%d]">About</a><a href="[sitetree_link,id=%d]">Staff</a><a href="http://silverstripe.org/">External Link</a><a name="anchor"></a>',
|
2011-03-18 04:37:22 +01:00
|
|
|
$aboutID,
|
|
|
|
$staffID
|
|
|
|
);
|
|
|
|
$aboutContent = sprintf (
|
2014-08-15 02:04:48 +02:00
|
|
|
'<a href="[sitetree_link,id=%d]">Home</a><a href="[sitetree_link,id=%d]">Staff</a><a name="second-anchor"></a>',
|
2011-03-18 04:37:22 +01:00
|
|
|
$homeID,
|
|
|
|
$staffID
|
|
|
|
);
|
|
|
|
$staffContent = sprintf (
|
2012-07-12 04:51:19 +02:00
|
|
|
'<a href="[sitetree_link,id=%d]">Home</a><a href="[sitetree_link,id=%d]">About</a>',
|
2011-03-18 04:37:22 +01:00
|
|
|
$homeID,
|
|
|
|
$aboutID
|
|
|
|
);
|
|
|
|
$actionContent = sprintf (
|
2012-07-12 04:51:19 +02:00
|
|
|
'<a href="[sitetree_link,id=%d]SearchForm">Search Form</a>', $homeID
|
2011-03-18 04:37:22 +01:00
|
|
|
);
|
|
|
|
$hashLinkContent = sprintf (
|
2012-07-12 04:51:19 +02:00
|
|
|
'<a href="[sitetree_link,id=%d]#anchor">Home</a><a href="[sitetree_link,id=%d]#second-anchor">About</a>',
|
2011-03-18 04:37:22 +01:00
|
|
|
$homeID,
|
|
|
|
$aboutID
|
|
|
|
);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:37:22 +01:00
|
|
|
$this->assertEquals (
|
|
|
|
$homeContent,
|
|
|
|
DataObject::get_by_id('SiteTree', $homeID)->Content,
|
|
|
|
'HTML URLSegment links are rewritten.'
|
|
|
|
);
|
|
|
|
$this->assertEquals (
|
2016-01-06 00:42:07 +01:00
|
|
|
$aboutContent,
|
2011-03-18 04:37:22 +01:00
|
|
|
DataObject::get_by_id('SiteTree', $aboutID)->Content
|
|
|
|
);
|
|
|
|
$this->assertEquals (
|
|
|
|
$staffContent,
|
|
|
|
DataObject::get_by_id('SiteTree', $staffID)->Content
|
|
|
|
);
|
|
|
|
$this->assertEquals (
|
|
|
|
$actionContent,
|
|
|
|
DataObject::get_by_id('SiteTree', $actionID)->Content,
|
|
|
|
'Links to actions on pages are rewritten correctly.'
|
|
|
|
);
|
|
|
|
$this->assertEquals (
|
|
|
|
$hashLinkContent,
|
|
|
|
DataObject::get_by_id('SiteTree', $hashID)->Content,
|
|
|
|
'Hash/anchor links are correctly handled.'
|
|
|
|
);
|
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2012-04-12 09:23:20 +02:00
|
|
|
}
|