silverstripe-cms/tests/tasks/MigrateSiteTreeLinkingTaskTest.php

88 lines
2.6 KiB
PHP
Raw Normal View History

<?php
use SilverStripe\ORM\DataObject;
2016-08-10 06:08:39 +02:00
use SilverStripe\CMS\Tasks\MigrateSiteTreeLinkingTask;
use SilverStripe\Dev\SapphireTest;
2016-08-10 06:08:39 +02:00
/**
* @package cms
* @subpackage tests
*/
class MigrateSiteTreeLinkingTaskTest extends SapphireTest {
2016-03-08 21:50:55 +01:00
protected static $fixture_file = 'MigrateSiteTreeLinkingTaskTest.yml';
2016-03-08 21:50:55 +01:00
protected static $use_draft_site = true;
2016-03-08 21:50:55 +01:00
public function testLinkingMigration() {
ob_start();
2016-03-08 21:50:55 +01:00
$task = new MigrateSiteTreeLinkingTask();
$task->run(null);
2016-03-08 21:50:55 +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
2016-07-22 01:32:32 +02:00
$homeID = $this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'home');
$aboutID = $this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'about');
$staffID = $this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'staff');
$actionID = $this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'action');
$hashID = $this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'hash_link');
2016-03-08 21:50:55 +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
$this->assertEquals (
$homeContent,
2016-07-22 01:32:32 +02:00
DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $homeID)->Content,
'HTML URLSegment links are rewritten.'
);
$this->assertEquals (
$aboutContent,
2016-07-22 01:32:32 +02:00
DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $aboutID)->Content
);
$this->assertEquals (
$staffContent,
2016-07-22 01:32:32 +02:00
DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $staffID)->Content
);
$this->assertEquals (
$actionContent,
2016-07-22 01:32:32 +02:00
DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $actionID)->Content,
'Links to actions on pages are rewritten correctly.'
);
$this->assertEquals (
$hashLinkContent,
2016-07-22 01:32:32 +02:00
DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $hashID)->Content,
'Hash/anchor links are correctly handled.'
);
}
2016-03-08 21:50:55 +01:00
}