2017-05-03 03:26:17 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class DMSDocumentAdminTest extends FunctionalTest
|
|
|
|
{
|
2017-05-29 00:15:21 +02:00
|
|
|
protected static $fixture_file = 'DMSDocumentAdminTest.yml';
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
}
|
|
|
|
|
2017-05-03 03:26:17 +02:00
|
|
|
/**
|
2017-06-14 01:05:19 +02:00
|
|
|
* Check that the default "add new" and "edit" buttons are gone, and replaced with our customised version of it
|
2017-05-03 03:26:17 +02:00
|
|
|
*/
|
2017-06-14 01:05:19 +02:00
|
|
|
public function testGridFieldHasCustomisedButtons()
|
2017-05-03 03:26:17 +02:00
|
|
|
{
|
|
|
|
$modelAdmin = new DMSDocumentAdmin;
|
|
|
|
$modelAdmin->init();
|
|
|
|
|
|
|
|
$form = $modelAdmin->getEditForm();
|
|
|
|
$gridFieldConfig = $form->Fields()->first()->getConfig();
|
|
|
|
|
2017-06-14 01:05:19 +02:00
|
|
|
$replacements = array(
|
|
|
|
'GridFieldAddNewButton'=>'DMSGridFieldAddNewButton',
|
|
|
|
'GridFieldEditButton'=>'DMSGridFieldEditButton'
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($replacements as $oldClass => $newClass) {
|
|
|
|
// Our button is an instance of the original, so is returned when asking for the original
|
|
|
|
$newButtons = $gridFieldConfig->getComponentsByType($oldClass);
|
|
|
|
foreach ($newButtons as $key => $newButton) {
|
|
|
|
if ($newButton instanceof $newClass) {
|
|
|
|
// Remove our version for testing's sake
|
|
|
|
$newButtons->remove($newButton);
|
|
|
|
}
|
2017-05-03 03:26:17 +02:00
|
|
|
}
|
|
|
|
|
2017-06-14 01:05:19 +02:00
|
|
|
$this->assertCount(0, $newButtons, 'Original button is removed');
|
|
|
|
$this->assertInstanceOf(
|
|
|
|
$newClass,
|
|
|
|
$gridFieldConfig->getComponentByType($newClass),
|
|
|
|
"Model admin for documents contains customised {$newClass} button"
|
|
|
|
);
|
|
|
|
}
|
2017-05-03 03:26:17 +02:00
|
|
|
}
|
2017-05-29 00:15:21 +02:00
|
|
|
|
2017-06-14 01:05:19 +02:00
|
|
|
|
|
|
|
|
2017-05-29 00:15:21 +02:00
|
|
|
/**
|
|
|
|
* Quick check to ensure that the ModelAdmin endpoint is working
|
|
|
|
*/
|
|
|
|
public function testModelAdminEndpointWorks()
|
|
|
|
{
|
|
|
|
$this->assertEquals(200, $this->get('admin/documents')->getStatusCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that the document sets GridField has a data column for the parent page title. Here we check for the
|
|
|
|
* Page title existing in the DOM, since "Page" is guaranteed to exist somewhere else.
|
|
|
|
*/
|
|
|
|
public function testDocumentSetsGridFieldHasParentPageColumn()
|
|
|
|
{
|
|
|
|
$result = (string) $this->get('admin/documents/DMSDocumentSet')->getBody();
|
|
|
|
$this->assertContains('Home Test Page', $result);
|
|
|
|
$this->assertContains('About Us Test Page', $result);
|
|
|
|
}
|
2017-06-06 23:31:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks that the document sets GridField has a data column which links to the DocumentSets tab on
|
|
|
|
* the actual page in the CMS
|
|
|
|
*/
|
|
|
|
public function testDocumentSetsGridFieldHasLinkToCMSPageEditor()
|
|
|
|
{
|
|
|
|
$result = (string)$this->get('admin/documents/DMSDocumentSet')->getBody();
|
|
|
|
$this->assertContains(
|
|
|
|
"<a class='dms-doc-sets-link'",
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
}
|
2017-05-03 03:26:17 +02:00
|
|
|
}
|