@@ -201,6 +201,92 @@ public function test_chapter_copy_does_not_copy_pages_if_user_cant_page_create()
201201 $ this ->assertEquals ($ chapter ->pages ()->count (), $ newChapter2 ->pages ()->count ());
202202 }
203203
204+ public function test_book_copy_updates_internal_references ()
205+ {
206+ $ book = $ this ->entities ->bookHasChaptersAndPages ();
207+ /** @var Chapter $chapter */
208+ $ chapter = $ book ->chapters ()->first ();
209+ /** @var Page $page */
210+ $ page = $ chapter ->pages ()->first ();
211+ $ this ->asEditor ();
212+ $ this ->entities ->updatePage ($ page , [
213+ 'name ' => 'reference test page ' ,
214+ 'html ' => '<p>This is a test <a href=" ' . $ book ->getUrl () . '">book link</a></p> ' ,
215+ ]);
216+
217+ $ html = '<p>This is a test <a href=" ' . $ page ->getUrl () . '">page link</a></p> ' ;
218+
219+ // Quick pre-update to get stable slug
220+ $ this ->put ($ book ->getUrl (), ['name ' => 'Internal ref test ' ]);
221+ $ book ->refresh ();
222+
223+ $ this ->put ($ book ->getUrl (), ['name ' => 'Internal ref test ' , 'description_html ' => $ html ]);
224+
225+ $ this ->post ($ book ->getUrl ('/copy ' ), ['name ' => 'My copied book ' ]);
226+
227+ $ newBook = Book::query ()->where ('name ' , '= ' , 'My copied book ' )->first ();
228+ $ newPage = $ newBook ->pages ()->where ('name ' , '= ' , 'reference test page ' )->first ();
229+
230+ $ this ->assertStringContainsString ($ newBook ->getUrl (), $ newPage ->html );
231+ $ this ->assertStringContainsString ($ newPage ->getUrl (), $ newBook ->description_html );
232+
233+ $ this ->assertStringNotContainsString ($ book ->getUrl (), $ newPage ->html );
234+ $ this ->assertStringNotContainsString ($ page ->getUrl (), $ newBook ->description_html );
235+ }
236+
237+ public function test_chapter_copy_updates_internal_references ()
238+ {
239+ $ chapter = $ this ->entities ->chapterHasPages ();
240+ /** @var Page $page */
241+ $ page = $ chapter ->pages ()->first ();
242+ $ this ->asEditor ();
243+ $ this ->entities ->updatePage ($ page , [
244+ 'name ' => 'reference test page ' ,
245+ 'html ' => '<p>This is a test <a href=" ' . $ chapter ->getUrl () . '">chapter link</a></p> ' ,
246+ ]);
247+
248+ $ html = '<p>This is a test <a href=" ' . $ page ->getUrl () . '">page link</a></p> ' ;
249+
250+ // Quick pre-update to get stable slug
251+ $ this ->put ($ chapter ->getUrl (), ['name ' => 'Internal ref test ' ]);
252+ $ chapter ->refresh ();
253+
254+ $ this ->put ($ chapter ->getUrl (), ['name ' => 'Internal ref test ' , 'description_html ' => $ html ]);
255+
256+ $ this ->post ($ chapter ->getUrl ('/copy ' ), ['name ' => 'My copied chapter ' ]);
257+
258+ $ newChapter = Chapter::query ()->where ('name ' , '= ' , 'My copied chapter ' )->first ();
259+ $ newPage = $ newChapter ->pages ()->where ('name ' , '= ' , 'reference test page ' )->first ();
260+
261+ $ this ->assertStringContainsString ($ newChapter ->getUrl (), $ newPage ->html );
262+ $ this ->assertStringContainsString ($ newPage ->getUrl (), $ newChapter ->description_html );
263+
264+ $ this ->assertStringNotContainsString ($ chapter ->getUrl (), $ newPage ->html );
265+ $ this ->assertStringNotContainsString ($ page ->getUrl (), $ newChapter ->description_html );
266+ }
267+
268+ public function test_page_copy_updates_internal_self_references ()
269+ {
270+ $ page = $ this ->entities ->page ();
271+ $ this ->asEditor ();
272+
273+ // Initial update to get stable slug
274+ $ this ->entities ->updatePage ($ page , ['name ' => 'reference test page ' ]);
275+
276+ $ page ->refresh ();
277+ $ this ->entities ->updatePage ($ page , [
278+ 'name ' => 'reference test page ' ,
279+ 'html ' => '<p>This is a test <a href=" ' . $ page ->getUrl () . '">page link</a></p> ' ,
280+ ]);
281+
282+ $ this ->post ($ page ->getUrl ('/copy ' ), ['name ' => 'My copied page ' ]);
283+ $ newPage = Page::query ()->where ('name ' , '= ' , 'My copied page ' )->first ();
284+ $ this ->assertNotNull ($ newPage );
285+
286+ $ this ->assertStringContainsString ($ newPage ->getUrl (), $ newPage ->html );
287+ $ this ->assertStringNotContainsString ($ page ->getUrl (), $ newPage ->html );
288+ }
289+
204290 public function test_page_copy ()
205291 {
206292 $ page = $ this ->entities ->page ();
0 commit comments