]> BookStack Code Mirror - bookstack/blobdiff - tests/References/ReferencesTest.php
Layout: Converted tri-layout component to ts
[bookstack] / tests / References / ReferencesTest.php
index bc691b0cd56adcde5684a33fe012770de31e6bde..f8698d028858145deba511a35784839d5d7de9df 100644 (file)
@@ -102,13 +102,13 @@ class ReferencesTest extends TestCase
 
         foreach ($entities as $entity) {
             $resp = $this->get($entity->getUrl());
-            $resp->assertSee('Referenced on 1 page');
-            $resp->assertDontSee('Referenced on 1 pages');
+            $resp->assertSee('Referenced by 1 item');
+            $resp->assertDontSee('Referenced by 1 items');
         }
 
         $this->createReference($otherPage, $entities['page']);
         $resp = $this->get($entities['page']->getUrl());
-        $resp->assertSee('Referenced on 2 pages');
+        $resp->assertSee('Referenced by 2 items');
     }
 
     public function test_references_to_visible_on_references_page()
@@ -271,7 +271,31 @@ class ReferencesTest extends TestCase
         }
     }
 
-    protected function createReference(Model $from, Model $to)
+    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
     {
         (new Reference())->forceFill([
             'from_type' => $from->getMorphClass(),