Skip to content

Commit

Permalink
Merge 3.3 into 3.4
Browse files Browse the repository at this point in the history
# Conflicts:
#	code/Report.php
  • Loading branch information
Damian Mooyman committed Aug 5, 2016
2 parents 6c1f17d + c6fdf44 commit f17fad1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
18 changes: 15 additions & 3 deletions code/Report.php
Expand Up @@ -219,7 +219,7 @@ static public function get_reports() {
*/
public function getCMSFields() {
$fields = new FieldList();

if($description = $this->description()) {
$fields->push(new LiteralField('ReportDescription', "<p>" . $description . "</p>"));
}
Expand Down Expand Up @@ -288,8 +288,20 @@ public function getReportField() {
if(isset($info['casting'])) $fieldCasting[$source] = $info['casting'];

if(isset($info['link']) && $info['link']) {
$link = singleton('CMSPageEditController')->Link('show');
$fieldFormatting[$source] = '<a href=\"' . $link . '/$ID\">$value</a>';
$fieldFormatting[$source] = function($value, $item) {
$title = Convert::raw2xml($value);

// If this item is previewable, decorate with link
if ($item instanceof CMSPreviewable) {
return sprintf(
'<a href="%s" title="%s">%s</a>',
$item->CMSEditLink(), $title, $title
);
}

// Fall back to basic title
return $title;
};
}

$displayFields[$source] = isset($info['title']) ? $info['title'] : $source;
Expand Down
43 changes: 41 additions & 2 deletions tests/ReportTest.php
Expand Up @@ -6,6 +6,8 @@
*/
class ReportTest extends SapphireTest {

protected $usesDatabase = true;

public function testGetReports() {
$reports = SS_Report::get_reports();
$this->assertNotNull($reports, "Reports returned");
Expand Down Expand Up @@ -76,6 +78,42 @@ public function testPermissions() {
$this->logInWithPermission('ADMIN');
$this->assertTrue($report->canView());
}

public function testColumnLink() {
$report = new ReportTest_FakeTest();
/** @var GridField $gridField */
$gridField = $report->getReportField();
/** @var GridFieldDataColumns $columns */
$columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');

$page = new ReportTest_FakeObject();
$page->Title = 'My Object';
$page->ID = 959547;

$titleContent = $columns->getColumnContent($gridField, $page, 'Title');
$this->assertEquals('<a href="dummy-edit-link/959547" title="My Object">My Object</a>', $titleContent);
}
}

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);
}
}

/**
Expand All @@ -89,7 +127,8 @@ public function title() {
public function columns() {
return array(
"Title" => array(
"title" => "Page Title"
"title" => "Page Title",
"link" => true,
)
);
}
Expand Down Expand Up @@ -131,7 +170,7 @@ public function sort() {
* @subpackage tests
*/
abstract class ReportTest_FakeTest_Abstract extends SS_Report implements TestOnly {

public function title() {
return 'Report title Abstract';
}
Expand Down

0 comments on commit f17fad1

Please sign in to comment.