Skip to content

Commit 3cd3e73

Browse files
committed
Copying: Fixed issue with non-page links to page permalinks
Found during manual testing. Added test case to cover.
1 parent 959981a commit 3cd3e73

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

app/References/ReferenceChangeContext.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,6 @@ public function add(Entity $oldEntity, Entity $newEntity): void
1717
$this->changes[] = [$oldEntity, $newEntity];
1818
}
1919

20-
/**
21-
* Get all the change pairs.
22-
* Returned array is an array of pairs, where the first item is the old entity
23-
* and the second is the new entity.
24-
* @return array<array{0: Entity, 1: Entity}>
25-
*/
26-
public function getChanges(): array
27-
{
28-
return $this->changes;
29-
}
30-
3120
/**
3221
* Get all the new entities from the changes.
3322
*/

app/References/ReferenceUpdater.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function changeReferencesUsingContext(ReferenceChangeContext $context): v
6161

6262
$this->updateReferencesWithinEntity($new, $oldToEntity->getUrl(), $newToEntity->getUrl());
6363
if ($newToEntity instanceof Page && $oldToEntity instanceof Page) {
64-
$this->updateReferencesWithinPage($newToEntity, $oldToEntity->getPermalink(), $newToEntity->getPermalink());
64+
$this->updateReferencesWithinEntity($new, $oldToEntity->getPermalink(), $newToEntity->getPermalink());
6565
}
6666
$reference->to_id = $newToEntity->id;
6767
$reference->to_type = $newToEntity->getMorphClass();

tests/Entity/CopyTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,25 @@ public function test_chapter_copy_updates_internal_references()
265265
$this->assertStringNotContainsString($page->getUrl() . '"', $newChapter->description_html);
266266
}
267267

268+
public function test_chapter_copy_updates_internal_permalink_references_in_its_description()
269+
{
270+
$chapter = $this->entities->chapterHasPages();
271+
/** @var Page $page */
272+
$page = $chapter->pages()->first();
273+
274+
$this->asEditor()->put($chapter->getUrl(), [
275+
'name' => 'Internal ref test',
276+
'description_html' => '<p>This is a test <a href="' . $page->getPermalink() . '">page link</a></p>',
277+
]);
278+
$chapter->refresh();
279+
280+
$this->post($chapter->getUrl('/copy'), ['name' => 'My copied chapter']);
281+
$newChapter = Chapter::query()->where('name', '=', 'My copied chapter')->first();
282+
283+
$this->assertStringContainsString('/link/', $newChapter->description_html);
284+
$this->assertStringNotContainsString($page->getPermalink() . '"', $newChapter->description_html);
285+
}
286+
268287
public function test_page_copy_updates_internal_self_references()
269288
{
270289
$page = $this->entities->page();

0 commit comments

Comments
 (0)