2012-11-30 15:06:49 +01:00
|
|
|
<?php
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\Forms\Tests;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\CSSContentParser;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Forms\LiteralField;
|
|
|
|
use SilverStripe\Forms\SelectionGroup_Item;
|
|
|
|
use SilverStripe\Forms\SelectionGroup;
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
class SelectionGroupTest extends SapphireTest
|
|
|
|
{
|
2012-11-30 15:06:49 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
function testFieldHolder()
|
|
|
|
{
|
|
|
|
$items = array(
|
|
|
|
new SelectionGroup_Item(
|
|
|
|
'one',
|
|
|
|
new LiteralField('one', 'one view'),
|
|
|
|
'one title'
|
|
|
|
),
|
|
|
|
new SelectionGroup_Item(
|
|
|
|
'two',
|
|
|
|
new LiteralField('two', 'two view'),
|
|
|
|
'two title'
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$field = new SelectionGroup('MyGroup', $items);
|
|
|
|
$parser = new CSSContentParser($field->FieldHolder());
|
|
|
|
$listEls = $parser->getBySelector('li');
|
|
|
|
$listElOne = $listEls[0];
|
|
|
|
$listElTwo = $listEls[1];
|
2012-11-30 15:06:49 +01:00
|
|
|
|
2017-04-26 06:03:52 +02:00
|
|
|
$this->assertEquals('one', (string)$listElOne->label[0]->input[0]['value']);
|
|
|
|
$this->assertEquals('two', (string)$listElTwo->label[0]->input[0]['value']);
|
2012-11-30 15:06:49 +01:00
|
|
|
|
2017-04-26 06:03:52 +02:00
|
|
|
$this->assertEquals(' one title', (string)$listElOne->label[0]);
|
|
|
|
$this->assertEquals(' two title', (string)$listElTwo->label[0]);
|
2012-11-30 15:06:49 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertContains('one view', (string)$listElOne->div);
|
|
|
|
$this->assertContains('two view', (string)$listElTwo->div);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2018-04-05 00:16:25 +02:00
|
|
|
function testSelectedFieldHolder()
|
|
|
|
{
|
|
|
|
$items = array(
|
|
|
|
new SelectionGroup_Item(
|
|
|
|
'one',
|
|
|
|
new LiteralField('one', 'one view'),
|
|
|
|
'one title'
|
|
|
|
),
|
|
|
|
new SelectionGroup_Item(
|
|
|
|
'two',
|
|
|
|
new LiteralField('two', 'two view'),
|
|
|
|
'two title'
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$field = new SelectionGroup('MyGroup', $items);
|
|
|
|
$field->setValue('two');
|
|
|
|
|
|
|
|
$parser = new CSSContentParser($field->FieldHolder());
|
|
|
|
$listEls = $parser->getBySelector('li');
|
|
|
|
$listElOne = $listEls[0];
|
|
|
|
$listElTwo = $listEls[1];
|
|
|
|
|
|
|
|
$this->assertEquals('one', (string)$listElOne->label[0]->input[0]['value']);
|
|
|
|
$this->assertEquals('two', (string)$listElTwo->label[0]->input[0]['value']);
|
|
|
|
$this->assertEquals('selected', (string)$listElTwo->attributes()->class);
|
|
|
|
}
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
function testLegacyItemsFieldHolder()
|
|
|
|
{
|
|
|
|
$items = array(
|
|
|
|
'one' => new LiteralField('one', 'one view'),
|
|
|
|
'two' => new LiteralField('two', 'two view'),
|
|
|
|
);
|
|
|
|
$field = new SelectionGroup('MyGroup', $items);
|
|
|
|
$parser = new CSSContentParser($field->FieldHolder());
|
|
|
|
$listEls = $parser->getBySelector('li');
|
|
|
|
$listElOne = $listEls[0];
|
|
|
|
$listElTwo = $listEls[1];
|
2012-11-30 15:06:49 +01:00
|
|
|
|
2017-04-26 06:03:52 +02:00
|
|
|
$this->assertEquals('one', (string)$listElOne->label[0]->input[0]['value']);
|
|
|
|
$this->assertEquals('two', (string)$listElTwo->label[0]->input[0]['value']);
|
2012-11-30 15:06:49 +01:00
|
|
|
|
2017-04-26 06:03:52 +02:00
|
|
|
$this->assertEquals(' one', (string)$listElOne->label[0]);
|
|
|
|
$this->assertEquals(' two', (string)$listElTwo->label[0]);
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
2012-11-30 15:06:49 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
function testLegacyItemsFieldHolderWithTitle()
|
|
|
|
{
|
|
|
|
$items = array(
|
|
|
|
'one//one title' => new LiteralField('one', 'one view'),
|
|
|
|
'two//two title' => new LiteralField('two', 'two view'),
|
|
|
|
);
|
|
|
|
$field = new SelectionGroup('MyGroup', $items);
|
|
|
|
$parser = new CSSContentParser($field->FieldHolder());
|
|
|
|
$listEls = $parser->getBySelector('li');
|
|
|
|
$listElOne = $listEls[0];
|
|
|
|
$listElTwo = $listEls[1];
|
2012-11-30 15:06:49 +01:00
|
|
|
|
2017-04-26 06:03:52 +02:00
|
|
|
$this->assertEquals('one', (string)$listElOne->label[0]->input[0]['value']);
|
|
|
|
$this->assertEquals('two', (string)$listElTwo->label[0]->input[0]['value']);
|
2012-11-30 15:06:49 +01:00
|
|
|
|
2017-04-26 06:03:52 +02:00
|
|
|
$this->assertEquals(' one title', (string)$listElOne->label[0]);
|
|
|
|
$this->assertEquals(' two title', (string)$listElTwo->label[0]);
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
}
|