silverstripe-framework/admin/tests/ModelAdminTest.php

90 lines
2.1 KiB
PHP
Raw Normal View History

<?php
2016-10-14 03:30:05 +02:00
namespace SilverStripe\Admin\Tests;
use SilverStripe\ORM\DataObject;
2016-06-23 01:37:22 +02:00
use SilverStripe\Security\Permission;
2016-08-11 01:14:02 +02:00
use SilverStripe\Admin\ModelAdmin;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Dev\TestOnly;
2016-10-14 03:30:05 +02:00
class ModelAdminTest extends FunctionalTest {
protected static $fixture_file = 'ModelAdminTest.yml';
2014-08-15 08:53:05 +02:00
protected $extraDataObjects = array(
'ModelAdminTest_Admin',
'ModelAdminTest_Contact',
'ModelAdminTest_Player'
);
2014-08-15 08:53:05 +02:00
public function testModelAdminOpens() {
$this->autoFollowRedirection = false;
$this->logInAs('admin');
$this->assertTrue((bool)Permission::check("ADMIN"));
$this->assertEquals(200, $this->get('ModelAdminTest_Admin')->getStatusCode());
}
public function testExportFieldsDefaultIsSummaryFields() {
$admin = new ModelAdminTest_Admin();
$admin->doInit();
$this->assertEquals(
$admin->getExportFields(),
ModelAdminTest_Contact::singleton()->summaryFields()
);
}
public function testExportFieldsOverloadedMethod() {
$admin = new ModelAdminTest_PlayerAdmin();
$admin->doInit();
$this->assertEquals($admin->getExportFields(), array(
'Name' => 'Name',
'Position' => 'Position'
));
}
}
class ModelAdminTest_Admin extends ModelAdmin implements TestOnly {
private static $url_segment = 'testadmin';
2014-08-15 08:53:05 +02:00
private static $managed_models = array(
'ModelAdminTest_Contact',
);
}
class ModelAdminTest_PlayerAdmin extends ModelAdmin implements TestOnly {
private static $url_segment = 'testadmin';
private static $managed_models = array(
'ModelAdminTest_Player'
);
public function getExportFields() {
return array(
'Name' => 'Name',
'Position' => 'Position'
);
}
}
class ModelAdminTest_Contact extends DataObject implements TestOnly {
private static $db = array(
'Name' => 'Varchar',
'Phone' => 'Varchar',
);
private static $summary_fields = array(
'Name' => 'Name',
'Phone' => 'Phone'
);
}
class ModelAdminTest_Player extends DataObject implements TestOnly {
private static $db = array(
'Name' => 'Varchar',
'Position' => 'Varchar',
);
private static $has_one = array(
'Contact' => 'ModelAdminTest_Contact'
);
}