X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/e537d0c4e8dbf0c8bf4ac8119e6a8d7a4adf4bfb..refs/pull/3693/head:/tests/References/ReferencesTest.php
diff --git a/tests/References/ReferencesTest.php b/tests/References/ReferencesTest.php
index 82cd16680..3fd68d647 100644
--- a/tests/References/ReferencesTest.php
+++ b/tests/References/ReferencesTest.php
@@ -3,6 +3,7 @@
namespace Tests\References;
use BookStack\Entities\Models\Book;
+use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Models\Page;
use BookStack\Entities\Repos\PageRepo;
use BookStack\Entities\Tools\TrashCan;
@@ -12,7 +13,6 @@ use Tests\TestCase;
class ReferencesTest extends TestCase
{
-
public function test_references_created_on_page_update()
{
/** @var Page $pageA */
@@ -24,14 +24,14 @@ class ReferencesTest extends TestCase
$this->asEditor()->put($pageA->getUrl(), [
'name' => 'Reference test',
- 'html' => 'Testing'
+ 'html' => 'Testing',
]);
$this->assertDatabaseHas('references', [
- 'from_id' => $pageA->id,
+ 'from_id' => $pageA->id,
'from_type' => $pageA->getMorphClass(),
- 'to_id' => $pageB->id,
- 'to_type' => $pageB->getMorphClass(),
+ 'to_id' => $pageB->id,
+ 'to_type' => $pageB->getMorphClass(),
]);
}
@@ -141,11 +141,61 @@ class ReferencesTest extends TestCase
$this->assertStringContainsString('href="http://localhost/books/my-updated-book-slugaroo"', $page->html);
$this->assertDatabaseHas('page_revisions', [
'page_id' => $page->id,
- 'summary' => 'System auto-update of internal links'
+ 'summary' => 'System auto-update of internal links',
]);
}
}
+ public function test_pages_linking_to_other_page_updated_on_parent_book_url_change()
+ {
+ /** @var Page $bookPage */
+ /** @var Page $otherPage */
+ /** @var Book $book */
+ $bookPage = Page::query()->first();
+ $otherPage = Page::query()->where('id', '!=', $bookPage->id)->first();
+ $book = $bookPage->book;
+
+ $otherPage->html = 'Link';
+ $otherPage->save();
+ $this->createReference($otherPage, $bookPage);
+
+ $this->asEditor()->put($book->getUrl(), [
+ 'name' => 'my updated book slugaroo',
+ ]);
+
+ $otherPage->refresh();
+ $this->assertStringContainsString('href="http://localhost/books/my-updated-book-slugaroo/page/' . $bookPage->slug . '"', $otherPage->html);
+ $this->assertDatabaseHas('page_revisions', [
+ 'page_id' => $otherPage->id,
+ 'summary' => 'System auto-update of internal links',
+ ]);
+ }
+
+ public function test_pages_linking_to_chapter_updated_on_parent_book_url_change()
+ {
+ /** @var Chapter $bookChapter */
+ /** @var Page $otherPage */
+ /** @var Book $book */
+ $bookChapter = Chapter::query()->first();
+ $otherPage = Page::query()->first();
+ $book = $bookChapter->book;
+
+ $otherPage->html = 'Link';
+ $otherPage->save();
+ $this->createReference($otherPage, $bookChapter);
+
+ $this->asEditor()->put($book->getUrl(), [
+ 'name' => 'my updated book slugaroo',
+ ]);
+
+ $otherPage->refresh();
+ $this->assertStringContainsString('href="http://localhost/books/my-updated-book-slugaroo/chapter/' . $bookChapter->slug . '"', $otherPage->html);
+ $this->assertDatabaseHas('page_revisions', [
+ 'page_id' => $otherPage->id,
+ 'summary' => 'System auto-update of internal links',
+ ]);
+ }
+
public function test_markdown_links_leading_to_entity_updated_on_url_change()
{
/** @var Page $page */
@@ -179,10 +229,9 @@ class ReferencesTest extends TestCase
{
(new Reference())->forceFill([
'from_type' => $from->getMorphClass(),
- 'from_id' => $from->id,
- 'to_type' => $to->getMorphClass(),
- 'to_id' => $to->id,
+ 'from_id' => $from->id,
+ 'to_type' => $to->getMorphClass(),
+ 'to_id' => $to->id,
])->save();
}
-
-}
\ No newline at end of file
+}