2013-01-17 01:22:13 +01:00
|
|
|
<?php
|
|
|
|
|
2016-06-16 07:06:51 +02:00
|
|
|
use SilverStripe\ORM\ArrayList;
|
2016-11-10 12:53:48 +01:00
|
|
|
use SilverStripe\ORM\DataObject;
|
2016-09-09 08:11:38 +02:00
|
|
|
use SilverStripe\Reports\Report;
|
2016-11-10 12:53:48 +01:00
|
|
|
use SilverStripe\Control\Controller;
|
2016-08-29 03:55:43 +02:00
|
|
|
use SilverStripe\Control\Session;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Dev\TestOnly;
|
2016-11-10 12:53:48 +01:00
|
|
|
use SilverStripe\Admin\CMSPreviewable ;
|
2016-11-10 14:01:37 +01:00
|
|
|
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
2016-08-29 03:55:43 +02:00
|
|
|
|
2016-06-16 07:06:51 +02:00
|
|
|
|
2013-01-17 01:22:13 +01:00
|
|
|
/**
|
|
|
|
* @package reports
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2015-12-15 23:06:45 +01:00
|
|
|
class ReportTest extends SapphireTest
|
|
|
|
{
|
2016-07-18 14:02:20 +02:00
|
|
|
protected $usesDatabase = true;
|
2015-12-15 23:06:45 +01:00
|
|
|
|
|
|
|
public function testGetReports()
|
|
|
|
{
|
2016-09-09 08:11:38 +02:00
|
|
|
$reports = Report::get_reports();
|
2016-07-29 00:44:00 +02:00
|
|
|
$this->assertNotNull($reports, "Reports returned");
|
|
|
|
$previousSort = 0;
|
|
|
|
foreach ($reports as $report) {
|
|
|
|
$this->assertGreaterThanOrEqual($previousSort, $report->sort, "Reports are in correct sort order");
|
|
|
|
$previousSort = $report->sort;
|
|
|
|
}
|
|
|
|
}
|
2015-12-15 23:06:45 +01:00
|
|
|
|
|
|
|
public function testExcludeReport()
|
|
|
|
{
|
2016-09-09 08:11:38 +02:00
|
|
|
$reports = Report::get_reports();
|
2016-07-29 00:44:00 +02:00
|
|
|
$reportNames = array();
|
|
|
|
foreach ($reports as $report) {
|
2016-09-27 23:00:51 +02:00
|
|
|
$reportNames[] = get_class($report);
|
2016-07-29 00:44:00 +02:00
|
|
|
}
|
|
|
|
$this->assertContains('ReportTest_FakeTest', $reportNames, 'ReportTest_FakeTest is in reports list');
|
|
|
|
|
|
|
|
//exclude one report
|
2016-09-09 08:11:38 +02:00
|
|
|
Report::add_excluded_reports('ReportTest_FakeTest');
|
2016-07-29 00:44:00 +02:00
|
|
|
|
2016-09-09 08:11:38 +02:00
|
|
|
$reports = Report::get_reports();
|
2016-07-29 00:44:00 +02:00
|
|
|
$reportNames = array();
|
|
|
|
foreach ($reports as $report) {
|
2016-09-27 23:00:51 +02:00
|
|
|
$reportNames[] = get_class($report);
|
2016-07-29 00:44:00 +02:00
|
|
|
}
|
|
|
|
$this->assertNotContains('ReportTest_FakeTest', $reportNames, 'ReportTest_FakeTest is NOT in reports list');
|
|
|
|
|
|
|
|
//exclude two reports
|
2016-09-09 08:11:38 +02:00
|
|
|
Report::add_excluded_reports(array('ReportTest_FakeTest', 'ReportTest_FakeTest2'));
|
2016-07-29 00:44:00 +02:00
|
|
|
|
2016-09-09 08:11:38 +02:00
|
|
|
$reports = Report::get_reports();
|
2016-07-29 00:44:00 +02:00
|
|
|
$reportNames = array();
|
|
|
|
foreach ($reports as $report) {
|
2016-09-27 23:00:51 +02:00
|
|
|
$reportNames[] = get_class($report);
|
2016-07-29 00:44:00 +02:00
|
|
|
}
|
|
|
|
$this->assertNotContains('ReportTest_FakeTest', $reportNames, 'ReportTest_FakeTest is NOT in reports list');
|
|
|
|
$this->assertNotContains('ReportTest_FakeTest2', $reportNames, 'ReportTest_FakeTest2 is NOT in reports list');
|
|
|
|
}
|
2015-12-15 23:06:45 +01:00
|
|
|
|
|
|
|
public function testAbstractClassesAreExcluded()
|
|
|
|
{
|
2016-09-09 08:11:38 +02:00
|
|
|
$reports = Report::get_reports();
|
2016-07-29 00:44:00 +02:00
|
|
|
$reportNames = array();
|
|
|
|
foreach ($reports as $report) {
|
2016-09-27 23:00:51 +02:00
|
|
|
$reportNames[] = get_class($report);
|
2016-07-29 00:44:00 +02:00
|
|
|
}
|
|
|
|
$this->assertNotContains('ReportTest_FakeTest_Abstract',
|
|
|
|
$reportNames,
|
|
|
|
'ReportTest_FakeTest_Abstract is NOT in reports list as it is abstract');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPermissions()
|
|
|
|
{
|
|
|
|
$report = new ReportTest_FakeTest2();
|
|
|
|
|
|
|
|
// Visitor cannot view
|
|
|
|
Session::clear("loggedInAs");
|
|
|
|
$this->assertFalse($report->canView());
|
|
|
|
|
|
|
|
// Logged in user that cannot view reports
|
|
|
|
$this->logInWithPermission('SITETREE_REORGANISE');
|
|
|
|
$this->assertFalse($report->canView());
|
|
|
|
|
|
|
|
// Logged in with report permissions
|
|
|
|
$this->logInWithPermission('CMS_ACCESS_ReportAdmin');
|
|
|
|
$this->assertTrue($report->canView());
|
|
|
|
|
2015-12-17 23:41:34 +01:00
|
|
|
// Admin can view
|
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
$this->assertTrue($report->canView());
|
|
|
|
}
|
2016-07-12 05:43:48 +02:00
|
|
|
|
|
|
|
public function testColumnLink() {
|
|
|
|
$report = new ReportTest_FakeTest();
|
|
|
|
/** @var GridField $gridField */
|
|
|
|
$gridField = $report->getReportField();
|
|
|
|
/** @var GridFieldDataColumns $columns */
|
2016-11-10 14:01:37 +01:00
|
|
|
$columns = $gridField->getConfig()->getComponentByType(GridFieldDataColumns::class);
|
2016-07-12 05:43:48 +02:00
|
|
|
|
|
|
|
$page = new ReportTest_FakeObject();
|
|
|
|
$page->Title = 'My Object';
|
|
|
|
$page->ID = 959547;
|
|
|
|
|
|
|
|
$titleContent = $columns->getColumnContent($gridField, $page, 'Title');
|
2016-11-10 14:01:37 +01:00
|
|
|
$this->assertEquals('<a class="grid-field__link-block" href="dummy-edit-link/959547" title="My Object">My Object</a>', $titleContent);
|
2016-07-12 05:43:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ReportTest_FakeObject extends DataObject implements CMSPreviewable, TestOnly {
|
|
|
|
|
|
|
|
private static $db = array(
|
|
|
|
'Title' => 'Varchar'
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return String Absolute URL to the end-user view for this record.
|
|
|
|
* Example: http://mysite.com/my-record
|
|
|
|
*/
|
|
|
|
public function Link()
|
|
|
|
{
|
|
|
|
return Controller::join_links('dummy-link', $this->ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function CMSEditLink()
|
|
|
|
{
|
|
|
|
return Controller::join_links('dummy-edit-link', $this->ID);
|
|
|
|
}
|
2016-11-10 12:53:48 +01:00
|
|
|
|
|
|
|
public function PreviewLink($action = null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMimeType() {
|
|
|
|
return 'text/html';
|
2016-07-29 00:44:00 +02:00
|
|
|
}
|
2013-01-17 01:22:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package reports
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2016-09-09 08:11:38 +02:00
|
|
|
class ReportTest_FakeTest extends Report implements TestOnly
|
2015-12-15 23:06:45 +01:00
|
|
|
{
|
|
|
|
public function title()
|
|
|
|
{
|
2016-07-29 00:44:00 +02:00
|
|
|
return 'Report title';
|
|
|
|
}
|
2015-12-15 23:06:45 +01:00
|
|
|
public function columns()
|
|
|
|
{
|
2016-07-29 00:44:00 +02:00
|
|
|
return array(
|
|
|
|
"Title" => array(
|
2016-11-10 12:53:48 +01:00
|
|
|
"title" => "Page Title",
|
|
|
|
"link" => true,
|
2016-07-29 00:44:00 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2015-12-15 23:06:45 +01:00
|
|
|
public function sourceRecords($params, $sort, $limit)
|
|
|
|
{
|
2016-07-29 00:44:00 +02:00
|
|
|
return new ArrayList();
|
|
|
|
}
|
2015-12-15 23:06:45 +01:00
|
|
|
|
|
|
|
public function sort()
|
|
|
|
{
|
2016-07-29 00:44:00 +02:00
|
|
|
return 100;
|
|
|
|
}
|
2013-01-17 01:22:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package reports
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2016-09-09 08:11:38 +02:00
|
|
|
class ReportTest_FakeTest2 extends Report implements TestOnly
|
2015-12-15 23:06:45 +01:00
|
|
|
{
|
|
|
|
public function title()
|
|
|
|
{
|
2016-07-29 00:44:00 +02:00
|
|
|
return 'Report title 2';
|
|
|
|
}
|
2015-12-15 23:06:45 +01:00
|
|
|
public function columns()
|
|
|
|
{
|
2016-07-29 00:44:00 +02:00
|
|
|
return array(
|
|
|
|
"Title" => array(
|
|
|
|
"title" => "Page Title 2"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2015-12-15 23:06:45 +01:00
|
|
|
public function sourceRecords($params, $sort, $limit)
|
|
|
|
{
|
2016-07-29 00:44:00 +02:00
|
|
|
return new ArrayList();
|
|
|
|
}
|
2015-12-15 23:06:45 +01:00
|
|
|
|
|
|
|
public function sort()
|
|
|
|
{
|
2016-07-29 00:44:00 +02:00
|
|
|
return 98;
|
|
|
|
}
|
2013-01-17 01:22:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package reports
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2016-09-09 08:11:38 +02:00
|
|
|
abstract class ReportTest_FakeTest_Abstract extends Report implements TestOnly
|
2015-12-15 23:06:45 +01:00
|
|
|
{
|
2016-06-16 07:06:51 +02:00
|
|
|
|
2015-12-15 23:06:45 +01:00
|
|
|
public function title()
|
|
|
|
{
|
2016-07-29 00:44:00 +02:00
|
|
|
return 'Report title Abstract';
|
|
|
|
}
|
2015-12-15 23:06:45 +01:00
|
|
|
|
|
|
|
public function columns()
|
|
|
|
{
|
2016-07-29 00:44:00 +02:00
|
|
|
return array(
|
|
|
|
"Title" => array(
|
|
|
|
"title" => "Page Title Abstract"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2015-12-15 23:06:45 +01:00
|
|
|
public function sourceRecords($params, $sort, $limit)
|
|
|
|
{
|
2016-07-29 00:44:00 +02:00
|
|
|
return new ArrayList();
|
|
|
|
}
|
2015-12-15 23:06:45 +01:00
|
|
|
|
|
|
|
public function sort()
|
|
|
|
{
|
2016-07-29 00:44:00 +02:00
|
|
|
return 5;
|
|
|
|
}
|
2013-01-17 01:22:13 +01:00
|
|
|
}
|