mirror of
https://github.com/silverstripe/silverstripe-frameworktest
synced 2024-10-22 11:06:02 +02:00
260ad323ac
Similar to FTFileMakerTask, this allows for creation of trees of arbitrary depths. Which is useful to test long page lists, deep trees, or large amount of “broad vs deep” nestings. Yes, it has no unit tests - I’m fine with that :)
54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
<?php
|
|
|
|
use SilverStripe\Dev\BuildTask;
|
|
/**
|
|
* Creates sample page structure, useful to test tree performance,
|
|
* UI behaviour on deeply nested pages etc.
|
|
*
|
|
* @todo Allow passing in counts
|
|
*/
|
|
class FTPageMakerTask extends BuildTask
|
|
{
|
|
|
|
/**
|
|
* Defaults create 15,000 pages
|
|
*/
|
|
protected $pageCountByDepth = [
|
|
10,
|
|
100,
|
|
5,
|
|
1,
|
|
1
|
|
];
|
|
|
|
public function run($request)
|
|
{
|
|
$this->generatePages();
|
|
}
|
|
|
|
protected function generatePages($depth = 0, $prefix = "", $parentID = 0)
|
|
{
|
|
$maxDepth = count($this->pageCountByDepth);
|
|
$pageCount = $this->pageCountByDepth[$depth];
|
|
|
|
for ($i=1; $i<=$pageCount; $i++) {
|
|
$fullPrefix = $prefix ? "{$prefix}-{$i}" : $i;
|
|
$page = new Page();
|
|
$page->ParentID = $parentID;
|
|
$page->Title = "Test page {$fullPrefix}";
|
|
$page->write();
|
|
$page->publish('Stage', 'Live');
|
|
|
|
echo "Created '$page->Title'\n";
|
|
|
|
$pageID = $page->ID;
|
|
unset($page);
|
|
|
|
if ($depth < $maxDepth-1) {
|
|
$this->generatePages($depth+1, $fullPrefix, $pageID);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|