Skip to content

Commit

Permalink
Add test for cached elements, use cache setters and fix return in doc…
Browse files Browse the repository at this point in the history
… block
  • Loading branch information
robbieaverill committed Oct 2, 2018
1 parent 27d6b12 commit 928c313
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Models/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,8 @@ public function getAreaRelationName()
}
}

$this->cacheData['area_relation_name'] = $result;
$this->setAreaRelationNameCache($result);

return $result;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Models/ElementalArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function setOwnerPageCached(DataObject $page)

/**
* A cache-aware accessor for the elements
* @return ArrayList|DataList
* @return ArrayList|DataList|BaseElement[]
*/
public function Elements()
{
Expand Down Expand Up @@ -206,7 +206,7 @@ public function getOwnerPage()
$page = Versioned::get_by_stage($class, $currentStage)->filter($areaID, $this->ID)->first();

if ($page) {
$this->cacheData['owner_page'] = $page;
$this->setOwnerPageCached($page);
return $page;
}
}
Expand Down
14 changes: 14 additions & 0 deletions tests/ElementalAreaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,18 @@ public function testUnsavedRelationListOfElementsReturnsEmptyArrayList()
$this->assertInstanceOf(ArrayList::class, $result);
$this->assertEmpty($result);
}

public function testElementsListIsCached()
{
$area = new ElementalArea();

$element = new ElementContent();
$element->HTML = 'Test';

$elements = new ArrayList([$element]);

$area->setElementsCached($elements);

$this->assertSame($elements, $area->Elements());
}
}

0 comments on commit 928c313

Please sign in to comment.