mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR GridFieldRelationAddTest (SSF-53)
This commit is contained in:
parent
d02a68089f
commit
88039ffb81
@ -371,3 +371,21 @@ class GridFieldTest_Component implements GridField_ColumnProvider, GridField_Act
|
||||
|
||||
|
||||
}
|
||||
|
||||
class GridFieldTest_Team extends DataObject implements TestOnly {
|
||||
static $db = array(
|
||||
'Name' => 'Varchar',
|
||||
'City' => 'Varchar'
|
||||
);
|
||||
|
||||
static $many_many = array('Players' => 'GridFieldTest_Player');
|
||||
}
|
||||
|
||||
class GridFieldTest_Player extends DataObject implements TestOnly {
|
||||
static $db = array(
|
||||
'Name' => 'Varchar',
|
||||
'Email' => 'Varchar',
|
||||
);
|
||||
|
||||
static $belongs_many_many = array('Teams' => 'GridFieldTest_Team');
|
||||
}
|
82
tests/forms/gridfield/GridFieldRelationAddTest.php
Normal file
82
tests/forms/gridfield/GridFieldRelationAddTest.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
class GridFieldRelationAddTest extends FunctionalTest {
|
||||
|
||||
static $fixture_file = 'sapphire/tests/forms/gridfield/GridFieldTest.yml';
|
||||
|
||||
protected $extraDataObjects = array('GridFieldTest_Team', 'GridFieldTest_Player');
|
||||
|
||||
function testSearch() {
|
||||
$team1 = $this->objFromFixture('GridFieldTest_Team', 'team1');
|
||||
$team2 = $this->objFromFixture('GridFieldTest_Team', 'team2');
|
||||
|
||||
$response = $this->get('GridFieldRelationAddTest_Controller');
|
||||
$this->assertFalse($response->isError());
|
||||
$parser = new CSSContentParser($response->getBody());
|
||||
$btns = $parser->getBySelector('.ss-gridfield #action_gridfield_relationfind');
|
||||
|
||||
$response = $this->post(
|
||||
'GridFieldRelationAddTest_Controller/Form/field/testfield/search/Team 2',
|
||||
array(
|
||||
(string)$btns[0]['name'] => 1
|
||||
)
|
||||
);
|
||||
$this->assertFalse($response->isError());
|
||||
$result = Convert::json2array($response->getBody());
|
||||
$this->assertEquals(1, count($result));
|
||||
$this->assertEquals(array($team2->ID => 'Team 2'), $result);
|
||||
|
||||
$response = $this->post(
|
||||
'GridFieldRelationAddTest_Controller/Form/field/testfield/search/Unknown',
|
||||
array(
|
||||
(string)$btns[0]['name'] => 1
|
||||
)
|
||||
);
|
||||
$this->assertFalse($response->isError());
|
||||
$result = Convert::json2array($response->getBody());
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
function testAdd() {
|
||||
$team1 = $this->objFromFixture('GridFieldTest_Team', 'team1');
|
||||
$team2 = $this->objFromFixture('GridFieldTest_Team', 'team2');
|
||||
|
||||
$response = $this->get('GridFieldRelationAddTest_Controller');
|
||||
$this->assertFalse($response->isError());
|
||||
$parser = new CSSContentParser($response->getBody());
|
||||
$items = $parser->getBySelector('.ss-gridfield .ss-gridfield-items .ss-gridfield-item');
|
||||
$this->assertEquals(1, count($items));
|
||||
$this->assertEquals($team1->ID, (int)$items[0]['data-id']);
|
||||
|
||||
$btns = $parser->getBySelector('.ss-gridfield #action_gridfield_relationadd');
|
||||
$response = $this->post(
|
||||
'GridFieldRelationAddTest_Controller/Form/field/testfield',
|
||||
array(
|
||||
'relationID' => $team2->ID,
|
||||
(string)$btns[0]['name'] => 1
|
||||
)
|
||||
);
|
||||
$this->assertFalse($response->isError());
|
||||
$parser = new CSSContentParser($response->getBody());
|
||||
$items = $parser->getBySelector('.ss-gridfield .ss-gridfield-items .ss-gridfield-item');
|
||||
$this->assertEquals(2, count($items));
|
||||
$this->assertEquals($team1->ID, (int)$items[0]['data-id']);
|
||||
$this->assertEquals($team2->ID, (int)$items[1]['data-id']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class GridFieldRelationAddTest_Controller extends Controller implements TestOnly {
|
||||
|
||||
protected $template = 'BlankPage';
|
||||
|
||||
function Form() {
|
||||
$player = DataObject::get('GridFieldTest_Player')->find('Email', 'player1@test.com');
|
||||
$config = GridFieldConfig::create()->addComponents(
|
||||
$relationComponent = new GridFieldRelationAdd('Name'),
|
||||
new GridFieldDefaultColumns()
|
||||
);
|
||||
$field = new GridField('testfield', 'testfield', $player->Teams(), $config);
|
||||
return new Form($this, 'Form', new FieldList($field), new FieldList());
|
||||
}
|
||||
}
|
18
tests/forms/gridfield/GridFieldTest.yml
Normal file
18
tests/forms/gridfield/GridFieldTest.yml
Normal file
@ -0,0 +1,18 @@
|
||||
GridFieldTest_Team:
|
||||
team1:
|
||||
Name: Team 1
|
||||
City: Cologne
|
||||
team2:
|
||||
Name: Team 2
|
||||
City: Wellington
|
||||
team3:
|
||||
Name: Team 3
|
||||
City: Auckland
|
||||
team4:
|
||||
Name: Team 4
|
||||
City: Melbourne
|
||||
GridFieldTest_Player:
|
||||
player1_team1:
|
||||
Name: Player 1
|
||||
Email: player1@test.com
|
||||
Teams: =>GridFieldTest_Team.team1
|
Loading…
x
Reference in New Issue
Block a user