Created
October 22, 2009 21:01
-
-
Save sminnee/216331 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: /Users/sminnee/Sites/airnz1/sapphire/tests/SiteTreeBrokenLinksTest.php | |
=================================================================== | |
--- /Users/sminnee/Sites/airnz1/sapphire/tests/SiteTreeBrokenLinksTest.php (revision 89880) | |
+++ /Users/sminnee/Sites/airnz1/sapphire/tests/SiteTreeBrokenLinksTest.php (working copy) | |
@@ -58,6 +58,69 @@ | |
$this->assertFalse($obj->HasBrokenFile, 'Page does NOT have a broken file'); | |
} | |
+ function testDeletingMarksBackLinkedPagesAsBroken() { | |
+ $this->logInWithPermission('ADMIN'); | |
+ | |
+ // Set up two published pages with a link from content -> about | |
+ $linkDest = $this->objFromFixture('Page','about'); | |
+ $linkDest->doPublish(); | |
+ | |
+ $linkSrc = $this->objFromFixture('Page','content'); | |
+ $linkSrc->Content = "<p><a href=\"" . $linkDest->URLSegment() . "/\">about us</a></p>"; | |
+ $linkSrc->write(); | |
+ $linkSrc->doPublish(); | |
+ | |
+ // Confirm no broken link | |
+ $this->assertEquals(0, $linkSrc->HasBrokenLink); | |
+ $this->assertEquals(0, DB::query("SELECT \"HasBrokenLink\" FROM \"SiteTree_Live\" | |
+ WHERE \"ID\" = $linkSrc->ID")->value()); | |
+ | |
+ // Delete page from draft | |
+ $linkDestID = $linkDest->ID; | |
+ $linkDest->delete(); | |
+ | |
+ // Confirm draft has broken link, and published doesn't | |
+ $linkSrc->flushCache(); | |
+ $linkSrc = $this->objFromFixture('Page', 'content'); | |
+ | |
+ $this->assertEquals(1, $linkSrc->HasBrokenLink); | |
+ $this->assertEquals(0, DB::query("SELECT \"HasBrokenLink\" FROM \"SiteTree_Live\" | |
+ WHERE \"ID\" = $linkSrc->ID")->value()); | |
+ | |
+ // Delete from live | |
+ $linkDest = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = $linkDestID"); | |
+ $linkDest->doDeleteFromLive(); | |
+ | |
+ // Confirm both draft and published have broken link | |
+ $linkSrc->flushCache(); | |
+ $linkSrc = $this->objFromFixture('Page', 'content'); | |
+ | |
+ $this->assertEquals(1, $linkSrc->HasBrokenLink); | |
+ $this->assertEquals(1, DB::query("SELECT \"HasBrokenLink\" FROM \"SiteTree_Live\" | |
+ WHERE \"ID\" = $linkSrc->ID")->value()); | |
+ } | |
+ | |
+ function testPublishingSourceBeforeDestHasBrokenLink() { | |
+ $this->logInWithPermission('ADMIN'); | |
+ | |
+ // Set up two draft pages with a link from content -> about | |
+ $linkDest = $this->objFromFixture('Page','about'); | |
+ // Ensure that it's not on the published site | |
+ $linkDest->doDeleteFromLive(); | |
+ | |
+ $linkSrc = $this->objFromFixture('Page','content'); | |
+ $linkSrc->Content = "<p><a href=\"" . $about->URLSegment() . "/\">about us</a></p>"; | |
+ $linkSrc->write(); | |
+ | |
+ // Publish the source of the link, while the dest is still unpublished. | |
+ $linkSrc->doPublish(); | |
+ | |
+ // Verify that the link isn't broken on draft but is broken on published | |
+ $this->assertEquals(0, $linkSrc->HasBrokenLink); | |
+ $this->assertEquals(1, DB::query("SELECT \"HasBrokenLink\" FROM \"SiteTree_Live\" | |
+ WHERE \"ID\" = $linkSrc->ID")->value()); | |
+ } | |
+ | |
} | |
?> | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment