2011-03-23 10:51:00 +01:00
|
|
|
<?php
|
|
|
|
|
2016-06-15 06:03:16 +02:00
|
|
|
use SilverStripe\ORM\DataObject;
|
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
class ModelAdminTest extends FunctionalTest {
|
2013-03-21 19:48:54 +01:00
|
|
|
protected static $fixture_file = 'ModelAdminTest.yml';
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
protected $extraDataObjects = array(
|
|
|
|
'ModelAdminTest_Admin',
|
|
|
|
'ModelAdminTest_Contact',
|
2012-03-25 09:01:43 +02:00
|
|
|
'ModelAdminTest_Player'
|
2011-03-23 10:51:00 +01:00
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testModelAdminOpens() {
|
2011-03-23 10:51:00 +01:00
|
|
|
$this->autoFollowRedirection = false;
|
|
|
|
$this->logInAs('admin');
|
|
|
|
$this->assertTrue((bool)Permission::check("ADMIN"));
|
|
|
|
$this->assertEquals(200, $this->get('ModelAdminTest_Admin')->getStatusCode());
|
|
|
|
}
|
2012-03-25 09:01:43 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testExportFieldsDefaultIsSummaryFields() {
|
2012-03-25 09:01:43 +02:00
|
|
|
$admin = new ModelAdminTest_Admin();
|
|
|
|
$admin->modelClass = 'ModelAdminTest_Contact';
|
|
|
|
$this->assertEquals($admin->getExportFields(), singleton('ModelAdminTest_Contact')->summaryFields());
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testExportFieldsOverloadedMethod() {
|
2012-03-25 09:01:43 +02:00
|
|
|
$admin = new ModelAdminTest_PlayerAdmin();
|
|
|
|
$admin->modelClass = 'ModelAdminTest_Player';
|
|
|
|
$this->assertEquals($admin->getExportFields(), array(
|
|
|
|
'Name' => 'Name',
|
|
|
|
'Position' => 'Position'
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class ModelAdminTest_Admin extends ModelAdmin implements TestOnly {
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $url_segment = 'testadmin';
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $managed_models = array(
|
2011-03-23 10:51:00 +01:00
|
|
|
'ModelAdminTest_Contact',
|
|
|
|
);
|
|
|
|
}
|
2012-03-25 09:01:43 +02:00
|
|
|
class ModelAdminTest_PlayerAdmin extends ModelAdmin implements TestOnly {
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $url_segment = 'testadmin';
|
2012-03-25 09:01:43 +02:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $managed_models = array(
|
2012-03-25 09:01:43 +02:00
|
|
|
'ModelAdminTest_Player'
|
|
|
|
);
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2012-03-25 09:01:43 +02:00
|
|
|
public function getExportFields() {
|
|
|
|
return array(
|
|
|
|
'Name' => 'Name',
|
|
|
|
'Position' => 'Position'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2011-03-23 10:51:00 +01:00
|
|
|
class ModelAdminTest_Contact extends DataObject implements TestOnly {
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $db = array(
|
2012-03-25 09:01:43 +02:00
|
|
|
'Name' => 'Varchar',
|
|
|
|
'Phone' => 'Varchar',
|
|
|
|
);
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $summary_fields = array(
|
2012-03-25 09:01:43 +02:00
|
|
|
'Name' => 'Name',
|
|
|
|
'Phone' => 'Phone'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
class ModelAdminTest_Player extends DataObject implements TestOnly {
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $db = array(
|
2012-03-25 09:01:43 +02:00
|
|
|
'Name' => 'Varchar',
|
|
|
|
'Position' => 'Varchar',
|
2011-03-23 10:51:00 +01:00
|
|
|
);
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $has_one = array(
|
2012-03-25 09:01:43 +02:00
|
|
|
'Contact' => 'ModelAdminTest_Contact'
|
|
|
|
);
|
|
|
|
}
|