From 56346a50bf161a2a840517cf8bf5d38cf8174103 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Thu, 17 Jan 2013 13:27:14 +1300 Subject: [PATCH] API: moved reports API to separate module --- code/reports/BrokenFilesReport.php | 45 ++ code/reports/BrokenRedirectorPagesReport.php | 39 ++ code/reports/BrokenVirtualPagesReport.php | 43 ++ code/reports/EmptyPagesReport.php | 35 ++ code/reports/RecentlyEditedReport.php | 34 ++ code/reports/Report.php | 429 ------------------ code/reports/SideReport.php | 328 ------------- composer.json | 3 +- javascript/ReportAdmin.Tree.js | 24 - javascript/ReportAdmin.js | 19 - ...{SideReportTest.php => CmsReportsTest.php} | 12 +- ...{SideReportTest.yml => CmsReportsTest.yml} | 0 tests/reports/ReportTest.php | 117 ----- tests/travis/before_script | 3 + 14 files changed, 207 insertions(+), 924 deletions(-) create mode 100644 code/reports/BrokenFilesReport.php create mode 100644 code/reports/BrokenRedirectorPagesReport.php create mode 100644 code/reports/BrokenVirtualPagesReport.php create mode 100644 code/reports/EmptyPagesReport.php create mode 100644 code/reports/RecentlyEditedReport.php delete mode 100644 code/reports/Report.php delete mode 100644 code/reports/SideReport.php delete mode 100644 javascript/ReportAdmin.Tree.js delete mode 100644 javascript/ReportAdmin.js rename tests/reports/{SideReportTest.php => CmsReportsTest.php} (75%) rename tests/reports/{SideReportTest.yml => CmsReportsTest.yml} (100%) delete mode 100644 tests/reports/ReportTest.php diff --git a/code/reports/BrokenFilesReport.php b/code/reports/BrokenFilesReport.php new file mode 100644 index 00000000..fe4e5235 --- /dev/null +++ b/code/reports/BrokenFilesReport.php @@ -0,0 +1,45 @@ + array( + "title" => "Title", // todo: use NestedTitle(2) + "link" => true, + ), + ); + } + + public function getParameterFields() { + return new FieldList( + new CheckboxField('OnLive', _t('SideReport.ParameterLiveCheckbox', 'Check live site')) + ); + } +} \ No newline at end of file diff --git a/code/reports/BrokenRedirectorPagesReport.php b/code/reports/BrokenRedirectorPagesReport.php new file mode 100644 index 00000000..56c14425 --- /dev/null +++ b/code/reports/BrokenRedirectorPagesReport.php @@ -0,0 +1,39 @@ + array( + "title" => "Title", // todo: use NestedTitle(2) + "link" => true, + ), + ); + } + + public function getParameterFields() { + return new FieldList( + new CheckboxField('OnLive', _t('SideReport.ParameterLiveCheckbox', 'Check live site')) + ); + } +} diff --git a/code/reports/BrokenVirtualPagesReport.php b/code/reports/BrokenVirtualPagesReport.php new file mode 100644 index 00000000..f187d90f --- /dev/null +++ b/code/reports/BrokenVirtualPagesReport.php @@ -0,0 +1,43 @@ + array( + "title" => "Title", // todo: use NestedTitle(2) + "link" => true, + ), + ); + } + + public function getParameterFields() { + return new FieldList( + new CheckboxField('OnLive', _t('SideReport.ParameterLiveCheckbox', 'Check live site')) + ); + } +} \ No newline at end of file diff --git a/code/reports/EmptyPagesReport.php b/code/reports/EmptyPagesReport.php new file mode 100644 index 00000000..ed718660 --- /dev/null +++ b/code/reports/EmptyPagesReport.php @@ -0,0 +1,35 @@ +where( + "\"ClassName\" != 'RedirectorPage' AND (\"Content\" = '' OR \"Content\" IS NULL OR \"Content\" LIKE '

' OR \"Content\" LIKE '

 

')" + )->sort('Title'); + } + + public function columns() { + return array( + "Title" => array( + "title" => "Title", // todo: use NestedTitle(2) + "link" => true, + ), + ); + } +} \ No newline at end of file diff --git a/code/reports/RecentlyEditedReport.php b/code/reports/RecentlyEditedReport.php new file mode 100644 index 00000000..65d1664c --- /dev/null +++ b/code/reports/RecentlyEditedReport.php @@ -0,0 +1,34 @@ +Format('U')); + return DataObject::get("SiteTree", "\"SiteTree\".\"LastEdited\" > '".date("Y-m-d H:i:s", $threshold)."'", "\"SiteTree\".\"LastEdited\" DESC"); + } + + public function columns() { + return array( + "Title" => array( + "title" => "Title", // todo: use NestedTitle(2) + "link" => true, + ), + ); + } +} \ No newline at end of file diff --git a/code/reports/Report.php b/code/reports/Report.php deleted file mode 100644 index 08d005fc..00000000 --- a/code/reports/Report.php +++ /dev/null @@ -1,429 +0,0 @@ -title; - } - - /** - * Return the description of this report. - * - * You have two ways of specifying the description: - * - overriding description(), which lets you support i18n - * - defining the $description property - */ - public function description() { - return $this->description; - } - - /** - * Return the {@link SQLQuery} that provides your report data. - */ - public function sourceQuery($params) { - if($this->hasMethod('sourceRecords')) { - return $this->sourceRecords()->dataQuery(); - } else { - user_error("Please override sourceQuery()/sourceRecords() and columns() or, if necessary, override getReportField()", E_USER_ERROR); - } - } - - /** - * Return a SS_List records for this report. - */ - public function records($params) { - if($this->hasMethod('sourceRecords')) { - return $this->sourceRecords($params, null, null); - } else { - $query = $this->sourceQuery(); - $results = new ArrayList(); - foreach($query->execute() as $data) { - $class = $this->dataClass(); - $result = new $class($data); - $results->push($result); - } - return $results; - } - } - - /** - * Return the data class for this report - */ - public function dataClass() { - return $this->dataClass; - } - - public function getLink($action = null) { - return Controller::join_links( - 'admin/reports/', - "$this->class", - '/', // trailing slash needed if $action is null! - "$action" - ); - } - - /** - * Exclude certain reports classes from the list of Reports in the CMS - * @param $reportClass Can be either a string with the report classname or an array of reports classnames - */ - static public function add_excluded_reports($reportClass) { - if (is_array($reportClass)) { - self::$excluded_reports = array_merge(self::$excluded_reports, $reportClass); - } else { - if (is_string($reportClass)) { - //add to the excluded reports, so this report doesn't get used - self::$excluded_reports[] = $reportClass; - } - } - } - - /** - * Return an array of excluded reports. That is, reports that will not be included in - * the list of reports in report admin in the CMS. - * @return array - */ - static public function get_excluded_reports() { - return self::$excluded_reports; - } - - /** - * Return the SS_Report objects making up the given list. - * @return Array of SS_Report objects - */ - static public function get_reports() { - $reports = ClassInfo::subclassesFor(get_called_class()); - - $reportsArray = array(); - if ($reports && count($reports) > 0) { - //collect reports into array with an attribute for 'sort' - foreach($reports as $report) { - if (in_array($report, self::$excluded_reports)) continue; //don't use the SS_Report superclass - $reflectionClass = new ReflectionClass($report); - if ($reflectionClass->isAbstract()) continue; //don't use abstract classes - - $reportObj = new $report; - if (method_exists($reportObj,'sort')) $reportObj->sort = $reportObj->sort(); //use the sort method to specify the sort field - $reportsArray[$report] = $reportObj; - } - } - - uasort($reportsArray, function($a, $b) { - if($a->sort == $b->sort) return 0; - else return ($a->sort < $b->sort) ? -1 : 1; - }); - - return $reportsArray; - } - - /////////////////////// UI METHODS /////////////////////// - - - /** - * Returns a FieldList with which to create the CMS editing form. - * You can use the extend() method of FieldList to create customised forms for your other - * data objects. - * - * @uses getReportField() to render a table, or similar field for the report. This - * method should be defined on the SS_Report subclasses. - * - * @return FieldList - */ - public function getCMSFields() { - $fields = new FieldList(); - - if($title = $this->title()) { - $fields->push(new LiteralField('ReportTitle', "

{$title}

")); - } - - if($description = $this->description()) { - $fields->push(new LiteralField('ReportDescription', "

" . $description . "

")); - } - - // Add search fields is available - if($this->hasMethod('parameterFields') && $fields = $this->parameterFields()) { - foreach($fields as $field) { - // Namespace fields for easier handling in form submissions - $field->setName(sprintf('filters[%s]', $field->getName())); - $field->addExtraClass('no-change-track'); // ignore in changetracker - $fields->push($field); - } - - // Add a search button - $fields->push(new FormAction('updatereport', _t('GridField.Filter'))); - } - - $fields->push($this->getReportField()); - - $this->extend('updateCMSFields', $fields); - - return $fields; - } - - public function getCMSActions() { - // getCMSActions() can be extended with updateCMSActions() on a extension - $actions = new FieldList(); - $this->extend('updateCMSActions', $actions); - return $actions; - } - - /** - * Return a field, such as a {@link GridField} that is - * used to show and manipulate data relating to this report. - * - * Generally, you should override {@link columns()} and {@link records()} to make your report, - * but if they aren't sufficiently flexible, then you can override this method. - * - * @return FormField subclass - */ - public function getReportField() { - // TODO Remove coupling with global state - $params = isset($_REQUEST['filters']) ? $_REQUEST['filters'] : array(); - $items = $this->sourceRecords($params, null, null); - - $gridFieldConfig = GridFieldConfig::create()->addComponents( - new GridFieldToolbarHeader(), - new GridFieldSortableHeader(), - new GridFieldDataColumns(), - new GridFieldPaginator(), - new GridFieldPrintButton(), - new GridFieldExportButton() - ); - $gridField = new GridField('Report',$this->title(), $items, $gridFieldConfig); - $columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns'); - $displayFields = array(); - $fieldCasting = array(); - $fieldFormatting = array(); - - // Parse the column information - foreach($this->columns() as $source => $info) { - if(is_string($info)) $info = array('title' => $info); - - if(isset($info['formatting'])) $fieldFormatting[$source] = $info['formatting']; - if(isset($info['csvFormatting'])) $csvFieldFormatting[$source] = $info['csvFormatting']; - if(isset($info['casting'])) $fieldCasting[$source] = $info['casting']; - - if(isset($info['link']) && $info['link']) { - $link = singleton('CMSPageEditController')->Link('show'); - $fieldFormatting[$source] = '$value'; - } - - $displayFields[$source] = isset($info['title']) ? $info['title'] : $source; - } - $columns->setDisplayFields($displayFields); - $columns->setFieldCasting($fieldCasting); - $columns->setFieldFormatting($fieldFormatting); - - return $gridField; - } - - /** - * @param Member $member - * @return boolean - */ - public function canView($member = null) { - if(!$member && $member !== FALSE) { - $member = Member::currentUser(); - } - - return true; - } - - - /** - * Return the name of this report, which - * is used by the templates to render the - * name of the report in the report tree, - * the left hand pane inside ReportAdmin. - * - * @return string - */ - public function TreeTitle() { - return $this->title(); - } - -} - -/** - * SS_ReportWrapper is a base class for creating report wappers. - * - * Wrappers encapsulate an existing report to alter their behaviour - they are implementations of - * the standard GoF decorator pattern. - * - * This base class ensure that, by default, wrappers behave in the same way as the report that is - * being wrapped. You should override any methods that need to behave differently in your subclass - * of SS_ReportWrapper. - * - * It also makes calls to 2 empty methods that you can override {@link beforeQuery()} and - * {@link afterQuery()} - * - * @package cms - * @subpackage reports - */ -abstract class SS_ReportWrapper extends SS_Report { - protected $baseReport; - - public function __construct($baseReport) { - $this->baseReport = is_string($baseReport) ? new $baseReport : $baseReport; - $this->dataClass = $this->baseReport->dataClass(); - parent::__construct(); - } - - public function ID() { - return get_class($this->baseReport) . '_' . get_class($this); - } - - /////////////////////////////////////////////////////////////////////////////////////////// - // Filtering - - public function parameterFields() { - return $this->baseReport->parameterFields(); - } - - /////////////////////////////////////////////////////////////////////////////////////////// - // Columns - - public function columns() { - return $this->baseReport->columns(); - } - - /////////////////////////////////////////////////////////////////////////////////////////// - // Querying - - /** - * Override this method to perform some actions prior to querying. - */ - public function beforeQuery($params) { - } - - /** - * Override this method to perform some actions after querying. - */ - public function afterQuery() { - } - - public function sourceQuery($params) { - if($this->baseReport->hasMethod('sourceRecords')) { - // The default implementation will create a fake query from our sourceRecords() method - return parent::sourceQuery($params); - - } else if($this->baseReport->hasMethod('sourceQuery')) { - $this->beforeQuery($params); - $query = $this->baseReport->sourceQuery($params); - $this->afterQuery(); - return $query; - - } else { - user_error("Please override sourceQuery()/sourceRecords() and columns() in your base report", E_USER_ERROR); - } - - } - - public function sourceRecords($params = array(), $sort = null, $limit = null) { - $this->beforeQuery($params); - $records = $this->baseReport->sourceRecords($params, $sort, $limit); - $this->afterQuery(); - return $records; - } - - - /////////////////////////////////////////////////////////////////////////////////////////// - // Pass-through - - public function title() { - return $this->baseReport->title(); - } - - public function group() { - return $this->baseReport->hasMethod('group') ? $this->baseReport->group() : 'Group'; - } - - public function sort() { - return $this->baseReport->hasMethod('sort') ? $this->baseReport->sort() : 0; - } - - public function description() { - return $this->baseReport->description(); - } - - public function canView($member = null) { - return $this->baseReport->canView($member); - } - -} - - diff --git a/code/reports/SideReport.php b/code/reports/SideReport.php deleted file mode 100644 index 3e119c65..00000000 --- a/code/reports/SideReport.php +++ /dev/null @@ -1,328 +0,0 @@ -controller = $controller; - $this->report = $report; - parent::__construct(); - } - - public function group() { - return _t('SideReport.OtherGroupTitle', "Other"); - } - - public function sort() { - return 0; - } - - public function setParameters($parameters) { - $this->parameters = $parameters; - } - - public function forTemplate() { - $records = $this->report->records($this->parameters); - $columns = $this->report->columns(); - - if($records && $records->Count()) { - $result = "\n"; - } else { - $result = "

" . - _t( - 'SideReport.REPEMPTY', - 'The {title} report is empty.', - array('title' => $this->report->title()) - ) - . "

"; - } - return $result; - } - - protected function formatValue($record, $source, $info) { - // Field sources - //if(is_string($source)) { - $val = Convert::raw2xml($record->$source); - //} else { - // $val = $record->val($source[0], $source[1]); - //} - - // Casting, a la TableListField. We're deep-calling a helper method on TableListField that - // should probably be pushed elsewhere... - if(!empty($info['casting'])) { - $val = TableListField::getCastedValue($val, $info['casting']); - } - - // Formatting, a la TableListField - if(!empty($info['formatting'])) { - $format = str_replace('$value', "__VAL__", $info['formatting']); - $format = preg_replace('/\$([A-Za-z0-9-_]+)/','$record->$1', $format); - $format = str_replace('__VAL__', '$val', $format); - $val = eval('return "' . $format . '";'); - } - - $prefix = empty($info['newline']) ? "" : "
"; - - - $classClause = ""; - if(isset($info['title'])) { - $cssClass = preg_replace('/[^A-Za-z0-9]+/', '', $info['title']); - $classClause = "class=\"$cssClass\""; - } - - if(isset($info['link']) && $info['link']) { - $linkBase = singleton('CMSPageEditController')->Link('show') . '/'; - $link = ($info['link'] === true) ? $linkBase . $record->ID : $info['link']; - return $prefix . "$val"; - } else { - return $prefix . "$val"; - } - - } -} - -/** - * A report wrapper that makes it easier to define slightly different behaviour for side-reports. - * - * This report wrapper will use sideReportColumns() for the report columns, instead of columns(). - * - * @package cms - * @subpackage content - */ -class SideReportWrapper extends SS_ReportWrapper { - public function columns() { - if($this->baseReport->hasMethod('sideReportColumns')) { - return $this->baseReport->sideReportColumns(); - } else { - return parent::columns(); - } - } -} - -//////////////////////////////////////////////////////////////////////////////////////////////// - -/** - * Content side-report listing empty pages - * - * @package cms - * @subpackage content - */ -class SideReport_EmptyPages extends SS_Report { - public function title() { - return _t('SideReport.EMPTYPAGES',"Pages with no content"); - } - - public function group() { - return _t('SideReport.ContentGroupTitle', "Content reports"); - } - public function sort() { - return 100; - } - public function sourceRecords($params = null) { - return DataObject::get("SiteTree", "\"ClassName\" != 'RedirectorPage' AND (\"Content\" = '' OR \"Content\" IS NULL OR \"Content\" LIKE '

