-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NEW: Add Hierarchy::prepopulate_numchildren_cache() #8380
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1d81ecb
NEW: Add DB::replace_parameter()
ac43376
NEW: Add Hierarchy::prepopulate_numchildren_cache()
574918c
Add a `_complete` flag prepopulate_numchildren_cache
cc7769a
Write some test for DB::replace_parameter
dd436f5
Write unit test for testing Hierarchy caching.
07f9cdc
Switch from preg_split to explode for DB::replace_parameter
700b5da
Simplify Hierarchy::prepopulate_numchildren_cache
76f7017
Wrap GroupBy in double quotes for Postgresql
c352a26
NEW: Add Hierarchy::prepopulateTreeDataCache()
9ca1f75
Applying feedback from Peer review.
e4a7c43
Remove DB::replace_parameter
ff92963
Attach table name the stageChildren where ParentID <> ID clause
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Versioned\Tests; | ||
|
||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\ORM\Hierarchy\Hierarchy; | ||
use SilverStripe\Versioned\Versioned; | ||
use SilverStripe\ORM\Tests\HierarchyTest\TestObject; | ||
use SilverStripe\ORM\Tests\HierarchyTest\HideTestObject; | ||
use SilverStripe\ORM\Tests\HierarchyTest\HideTestSubObject; | ||
|
||
/** | ||
* @internal Only test the right values are returned, not that the cache is actually used. | ||
*/ | ||
class HierachyCacheTest extends SapphireTest | ||
{ | ||
|
||
protected static $fixture_file = 'HierarchyTest.yml'; | ||
|
||
protected static $extra_dataobjects = array( | ||
TestObject::class, | ||
HideTestObject::class, | ||
HideTestSubObject::class, | ||
); | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
TestObject::singleton()->flushCache(); | ||
} | ||
|
||
public static function setUpBeforeClass() | ||
{ | ||
parent::setUpBeforeClass(); | ||
HideTestObject::config()->update( | ||
'hide_from_hierarchy', | ||
[ HideTestSubObject::class ] | ||
); | ||
} | ||
|
||
public function cacheNumChildrenDataProvider() | ||
{ | ||
return [ | ||
[TestObject::class, 'obj1', false, 0, 'childless object should have a numChildren of 0'], | ||
[TestObject::class, 'obj1', true, 0, 'childless object should have a numChildren of 0 when cache'], | ||
[TestObject::class, 'obj2', false, 2, 'Root object numChildren should count direct children'], | ||
[TestObject::class, 'obj2', true, 2, 'Root object numChildren should count direct children when cache'], | ||
[TestObject::class, 'obj3a', false, 2, 'Sub object numChildren should count direct children'], | ||
[TestObject::class, 'obj3a', false, 2, 'Sub object numChildren should count direct children when cache'], | ||
robbieaverill marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[TestObject::class, 'obj3d', false, 0, 'Childess Sub object numChildren should be 0'], | ||
[TestObject::class, 'obj3d', true, 0, 'Childess Sub object numChildren should be 0 when cache'], | ||
[HideTestObject::class, 'obj4', false, 1, 'Hidden object should not be included in count'], | ||
[HideTestObject::class, 'obj4', true, 1, 'Hidden object should not be included in couunt when cache'] | ||
]; | ||
} | ||
|
||
|
||
/** | ||
* @dataProvider cacheNumChildrenDataProvider | ||
*/ | ||
public function testNumChildrenCache($className, $identifier, $cache, $expected, $message) | ||
{ | ||
$node = $this->objFromFixture($className, $identifier); | ||
|
||
$actual = $node->numChildren($cache); | ||
|
||
$this->assertEquals($expected, $actual, $message); | ||
|
||
if ($cache) { | ||
// When caching is eanbled, try re-accessing the numChildren value to make sure it doesn't change. | ||
$actual = $node->numChildren($cache); | ||
$this->assertEquals($expected, $actual, $message); | ||
} | ||
} | ||
|
||
public function prepopulateCacheNumChildrenDataProvider() | ||
{ | ||
return [ | ||
[ | ||
TestObject::class, 'Stage', [], | ||
TestObject::class, 'obj1', false, 0, 'childless object should have a numChildren of 0' | ||
], | ||
[ | ||
TestObject::class, 'Stage', [], | ||
TestObject::class, 'obj1', true, 0, 'childless object should have a numChildren of 0 when cache' | ||
], | ||
[ | ||
TestObject::class, 'Stage', [2], | ||
TestObject::class, 'obj1', false, 0, 'childless object should have a numChildren of 0' | ||
], | ||
[ | ||
TestObject::class, 'Stage', [2], | ||
TestObject::class, 'obj1', true, 0, 'childless object should have a numChildren of 0 when cache' | ||
], | ||
[ | ||
TestObject::class, 'Stage', [], | ||
TestObject::class, 'obj2', false, 2, 'Root object numChildren should count direct children' | ||
], | ||
[ | ||
TestObject::class, 'Stage', [], | ||
TestObject::class, 'obj2', true, 2, 'Root object numChildren should count direct children when cache' | ||
], | ||
[ | ||
TestObject::class, 'Stage', [2], | ||
TestObject::class, 'obj2', false, 2, 'Root object numChildren should count direct children' | ||
], | ||
[ | ||
TestObject::class, 'Stage', [2], | ||
TestObject::class, 'obj2', true, 2, 'Root object numChildren should count direct children when cache' | ||
], | ||
[ | ||
HideTestObject::class, 'Stage', [], | ||
HideTestObject::class, 'obj4', false, 1, 'Hidden object should not be included in count' | ||
], | ||
[ | ||
HideTestObject::class, 'Stage', [], | ||
HideTestObject::class, 'obj4', true, 1, 'Hidden object should not be included in count when cache' | ||
], | ||
[ | ||
HideTestObject::class, 'Stage', [2], | ||
HideTestObject::class, 'obj4', false, 1, 'Hidden object should not be included in count' | ||
], | ||
[ | ||
HideTestObject::class, 'Stage', [2], | ||
HideTestObject::class, 'obj4', true, 1, 'Hidden object should not be included in count when cache' | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider prepopulateCacheNumChildrenDataProvider | ||
*/ | ||
public function testPrepopulatedNumChildrenCache( | ||
$baseClass, | ||
$stage, | ||
$idList, | ||
$className, | ||
$identifier, | ||
$cache, | ||
$expected, | ||
$message | ||
) { | ||
Hierarchy::prepopulate_numchildren_cache($baseClass, $stage, $idList); | ||
maxime-rainville marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$node = $this->objFromFixture($className, $identifier); | ||
|
||
$actual = $node->numChildren($cache); | ||
|
||
$this->assertEquals($expected, $actual, $message); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you apply this to SiteTree instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not as it ought to work with this and that's how the other Hierarchy test are using.