2011-03-18 04:37:22 +01:00
|
|
|
<?php
|
2016-06-16 06:57:19 +02:00
|
|
|
|
2017-08-09 04:53:38 +02:00
|
|
|
namespace SilverStripe\CMS\Tests\Tasks;
|
2017-08-09 03:25:12 +02:00
|
|
|
|
2017-08-09 04:53:38 +02:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
2016-08-10 06:08:39 +02:00
|
|
|
use SilverStripe\CMS\Tasks\MigrateSiteTreeLinkingTask;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2017-08-09 04:53:38 +02:00
|
|
|
use SilverStripe\ORM\DataObject;
|
2016-08-23 04:36:06 +02:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
class MigrateSiteTreeLinkingTaskTest extends SapphireTest
|
|
|
|
{
|
|
|
|
protected static $fixture_file = 'MigrateSiteTreeLinkingTaskTest.yml';
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
protected static $use_draft_site = true;
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
public function testLinkingMigration()
|
|
|
|
{
|
|
|
|
ob_start();
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
$task = new MigrateSiteTreeLinkingTask();
|
|
|
|
$task->run(null);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2017-01-25 21:59:25 +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
|
|
|
|
2017-08-09 04:53:38 +02:00
|
|
|
$homeID = $this->idFromFixture(SiteTree::class, 'home');
|
|
|
|
$aboutID = $this->idFromFixture(SiteTree::class, 'about');
|
|
|
|
$staffID = $this->idFromFixture(SiteTree::class, 'staff');
|
|
|
|
$actionID = $this->idFromFixture(SiteTree::class, 'action');
|
|
|
|
$hashID = $this->idFromFixture(SiteTree::class, 'hash_link');
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
$homeContent = sprintf(
|
|
|
|
'<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>',
|
|
|
|
$aboutID,
|
|
|
|
$staffID
|
|
|
|
);
|
|
|
|
$aboutContent = sprintf(
|
|
|
|
'<a href="[sitetree_link,id=%d]">Home</a><a href="[sitetree_link,id=%d]">Staff</a><a name="second-anchor"></a>',
|
|
|
|
$homeID,
|
|
|
|
$staffID
|
|
|
|
);
|
|
|
|
$staffContent = sprintf(
|
|
|
|
'<a href="[sitetree_link,id=%d]">Home</a><a href="[sitetree_link,id=%d]">About</a>',
|
|
|
|
$homeID,
|
|
|
|
$aboutID
|
|
|
|
);
|
|
|
|
$actionContent = sprintf(
|
|
|
|
'<a href="[sitetree_link,id=%d]SearchForm">Search Form</a>',
|
|
|
|
$homeID
|
|
|
|
);
|
|
|
|
$hashLinkContent = sprintf(
|
|
|
|
'<a href="[sitetree_link,id=%d]#anchor">Home</a><a href="[sitetree_link,id=%d]#second-anchor">About</a>',
|
|
|
|
$homeID,
|
|
|
|
$aboutID
|
|
|
|
);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
$homeContent,
|
2017-08-09 04:53:38 +02:00
|
|
|
DataObject::get_by_id(SiteTree::class, $homeID)->Content,
|
2017-01-25 21:59:25 +01:00
|
|
|
'HTML URLSegment links are rewritten.'
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
$aboutContent,
|
2017-08-09 04:53:38 +02:00
|
|
|
DataObject::get_by_id(SiteTree::class, $aboutID)->Content
|
2017-01-25 21:59:25 +01:00
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
$staffContent,
|
2017-08-09 04:53:38 +02:00
|
|
|
DataObject::get_by_id(SiteTree::class, $staffID)->Content
|
2017-01-25 21:59:25 +01:00
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
$actionContent,
|
2017-08-09 04:53:38 +02:00
|
|
|
DataObject::get_by_id(SiteTree::class, $actionID)->Content,
|
2017-01-25 21:59:25 +01:00
|
|
|
'Links to actions on pages are rewritten correctly.'
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
$hashLinkContent,
|
2017-08-09 04:53:38 +02:00
|
|
|
DataObject::get_by_id(SiteTree::class, $hashID)->Content,
|
2017-01-25 21:59:25 +01:00
|
|
|
'Hash/anchor links are correctly handled.'
|
|
|
|
);
|
|
|
|
}
|
2012-04-12 09:23:20 +02:00
|
|
|
}
|