' OR \"Content\" LIKE '

 

')", '"Title"'); - } - public function columns() { - return array( - "Title" => array( - "title" => "Title", // todo: use NestedTitle(2) - "link" => true, - ), - ); - } -} - -/** - * Content side-report listing recently editing pages. - * - * @package cms - * @subpackage content - */ -class SideReport_RecentlyEdited extends SS_Report { - public function title() { - return _t('SideReport.LAST2WEEKS',"Pages edited in the last 2 weeks"); - } - public function group() { - return _t('SideReport.ContentGroupTitle', "Content reports"); - } - public function sort() { - return 200; - } - public function sourceRecords($params = null) { - $threshold = strtotime('-14 days', SS_Datetime::now()->Format('U')); - return DataObject::get("SiteTree", "\"SiteTree\".\"LastEdited\" > '".date("Y-m-d H:i:s", $threshold)."'", "\"SiteTree\".\"LastEdited\" DESC"); - } - public function columns() { - return array( - "Title" => array( - "title" => "Title", // todo: use NestedTitle(2) - "link" => true, - ), - ); - } -} - -/** - * Content side-report listing pages with broken links - * - * @package cms - * @subpackage content - */ -class SideReport_BrokenLinks extends SS_Report { - public function title() { - return _t('SideReport.BROKENLINKS',"Pages with broken links"); - } - public function group() { - return _t('SideReport.BrokenLinksGroupTitle', "Broken links reports"); - } - public function sourceRecords($params = null) { - // Get class names for page types that are not virtual pages or redirector pages - $classes = array_diff(ClassInfo::subclassesFor('SiteTree'), ClassInfo::subclassesFor('VirtualPage'), ClassInfo::subclassesFor('RedirectorPage')); - $classNames = "'".join("','", $classes)."'"; - - if (isset($_REQUEST['OnLive'])) $ret = Versioned::get_by_stage('SiteTree', 'Live', "\"ClassName\" IN ($classNames) AND \"HasBrokenLink\" = 1"); - else $ret = DataObject::get('SiteTree', "\"ClassName\" IN ($classNames) AND \"HasBrokenLink\" = 1"); - return $ret; - } - public function columns() { - return array( - "Title" => array( - "title" => _t('ReportAdmin.ReportTitle', 'Title'), // todo: use NestedTitle(2) - "link" => true, - ), - ); - } - public function getParameterFields() { - return new FieldList( - new CheckboxField('OnLive', _t('SideReport.ParameterLiveCheckbox', 'Check live site')) - ); - } -} - -/** - * Content side-report listing pages with broken files - * or asset links - * - * @package cms - * @subpackage content - */ -class SideReport_BrokenFiles extends SS_Report { - public function title() { - return _t('SideReport.BROKENFILES',"Pages with broken files"); - } - public function group() { - return _t('SideReport.BrokenLinksGroupTitle', "Broken links reports"); - } - public function sourceRecords($params = null) { - // Get class names for page types that are not virtual pages or redirector pages - $classes = array_diff(ClassInfo::subclassesFor('SiteTree'), ClassInfo::subclassesFor('VirtualPage'), ClassInfo::subclassesFor('RedirectorPage')); - $classNames = "'".join("','", $classes)."'"; - - if (isset($_REQUEST['OnLive'])) $ret = Versioned::get_by_stage('SiteTree', 'Live', "\"ClassName\" IN ($classNames) AND \"HasBrokenFile\" = 1"); - else $ret = DataObject::get('SiteTree', "\"ClassName\" IN ($classNames) AND \"HasBrokenFile\" = 1"); - return $ret; - } - public function columns() { - return array( - "Title" => array( - "title" => "Title", // todo: use NestedTitle(2) - "link" => true, - ), - ); - } - - public function getParameterFields() { - return new FieldList( - new CheckboxField('OnLive', _t('SideReport.ParameterLiveCheckbox', 'Check live site')) - ); - } -} - -/** - * @package cms - * @subpackage content - */ -class SideReport_BrokenVirtualPages extends SS_Report { - public function title() { - return _t('SideReport.BROKENVIRTUALPAGES', 'VirtualPages pointing to deleted pages'); - } - public function group() { - return _t('SideReport.BrokenLinksGroupTitle', "Broken links reports"); - } - public function sourceRecords($params = null) { - $classNames = "'".join("','", ClassInfo::subclassesFor('VirtualPage'))."'"; - if (isset($_REQUEST['OnLive'])) $ret = Versioned::get_by_stage('SiteTree', 'Live', "\"ClassName\" IN ($classNames) AND \"HasBrokenLink\" = 1"); - else $ret = DataObject::get('SiteTree', "\"ClassName\" IN ($classNames) AND \"HasBrokenLink\" = 1"); - return $ret; - } - - public function columns() { - return array( - "Title" => array( - "title" => "Title", // todo: use NestedTitle(2) - "link" => true, - ), - ); - } - - public function getParameterFields() { - return new FieldList( - new CheckboxField('OnLive', _t('SideReport.ParameterLiveCheckbox', 'Check live site')) - ); - } -} - -/** - * @package cms - * @subpackage content - */ -class SideReport_BrokenRedirectorPages extends SS_Report { - public function title() { - return _t('SideReport.BROKENREDIRECTORPAGES', 'RedirectorPages pointing to deleted pages'); - } - public function group() { - return _t('SideReport.BrokenLinksGroupTitle', "Broken links reports"); - } - public function sourceRecords($params = null) { - $classNames = "'".join("','", ClassInfo::subclassesFor('RedirectorPage'))."'"; - - if (isset($_REQUEST['OnLive'])) $ret = Versioned::get_by_stage('SiteTree', 'Live', "\"ClassName\" IN ($classNames) AND \"HasBrokenLink\" = 1"); - else $ret = DataObject::get('SiteTree', "\"ClassName\" IN ($classNames) AND \"HasBrokenLink\" = 1"); - return $ret; - } - - public function columns() { - return array( - "Title" => array( - "title" => "Title", // todo: use NestedTitle(2) - "link" => true, - ), - ); - } - - public function getParameterFields() { - return new FieldList( - new CheckboxField('OnLive', _t('SideReport.ParameterLiveCheckbox', 'Check live site')) - ); - } -} diff --git a/composer.json b/composer.json index 3e63d8d7..0b49c477 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ "require": { "php": ">=5.3.2", "composer/installers": "*", - "silverstripe/framework": "3.2.x-dev" + "silverstripe/framework": "3.2.x-dev", + "silverstripe/reports": "*" }, "extra": { "branch-alias": { diff --git a/javascript/ReportAdmin.Tree.js b/javascript/ReportAdmin.Tree.js deleted file mode 100644 index a7a93aef..00000000 --- a/javascript/ReportAdmin.Tree.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * File: ReportAdmin.Tree.js - */ -(function($) { - $.entwine('ss.tree', function($){ - /** - * Class: .cms-tree - * - * Tree panel. - */ - $('.cms-tree').entwine({ - onmatch: function() { - // make sure current ID of loaded form is actually selected in tree - var id = $('.cms-edit-form :input[name=ID]').val(); - if (id) this[0].setCurrentByIdx(id); - - this._super(); - }, - onunmatch: function() { - this._super(); - } - }); - }); -}(jQuery)); diff --git a/javascript/ReportAdmin.js b/javascript/ReportAdmin.js deleted file mode 100644 index 5d927a81..00000000 --- a/javascript/ReportAdmin.js +++ /dev/null @@ -1,19 +0,0 @@ -/** - * File: ReportAdmin.js - */ - -(function($) { - $.entwine('ss', function($){ - $('.ReportAdmin .cms-edit-form').entwine({ - onsubmit: function(e) { - var url = $.path.parseUrl(document.location.href).hrefNoSearch, - params = this.find(':input[name^=filters]').serializeArray(); - params = $.grep(params, function(param) {return (param.value);}); // filter out empty - if(params) url = $.path.addSearchParams(url, params); - $('.cms-container').loadPanel(url); - return false; - } - }); - - }); -})(jQuery); diff --git a/tests/reports/SideReportTest.php b/tests/reports/CmsReportsTest.php similarity index 75% rename from tests/reports/SideReportTest.php rename to tests/reports/CmsReportsTest.php index 3e12c1e1..26d334b1 100644 --- a/tests/reports/SideReportTest.php +++ b/tests/reports/CmsReportsTest.php @@ -4,18 +4,18 @@ * @subpackage tests */ -class SideReportTest extends SapphireTest { +class CmsReportsTest extends SapphireTest { - static $fixture_file = 'SideReportTest.yml'; + public static $fixture_file = 'CmsReportsTest.yml'; - static $daysAgo = 14; + public static $daysAgo = 14; public function setUp() { parent::setUp(); // set the dates by hand: impossible to set via yml - $afterThreshold = strtotime('-'.(SideReportTest::$daysAgo-1).' days', strtotime('31-06-2009 00:00:00')); - $beforeThreshold = strtotime('-'.(SideReportTest::$daysAgo+1).' days', strtotime('31-06-2009 00:00:00')); + $afterThreshold = strtotime('-'.(self::$daysAgo-1).' days', strtotime('31-06-2009 00:00:00')); + $beforeThreshold = strtotime('-'.(self::$daysAgo+1).' days', strtotime('31-06-2009 00:00:00')); $after = $this->objFromFixture('SiteTree', 'after'); $before = $this->objFromFixture('SiteTree', 'before'); @@ -30,7 +30,7 @@ class SideReportTest extends SapphireTest { $after = $this->objFromFixture('SiteTree', 'after'); $before = $this->objFromFixture('SiteTree', 'before'); - $r = new SideReport_RecentlyEdited(); + $r = new RecentlyEditedReport(); // check if contains only elements not older than $daysAgo days $this->assertNotNull($r->records(array())); diff --git a/tests/reports/SideReportTest.yml b/tests/reports/CmsReportsTest.yml similarity index 100% rename from tests/reports/SideReportTest.yml rename to tests/reports/CmsReportsTest.yml diff --git a/tests/reports/ReportTest.php b/tests/reports/ReportTest.php deleted file mode 100644 index 67b5de30..00000000 --- a/tests/reports/ReportTest.php +++ /dev/null @@ -1,117 +0,0 @@ -assertNotNull($reports, "Reports returned"); - $previousSort = 0; - foreach($reports as $report) { - $this->assertGreaterThanOrEqual($previousSort, $report->sort, "Reports are in correct sort order"); - $previousSort = $report->sort; - } - } - - public function testExcludeReport() { - $reports = SS_Report::get_reports(); - $reportNames = array(); - foreach($reports as $report) { - $reportNames[] = $report->class; - } - $this->assertContains('ReportTest_FakeTest',$reportNames,'ReportTest_FakeTest is in reports list'); - - //exclude one report - SS_Report::add_excluded_reports('ReportTest_FakeTest'); - - $reports = SS_Report::get_reports(); - $reportNames = array(); - foreach($reports as $report) { - $reportNames[] = $report->class; - } - $this->assertNotContains('ReportTest_FakeTest',$reportNames,'ReportTest_FakeTest is NOT in reports list'); - - //exclude two reports - SS_Report::add_excluded_reports(array('ReportTest_FakeTest','ReportTest_FakeTest2')); - - $reports = SS_Report::get_reports(); - $reportNames = array(); - foreach($reports as $report) { - $reportNames[] = $report->class; - } - $this->assertNotContains('ReportTest_FakeTest',$reportNames,'ReportTest_FakeTest is NOT in reports list'); - $this->assertNotContains('ReportTest_FakeTest2',$reportNames,'ReportTest_FakeTest2 is NOT in reports list'); - } - - public function testAbstractClassesAreExcluded() { - $reports = SS_Report::get_reports(); - $reportNames = array(); - foreach($reports as $report) { - $reportNames[] = $report->class; - } - $this->assertNotContains('ReportTest_FakeTest_Abstract', - $reportNames, - 'ReportTest_FakeTest_Abstract is NOT in reports list as it is abstract'); - } -} - -class ReportTest_FakeTest extends SS_Report implements TestOnly { - public function title() { - return 'Report title'; - } - public function columns() { - return array( - "Title" => array( - "title" => "Page Title" - ) - ); - } - public function sourceRecords($params, $sort, $limit) { - return new ArrayList(); - } - - public function sort() { - return 100; - } -} - - -class ReportTest_FakeTest2 extends SS_Report implements TestOnly { - public function title() { - return 'Report title 2'; - } - public function columns() { - return array( - "Title" => array( - "title" => "Page Title 2" - ) - ); - } - public function sourceRecords($params, $sort, $limit) { - return new ArrayList(); - } - - public function sort() { - return 98; - } -} - -abstract class ReportTest_FakeTest_Abstract extends SS_Report implements TestOnly { - public function title() { - return 'Report title Abstract'; - } - public function columns() { - return array( - "Title" => array( - "title" => "Page Title Abstract" - ) - ); - } - public function sourceRecords($params, $sort, $limit) { - return new ArrayList(); - } - - public function sort() { - return 5; - } -} - diff --git a/tests/travis/before_script b/tests/travis/before_script index 94f244f8..63587ce8 100755 --- a/tests/travis/before_script +++ b/tests/travis/before_script @@ -27,6 +27,9 @@ git clone --depth=100 --quiet git://github.com/silverstripe/silverstripe-postgre echo "Checking out sapphire@$TRAVIS_BRANCH" git clone --depth=100 --quiet -b $TRAVIS_BRANCH git://github.com/silverstripe/sapphire.git $BUILD_DIR/framework +echo "Checking out reports@master" +git clone --depth=100 --quiet git://github.com/silverstripe-labs/silverstripe-reports.git $BUILD_DIR/reports + # Copy setup files cp $BUILD_DIR/framework/tests/travis/_ss_environment.php $BUILD_DIR cp $BUILD_DIR/framework/tests/travis/_config.php $BUILD_DIR/mysite