Skip to content

Commit

Permalink
BUG Change all shortcodes into the new, comma separated, format.
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz authored and chillu committed Jul 12, 2012
1 parent 8055fc2 commit 54fd54a
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion code/model/SiteTree.php
Expand Up @@ -366,7 +366,7 @@ public static function page_type_classes() {
} }


/** /**
* 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 * @return string
*/ */
Expand Down
2 changes: 1 addition & 1 deletion tasks/MigrateSiteTreeLinkingTask.php
Expand Up @@ -26,7 +26,7 @@ public function run($request) {
// TOOD: Replace in all HTMLText fields // TOOD: Replace in all HTMLText fields
$page->Content = preg_replace ( $page->Content = preg_replace (
"/href *= *([\"']?){$linked->URLSegment}\/?/i", "/href *= *([\"']?){$linked->URLSegment}\/?/i",
"href=$1[sitetree_link id={$linked->ID}]", "href=$1[sitetree_link,id={$linked->ID}]",
$page->Content, $page->Content,
-1, -1,
$replaced $replaced
Expand Down
2 changes: 1 addition & 1 deletion tests/controller/ContentControllerTest.php
Expand Up @@ -112,7 +112,7 @@ public function testLinkShortcodes() {


$page = new SiteTree(); $page = new SiteTree();
$page->URLSegment = 'linking-page'; $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->write();
$page->publish('Stage', 'Live'); $page->publish('Stage', 'Live');


Expand Down
4 changes: 2 additions & 2 deletions tests/model/SiteTreeBacklinksTest.php
Expand Up @@ -36,7 +36,7 @@ function testSavingPageWithLinkAddsBacklink() {
$this->assertNotContains($page2->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 2 doesn\'t exist'); $this->assertNotContains($page2->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 2 doesn\'t exist');


// add hyperlink to page 1 on page 2 // 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(); $page2->write();


// load page 1 // load page 1
Expand Down Expand Up @@ -205,7 +205,7 @@ function testLinkTrackingOnExtraContentFields() {
$this->assertNotContains($page2->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 2 doesn\'t exist'); $this->assertNotContains($page2->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 2 doesn\'t exist');


// add hyperlink to page 1 on page 2 // 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->write();
$page2->doPublish(); $page2->doPublish();


Expand Down
2 changes: 1 addition & 1 deletion tests/model/SiteTreeBacklinksTest.yml
Expand Up @@ -11,7 +11,7 @@ Page:
page3: page3:
Title: page3 Title: page3
URLSegment: 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 LinkTracking: =>Page.page1




12 changes: 6 additions & 6 deletions tests/model/SiteTreeBrokenLinksTest.php
Expand Up @@ -21,11 +21,11 @@ static function tear_down_once() {
function testBrokenLinksBetweenPages() { function testBrokenLinksBetweenPages() {
$obj = $this->objFromFixture('Page','content'); $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(); $obj->syncLinkTracking();
$this->assertTrue($obj->HasBrokenLink, 'Page has a broken link'); $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(); $obj->syncLinkTracking();
$this->assertFalse($obj->HasBrokenLink, 'Page does NOT have a broken link'); $this->assertFalse($obj->HasBrokenLink, 'Page does NOT have a broken link');
} }
Expand Down Expand Up @@ -107,7 +107,7 @@ function testDeletingMarksBackLinkedPagesAsBroken() {
$linkDest->doPublish(); $linkDest->doPublish();


$linkSrc = $this->objFromFixture('Page','content'); $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->write();


$linkSrc->doPublish(); $linkSrc->doPublish();
Expand Down Expand Up @@ -151,7 +151,7 @@ function testPublishingSourceBeforeDestHasBrokenLink() {
$linkDest->doDeleteFromLive(); $linkDest->doDeleteFromLive();


$linkSrc = $this->objFromFixture('Page','content'); $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->write();


// Publish the source of the link, while the dest is still unpublished. // Publish the source of the link, while the dest is still unpublished.
Expand All @@ -175,7 +175,7 @@ function testRestoreFixesBrokenLinks() {
// Content links are one kind of link to pages // Content links are one kind of link to pages
$p2 = new Page(); $p2 = new Page();
$p2->Title = "regular link"; $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(); $p2->write();
$this->assertTrue($p2->doPublish()); $this->assertTrue($p2->doPublish());


Expand Down Expand Up @@ -250,7 +250,7 @@ function testRevertToLiveFixesBrokenLinks() {
// Content links are one kind of link to pages // Content links are one kind of link to pages
$p2 = new Page(); $p2 = new Page();
$p2->Title = "regular link"; $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(); $p2->write();
$this->assertTrue($p2->doPublish()); $this->assertTrue($p2->doPublish());


Expand Down
12 changes: 6 additions & 6 deletions tests/model/SiteTreeHTMLEditorFieldTest.php
Expand Up @@ -11,12 +11,12 @@ public function testLinkTracking() {
$aboutID = $this->idFromFixture('SiteTree', 'about'); $aboutID = $this->idFromFixture('SiteTree', 'about');
$contactID = $this->idFromFixture('SiteTree', 'contact'); $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); $editor->saveInto($sitetree);
$this->assertEquals(array($aboutID => $aboutID), $sitetree->LinkTracking()->getIdList(), 'Basic link tracking works.'); $this->assertEquals(array($aboutID => $aboutID), $sitetree->LinkTracking()->getIdList(), 'Basic link tracking works.');


$editor->setValue ( $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); $editor->saveInto($sitetree);
$this->assertEquals ( $this->assertEquals (
Expand Down Expand Up @@ -89,13 +89,13 @@ public function testBrokenLinkTracking() {


$this->assertFalse((bool) $sitetree->HasBrokenLink); $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); $editor->saveInto($sitetree);


$this->assertTrue($sitetree->HasBrokenLink); $this->assertTrue($sitetree->HasBrokenLink);


$editor->setValue(sprintf ( $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') $this->idFromFixture('SiteTree', 'home')
)); ));
$sitetree->HasBrokenLink = false; $sitetree->HasBrokenLink = false;
Expand All @@ -108,13 +108,13 @@ public function testBrokenLinkHighlighting() {
$sitetree = new SiteTree(); $sitetree = new SiteTree();
$editor = new HtmlEditorField('Content'); $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()))); $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'); $this->assertContains('ss-broken', (string) $element['class'], 'A broken link class is added to broken links');


$editor->setValue(sprintf ( $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') $this->idFromFixture('SiteTree', 'home')
)); ));


Expand Down
10 changes: 5 additions & 5 deletions tests/model/SiteTreeTest.php
Expand Up @@ -587,8 +587,8 @@ public function testLinkShortcodeHandler() {
$parser = new ShortcodeParser(); $parser = new ShortcodeParser();
$parser->register('sitetree_link', array('SiteTree', 'link_shortcode_handler')); $parser->register('sitetree_link', array('SiteTree', 'link_shortcode_handler'));


$aboutShortcode = sprintf('[sitetree_link id=%d]', $aboutPage->ID); $aboutShortcode = sprintf('[sitetree_link,id=%d]', $aboutPage->ID);
$aboutEnclosed = sprintf('[sitetree_link id=%d]Example Content[/sitetree_link]', $aboutPage->ID); $aboutEnclosed = sprintf('[sitetree_link,id=%d]Example Content[/sitetree_link]', $aboutPage->ID);


$aboutShortcodeExpected = $aboutPage->Link(); $aboutShortcodeExpected = $aboutPage->Link();
$aboutEnclosedExpected = sprintf('<a href="%s">Example Content</a>', $aboutPage->Link()); $aboutEnclosedExpected = sprintf('<a href="%s">Example Content</a>', $aboutPage->Link());
Expand All @@ -601,8 +601,8 @@ public function testLinkShortcodeHandler() {
$this->assertEquals($aboutShortcodeExpected, $parser->parse($aboutShortcode), 'Test that deleted pages still link.'); $this->assertEquals($aboutShortcodeExpected, $parser->parse($aboutShortcode), 'Test that deleted pages still link.');
$this->assertEquals($aboutEnclosedExpected, $parser->parse($aboutEnclosed)); $this->assertEquals($aboutEnclosedExpected, $parser->parse($aboutEnclosed));


$aboutShortcode = '[sitetree_link id="-1"]'; $aboutShortcode = '[sitetree_link,id="-1"]';
$aboutEnclosed = '[sitetree_link id="-1"]Example Content[/sitetree_link]'; $aboutEnclosed = '[sitetree_link,id="-1"]Example Content[/sitetree_link]';


$aboutShortcodeExpected = $errorPage->Link(); $aboutShortcodeExpected = $errorPage->Link();
$aboutEnclosedExpected = sprintf('<a href="%s">Example Content</a>', $errorPage->Link()); $aboutEnclosedExpected = sprintf('<a href="%s">Example Content</a>', $errorPage->Link());
Expand All @@ -611,7 +611,7 @@ public function testLinkShortcodeHandler() {
$this->assertEquals($aboutEnclosedExpected, $parser->parse($aboutEnclosed)); $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]'), '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]')); $this->assertEquals('', $parser->parse('[sitetree_link]Example Content[/sitetree_link]'));
} }


Expand Down
10 changes: 5 additions & 5 deletions tests/tasks/MigrateSiteTreeLinkingTaskTest.php
Expand Up @@ -29,25 +29,25 @@ public function testLinkingMigration() {
$hashID = $this->idFromFixture('SiteTree', 'hash_link'); $hashID = $this->idFromFixture('SiteTree', 'hash_link');


$homeContent = sprintf ( $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, $aboutID,
$staffID $staffID
); );
$aboutContent = sprintf ( $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, $homeID,
$staffID $staffID
); );
$staffContent = sprintf ( $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, $homeID,
$aboutID $aboutID
); );
$actionContent = sprintf ( $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 ( $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, $homeID,
$aboutID $aboutID
); );
Expand Down

0 comments on commit 54fd54a

Please sign in to comment.