2010-02-22 07:11:58 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2010-02-22 07:11:58 +01:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class OptionsetFieldTest extends SapphireTest {
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testSetDisabledItems() {
|
2010-02-22 07:11:58 +01:00
|
|
|
$f = new OptionsetField(
|
2016-08-03 01:23:17 +02:00
|
|
|
'Test',
|
|
|
|
false,
|
2010-02-22 07:11:58 +01:00
|
|
|
array(0 => 'Zero', 1 => 'One')
|
|
|
|
);
|
2016-08-03 01:23:17 +02:00
|
|
|
|
2010-02-22 07:11:58 +01:00
|
|
|
$f->setDisabledItems(array(0));
|
|
|
|
$p = new CSSContentParser($f->Field());
|
|
|
|
$item0 = $p->getBySelector('#Test_0');
|
|
|
|
$item1 = $p->getBySelector('#Test_1');
|
|
|
|
$this->assertEquals(
|
|
|
|
(string)$item0[0]['disabled'],
|
|
|
|
'disabled'
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
(string)$item1[0]['disabled'],
|
|
|
|
''
|
|
|
|
);
|
|
|
|
}
|
2013-12-11 22:23:29 +01:00
|
|
|
|
|
|
|
public function testReadonlyField() {
|
|
|
|
$sourceArray = array(0 => 'No', 1 => 'Yes');
|
|
|
|
$field = new OptionsetField('FeelingOk', 'are you feeling ok?', $sourceArray, 1);
|
|
|
|
$field->setEmptyString('(Select one)');
|
|
|
|
$field->setValue(1);
|
|
|
|
$readonlyField = $field->performReadonlyTransformation();
|
|
|
|
preg_match('/Yes/', $field->Field(), $matches);
|
|
|
|
$this->assertEquals($matches[0], 'Yes');
|
|
|
|
}
|
2016-08-03 01:23:17 +02:00
|
|
|
|
|
|
|
public function testSafelyCast() {
|
|
|
|
$field1 = new OptionsetField('Options', 'Options', array(
|
|
|
|
1 => 'One',
|
|
|
|
2 => 'Two & Three',
|
|
|
|
3 => DBField::create_field('HTMLText', 'Four & Five & Six')
|
|
|
|
));
|
|
|
|
$fieldHTML = (string)$field1->Field();
|
|
|
|
$this->assertContains('One', $fieldHTML);
|
|
|
|
$this->assertContains('Two & Three', $fieldHTML);
|
|
|
|
$this->assertNotContains('Two & Three', $fieldHTML);
|
|
|
|
$this->assertContains('Four & Five & Six', $fieldHTML);
|
|
|
|
$this->assertNotContains('Four & Five & Six', $fieldHTML);
|
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|