+ public function test_description_links_from_book_chapter_shelf_updated_on_url_change()
+ {
+ $entities = [$this->entities->chapter(), $this->entities->book(), $this->entities->shelf()];
+ $shelf = $this->entities->shelf();
+ $this->asEditor();
+
+ foreach ($entities as $entity) {
+ $this->put($entity->getUrl(), [
+ 'name' => 'Reference test',
+ 'description_html' => '<a href="' . $shelf->getUrl() . '">Testing</a>',
+ ]);
+ }
+
+ $oldUrl = $shelf->getUrl();
+ $this->put($shelf->getUrl(), ['name' => 'My updated shelf link']);
+ $shelf->refresh();
+ $this->assertNotEquals($oldUrl, $shelf->getUrl());
+
+ foreach ($entities as $entity) {
+ $oldHtml = $entity->description_html;
+ $entity->refresh();
+ $this->assertNotEquals($oldHtml, $entity->description_html);
+ $this->assertStringContainsString($shelf->getUrl(), $entity->description_html);
+ }
+ }
+
+ public function test_reference_from_deleted_item_does_not_count_or_show_in_references_page()
+ {
+ $page = $this->entities->page();
+ $referencingPageA = $this->entities->page();
+ $referencingPageB = $this->entities->page();
+
+ $this->asEditor();
+ $this->createReference($referencingPageA, $page);
+ $this->createReference($referencingPageB, $page);
+
+ $resp = $this->get($page->getUrl());
+ $resp->assertSee('Referenced by 2 items');
+
+ $this->delete($referencingPageA->getUrl());
+
+ $resp = $this->get($page->getUrl());
+ $resp->assertSee('Referenced by 1 item');
+
+ $resp = $this->get($page->getUrl('/references'));
+ $resp->assertOk();
+ $resp->assertSee($referencingPageB->getUrl());
+ $resp->assertDontSee($referencingPageA->getUrl());
+ }
+
+ protected function createReference(Model $from, Model $to): void