Skip to content

Commit

Permalink
fix: getPage returning the wrong page
Browse files Browse the repository at this point in the history
If you programaticaly update the ParentID of an element, getPage() still returns the outdated page.
  • Loading branch information
wilr committed Aug 17, 2023
1 parent 8bc68fe commit 65f4c70
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
/vendor/
/resources/
/assets/
/public
.phpunit.result.cache
composer.lock
3 changes: 1 addition & 2 deletions src/Models/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,7 @@ public function getSimpleClassName()
*/
public function getPage()
{
// Allow for repeated calls to be cached
if (isset($this->cacheData['page'])) {
if (isset($this->cacheData['page']) && !$this->isChanged('ParentID')) {
return $this->cacheData['page'];
}

Expand Down
14 changes: 14 additions & 0 deletions tests/BaseElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,4 +511,18 @@ public function testGetContentForCmsSearch()
$element = $this->objFromFixture(TestElement::class, 'elementDataObject3');
$this->assertSame('Hello Test|#|Element 3', $element->getContentForCmsSearch());
}


public function testGetPage()
{
$element = $this->objFromFixture(ElementContent::class, 'content1');

$this->assertStringContainsString($element->getPage()->Title(), 'Test Elemental');

$updatePage = $this->objFromFixture(TestPage::class, 'page_with_elements');

$element->ParentID = $updatePage->ID;

$this->assertStringContainsString($element->getPage()->Title(), 'Page with elements');
}
}

0 comments on commit 65f4c70

Please sign in to comment.