BUG Change all shortcodes into the new, comma separated, format.

Ref http://open.silverstripe.org/ticket/7337
This commit is contained in:
Mateusz Uzdowski 2012-07-12 14:51:19 +12:00 committed by Ingo Schommer
parent 8055fc2e7b
commit 54fd54a2fb
9 changed files with 28 additions and 28 deletions

View File

@ -366,7 +366,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
}
/**
* Replace a "[sitetree_link id=n]" shortcode with a link to the page with the corresponding ID.
* Replace a "[sitetree_link,id=n]" shortcode with a link to the page with the corresponding ID.
*
* @return string
*/

View File

@ -26,7 +26,7 @@ class MigrateSiteTreeLinkingTask extends BuildTask {
// TOOD: Replace in all HTMLText fields
$page->Content = preg_replace (
"/href *= *([\"']?){$linked->URLSegment}\/?/i",
"href=$1[sitetree_link id={$linked->ID}]",
"href=$1[sitetree_link,id={$linked->ID}]",
$page->Content,
-1,
$replaced

View File

@ -112,7 +112,7 @@ class ContentControllerTest extends FunctionalTest {
$page = new SiteTree();
$page->URLSegment = 'linking-page';
$page->Content = sprintf('<a href="[sitetree_link id=%s]">Testlink</a>', $linkedPage->ID);
$page->Content = sprintf('<a href="[sitetree_link,id=%s]">Testlink</a>', $linkedPage->ID);
$page->write();
$page->publish('Stage', 'Live');

View File

@ -36,7 +36,7 @@ class SiteTreeBacklinksTest extends SapphireTest {
$this->assertNotContains($page2->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 2 doesn\'t exist');
// add hyperlink to page 1 on page 2
$page2->Content .= '<p><a href="[sitetree_link id='.$page1->ID.']">Testing page 1 link</a></p>';
$page2->Content .= '<p><a href="[sitetree_link,id='.$page1->ID.']">Testing page 1 link</a></p>';
$page2->write();
// load page 1
@ -205,7 +205,7 @@ class SiteTreeBacklinksTest extends SapphireTest {
$this->assertNotContains($page2->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 2 doesn\'t exist');
// add hyperlink to page 1 on page 2
$page2->ExtraContent .= '<p><a href="[sitetree_link id='.$page1->ID.']">Testing page 1 link</a></p>';
$page2->ExtraContent .= '<p><a href="[sitetree_link,id='.$page1->ID.']">Testing page 1 link</a></p>';
$page2->write();
$page2->doPublish();

View File

@ -11,7 +11,7 @@ Page:
page3:
Title: page3
URLSegment: page3
Content: '<p><a href="[sitetree_link id=1]">Testing page 1 link</a></p>'
Content: '<p><a href="[sitetree_link,id=1]">Testing page 1 link</a></p>'
LinkTracking: =>Page.page1

View File

@ -21,11 +21,11 @@ class SiteTreeBrokenLinksTest extends SapphireTest {
function testBrokenLinksBetweenPages() {
$obj = $this->objFromFixture('Page','content');
$obj->Content = '<a href="[sitetree_link id=3423423]">this is a broken link</a>';
$obj->Content = '<a href="[sitetree_link,id=3423423]">this is a broken link</a>';
$obj->syncLinkTracking();
$this->assertTrue($obj->HasBrokenLink, 'Page has a broken link');
$obj->Content = '<a href="[sitetree_link id=' . $this->idFromFixture('Page','about') .']">this is not a broken link</a>';
$obj->Content = '<a href="[sitetree_link,id=' . $this->idFromFixture('Page','about') .']">this is not a broken link</a>';
$obj->syncLinkTracking();
$this->assertFalse($obj->HasBrokenLink, 'Page does NOT have a broken link');
}
@ -107,7 +107,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest {
$linkDest->doPublish();
$linkSrc = $this->objFromFixture('Page','content');
$linkSrc->Content = "<p><a href=\"[sitetree_link id=$linkDest->ID]\">about us</a></p>";
$linkSrc->Content = "<p><a href=\"[sitetree_link,id=$linkDest->ID]\">about us</a></p>";
$linkSrc->write();
$linkSrc->doPublish();
@ -151,7 +151,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest {
$linkDest->doDeleteFromLive();
$linkSrc = $this->objFromFixture('Page','content');
$linkSrc->Content = "<p><a href=\"[sitetree_link id=$linkDest->ID]\">about us</a></p>";
$linkSrc->Content = "<p><a href=\"[sitetree_link,id=$linkDest->ID]\">about us</a></p>";
$linkSrc->write();
// Publish the source of the link, while the dest is still unpublished.
@ -175,7 +175,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest {
// Content links are one kind of link to pages
$p2 = new Page();
$p2->Title = "regular link";
$p2->Content = "<a href=\"[sitetree_link id=$p->ID]\">test</a>";
$p2->Content = "<a href=\"[sitetree_link,id=$p->ID]\">test</a>";
$p2->write();
$this->assertTrue($p2->doPublish());
@ -250,7 +250,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest {
// Content links are one kind of link to pages
$p2 = new Page();
$p2->Title = "regular link";
$p2->Content = "<a href=\"[sitetree_link id=$p->ID]\">test</a>";
$p2->Content = "<a href=\"[sitetree_link,id=$p->ID]\">test</a>";
$p2->write();
$this->assertTrue($p2->doPublish());

View File

@ -11,12 +11,12 @@ class SiteTreeHtmlEditorFieldTest extends FunctionalTest {
$aboutID = $this->idFromFixture('SiteTree', 'about');
$contactID = $this->idFromFixture('SiteTree', 'contact');
$editor->setValue("<a href=\"[sitetree_link id=$aboutID]\">Example Link</a>");
$editor->setValue("<a href=\"[sitetree_link,id=$aboutID]\">Example Link</a>");
$editor->saveInto($sitetree);
$this->assertEquals(array($aboutID => $aboutID), $sitetree->LinkTracking()->getIdList(), 'Basic link tracking works.');
$editor->setValue (
"<a href=\"[sitetree_link id=$aboutID]\"></a><a href=\"[sitetree_link id=$contactID]\"></a>"
"<a href=\"[sitetree_link,id=$aboutID]\"></a><a href=\"[sitetree_link,id=$contactID]\"></a>"
);
$editor->saveInto($sitetree);
$this->assertEquals (
@ -89,13 +89,13 @@ class SiteTreeHtmlEditorFieldTest extends FunctionalTest {
$this->assertFalse((bool) $sitetree->HasBrokenLink);
$editor->setValue('<p><a href="[sitetree_link id=0]">Broken Link</a></p>');
$editor->setValue('<p><a href="[sitetree_link,id=0]">Broken Link</a></p>');
$editor->saveInto($sitetree);
$this->assertTrue($sitetree->HasBrokenLink);
$editor->setValue(sprintf (
'<p><a href="[sitetree_link id=%d]">Working Link</a></p>',
'<p><a href="[sitetree_link,id=%d]">Working Link</a></p>',
$this->idFromFixture('SiteTree', 'home')
));
$sitetree->HasBrokenLink = false;
@ -108,13 +108,13 @@ class SiteTreeHtmlEditorFieldTest extends FunctionalTest {
$sitetree = new SiteTree();
$editor = new HtmlEditorField('Content');
$editor->setValue('<a href="[sitetree_link id=0]">Broken Link</a>');
$editor->setValue('<a href="[sitetree_link,id=0]">Broken Link</a>');
$element = new SimpleXMLElement(html_entity_decode((string) new SimpleXMLElement($editor->Field())));
$this->assertContains('ss-broken', (string) $element['class'], 'A broken link class is added to broken links');
$editor->setValue(sprintf (
'<a href="[sitetree_link id=%d]">Working Link</a>',
'<a href="[sitetree_link,id=%d]">Working Link</a>',
$this->idFromFixture('SiteTree', 'home')
));

View File

@ -587,8 +587,8 @@ class SiteTreeTest extends SapphireTest {
$parser = new ShortcodeParser();
$parser->register('sitetree_link', array('SiteTree', 'link_shortcode_handler'));
$aboutShortcode = sprintf('[sitetree_link id=%d]', $aboutPage->ID);
$aboutEnclosed = sprintf('[sitetree_link id=%d]Example Content[/sitetree_link]', $aboutPage->ID);
$aboutShortcode = sprintf('[sitetree_link,id=%d]', $aboutPage->ID);
$aboutEnclosed = sprintf('[sitetree_link,id=%d]Example Content[/sitetree_link]', $aboutPage->ID);
$aboutShortcodeExpected = $aboutPage->Link();
$aboutEnclosedExpected = sprintf('<a href="%s">Example Content</a>', $aboutPage->Link());
@ -601,8 +601,8 @@ class SiteTreeTest extends SapphireTest {
$this->assertEquals($aboutShortcodeExpected, $parser->parse($aboutShortcode), 'Test that deleted pages still link.');
$this->assertEquals($aboutEnclosedExpected, $parser->parse($aboutEnclosed));
$aboutShortcode = '[sitetree_link id="-1"]';
$aboutEnclosed = '[sitetree_link id="-1"]Example Content[/sitetree_link]';
$aboutShortcode = '[sitetree_link,id="-1"]';
$aboutEnclosed = '[sitetree_link,id="-1"]Example Content[/sitetree_link]';
$aboutShortcodeExpected = $errorPage->Link();
$aboutEnclosedExpected = sprintf('<a href="%s">Example Content</a>', $errorPage->Link());
@ -611,7 +611,7 @@ class SiteTreeTest extends SapphireTest {
$this->assertEquals($aboutEnclosedExpected, $parser->parse($aboutEnclosed));
$this->assertEquals('', $parser->parse('[sitetree_link]'), 'Test that invalid ID attributes are not parsed.');
$this->assertEquals('', $parser->parse('[sitetree_link id="text"]'));
$this->assertEquals('', $parser->parse('[sitetree_link,id="text"]'));
$this->assertEquals('', $parser->parse('[sitetree_link]Example Content[/sitetree_link]'));
}

View File

@ -29,25 +29,25 @@ class MigrateSiteTreeLinkingTaskTest extends SapphireTest {
$hashID = $this->idFromFixture('SiteTree', 'hash_link');
$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 href="[sitetree_link,id=%d]">About</a><a href="[sitetree_link,id=%d]">Staff</a><a href="http://silverstripe.org/">External Link</a>',
$aboutID,
$staffID
);
$aboutContent = sprintf (
'<a href="[sitetree_link id=%d]">Home</a><a href="[sitetree_link id=%d]">Staff</a>',
'<a href="[sitetree_link,id=%d]">Home</a><a href="[sitetree_link,id=%d]">Staff</a>',
$homeID,
$staffID
);
$staffContent = sprintf (
'<a href="[sitetree_link id=%d]">Home</a><a href="[sitetree_link id=%d]">About</a>',
'<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
'<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>',
'<a href="[sitetree_link,id=%d]#anchor">Home</a><a href="[sitetree_link,id=%d]#second-anchor">About</a>',
$homeID,
$aboutID
);