2012-03-01 14:32:30 +01:00
|
|
|
<?php
|
2012-03-09 00:54:02 +01:00
|
|
|
class GridFieldAddExistingAutocompleterTest extends FunctionalTest {
|
2012-03-01 14:32:30 +01:00
|
|
|
|
2012-03-24 04:38:57 +01:00
|
|
|
static $fixture_file = 'GridFieldTest.yml';
|
2012-03-01 14:32:30 +01:00
|
|
|
|
|
|
|
protected $extraDataObjects = array('GridFieldTest_Team', 'GridFieldTest_Player');
|
|
|
|
|
|
|
|
function testSearch() {
|
|
|
|
$team1 = $this->objFromFixture('GridFieldTest_Team', 'team1');
|
|
|
|
$team2 = $this->objFromFixture('GridFieldTest_Team', 'team2');
|
|
|
|
|
2012-03-09 00:54:02 +01:00
|
|
|
$response = $this->get('GridFieldAddExistingAutocompleterTest_Controller');
|
2012-03-01 14:32:30 +01:00
|
|
|
$this->assertFalse($response->isError());
|
|
|
|
$parser = new CSSContentParser($response->getBody());
|
|
|
|
$btns = $parser->getBySelector('.ss-gridfield #action_gridfield_relationfind');
|
|
|
|
|
|
|
|
$response = $this->post(
|
2012-03-09 00:54:02 +01:00
|
|
|
'GridFieldAddExistingAutocompleterTest_Controller/Form/field/testfield/search/Team 2',
|
2012-03-01 14:32:30 +01:00
|
|
|
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(
|
2012-03-09 00:54:02 +01:00
|
|
|
'GridFieldAddExistingAutocompleterTest_Controller/Form/field/testfield/search/Unknown',
|
2012-03-01 14:32:30 +01:00
|
|
|
array(
|
|
|
|
(string)$btns[0]['name'] => 1
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertFalse($response->isError());
|
|
|
|
$result = Convert::json2array($response->getBody());
|
2012-03-30 05:18:14 +02:00
|
|
|
$this->assertEmpty($result, 'The output is either an empty array or boolean FALSE');
|
2012-03-01 14:32:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function testAdd() {
|
2012-03-08 01:58:53 +01:00
|
|
|
$this->logInWithPermission('ADMIN');
|
2012-03-01 14:32:30 +01:00
|
|
|
$team1 = $this->objFromFixture('GridFieldTest_Team', 'team1');
|
|
|
|
$team2 = $this->objFromFixture('GridFieldTest_Team', 'team2');
|
|
|
|
|
2012-03-09 00:54:02 +01:00
|
|
|
$response = $this->get('GridFieldAddExistingAutocompleterTest_Controller');
|
2012-03-01 14:32:30 +01:00
|
|
|
$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(
|
2012-03-09 00:54:02 +01:00
|
|
|
'GridFieldAddExistingAutocompleterTest_Controller/Form/field/testfield',
|
2012-03-01 14:32:30 +01:00
|
|
|
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']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-09 00:54:02 +01:00
|
|
|
class GridFieldAddExistingAutocompleterTest_Controller extends Controller implements TestOnly {
|
2012-03-01 14:32:30 +01:00
|
|
|
|
|
|
|
protected $template = 'BlankPage';
|
|
|
|
|
|
|
|
function Form() {
|
|
|
|
$player = DataObject::get('GridFieldTest_Player')->find('Email', 'player1@test.com');
|
|
|
|
$config = GridFieldConfig::create()->addComponents(
|
2012-03-09 06:11:50 +01:00
|
|
|
$relationComponent = new GridFieldAddExistingAutocompleter('before', 'Name'),
|
2012-03-09 02:07:40 +01:00
|
|
|
new GridFieldDataColumns()
|
2012-03-01 14:32:30 +01:00
|
|
|
);
|
|
|
|
$field = new GridField('testfield', 'testfield', $player->Teams(), $config);
|
|
|
|
return new Form($this, 'Form', new FieldList($field), new FieldList());
|
|
|
|
}
|
2012-03-30 05:18:14 +02:00
|
|
|
}
|