silverstripe-cms/tests/php/Tasks/MigrateSiteTreeLinkingTaskTest.php

86 lines
2.9 KiB
PHP
Raw Normal View History

<?php
2017-08-09 14:53:38 +12:00
namespace SilverStripe\CMS\Tests\Tasks;
2017-08-09 13:25:12 +12:00
2017-08-09 14:53:38 +12:00
use SilverStripe\CMS\Model\SiteTree;
2016-08-10 16:08:39 +12:00
use SilverStripe\CMS\Tasks\MigrateSiteTreeLinkingTask;
use SilverStripe\Dev\SapphireTest;
2017-08-09 14:53:38 +12:00
use SilverStripe\ORM\DataObject;
2017-01-26 09:59:25 +13:00
class MigrateSiteTreeLinkingTaskTest extends SapphireTest
{
protected static $fixture_file = 'MigrateSiteTreeLinkingTaskTest.yml';
2016-03-09 09:50:55 +13:00
2017-01-26 09:59:25 +13:00
protected static $use_draft_site = true;
2016-03-09 09:50:55 +13:00
2017-01-26 09:59:25 +13:00
public function testLinkingMigration()
{
ob_start();
2016-03-09 09:50:55 +13:00
2017-01-26 09:59:25 +13:00
$task = new MigrateSiteTreeLinkingTask();
$task->run(null);
2016-03-09 09:50:55 +13:00
2017-01-26 09:59:25 +13: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-09 09:50:55 +13:00
2017-08-09 14:53:38 +12: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-09 09:50:55 +13:00
2017-01-26 09:59:25 +13: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-09 09:50:55 +13:00
2017-01-26 09:59:25 +13:00
$this->assertEquals(
$homeContent,
2017-08-09 14:53:38 +12:00
DataObject::get_by_id(SiteTree::class, $homeID)->Content,
2017-01-26 09:59:25 +13:00
'HTML URLSegment links are rewritten.'
);
$this->assertEquals(
$aboutContent,
2017-08-09 14:53:38 +12:00
DataObject::get_by_id(SiteTree::class, $aboutID)->Content
2017-01-26 09:59:25 +13:00
);
$this->assertEquals(
$staffContent,
2017-08-09 14:53:38 +12:00
DataObject::get_by_id(SiteTree::class, $staffID)->Content
2017-01-26 09:59:25 +13:00
);
$this->assertEquals(
$actionContent,
2017-08-09 14:53:38 +12:00
DataObject::get_by_id(SiteTree::class, $actionID)->Content,
2017-01-26 09:59:25 +13:00
'Links to actions on pages are rewritten correctly.'
);
$this->assertEquals(
$hashLinkContent,
2017-08-09 14:53:38 +12:00
DataObject::get_by_id(SiteTree::class, $hashID)->Content,
2017-01-26 09:59:25 +13:00
'Hash/anchor links are correctly handled.'
);
}
}