2008-11-11 03:35:54 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-11-11 03:35:54 +01:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class CompositeFieldTest extends SapphireTest {
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testFieldPosition() {
|
2008-11-11 03:35:54 +01:00
|
|
|
$compositeOuter = new CompositeField(
|
|
|
|
new TextField('A'),
|
|
|
|
new TextField('B'),
|
|
|
|
$compositeInner = new CompositeField(
|
|
|
|
new TextField('C1'),
|
|
|
|
new TextField('C2')
|
|
|
|
),
|
|
|
|
new TextField('D')
|
|
|
|
);
|
2012-04-14 07:32:29 +02:00
|
|
|
|
2008-11-11 03:35:54 +01:00
|
|
|
$this->assertEquals(0, $compositeOuter->fieldPosition('A'));
|
|
|
|
$this->assertEquals(1, $compositeOuter->fieldPosition('B'));
|
|
|
|
$this->assertEquals(3, $compositeOuter->fieldPosition('D'));
|
|
|
|
|
|
|
|
$this->assertEquals(0, $compositeInner->fieldPosition('C1'));
|
|
|
|
$this->assertEquals(1, $compositeInner->fieldPosition('C2'));
|
|
|
|
|
|
|
|
$compositeOuter->insertBefore(new TextField('AB'), 'B');
|
|
|
|
$this->assertEquals(0, $compositeOuter->fieldPosition('A'));
|
|
|
|
$this->assertEquals(1, $compositeOuter->fieldPosition('AB'));
|
|
|
|
$this->assertEquals(2, $compositeOuter->fieldPosition('B'));
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testTag() {
|
2012-04-13 23:47:17 +02:00
|
|
|
$div = new CompositeField(
|
2012-02-16 15:44:36 +01:00
|
|
|
new TextField('A'),
|
|
|
|
new TextField('B')
|
|
|
|
);
|
2012-04-13 23:47:17 +02:00
|
|
|
$this->assertStringStartsWith('<div', trim($div->FieldHolder()));
|
|
|
|
$this->assertStringEndsWith('/div>', trim($div->FieldHolder()));
|
|
|
|
|
|
|
|
$fieldset = new CompositeField();
|
|
|
|
$fieldset->setTag('fieldset');
|
2012-02-16 15:44:36 +01:00
|
|
|
|
2012-04-13 23:47:17 +02:00
|
|
|
$this->assertStringStartsWith('<fieldset', trim($fieldset->FieldHolder()));
|
|
|
|
$this->assertStringEndsWith('/fieldset>', trim($fieldset->FieldHolder()));
|
2012-02-16 15:44:36 +01:00
|
|
|
}
|
2012-02-16 16:40:19 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testLegend() {
|
2012-02-16 16:40:19 +01:00
|
|
|
$composite = new CompositeField(
|
|
|
|
new TextField('A'),
|
|
|
|
new TextField('B')
|
|
|
|
);
|
2012-04-13 23:47:17 +02:00
|
|
|
|
2012-02-16 16:40:19 +01:00
|
|
|
$composite->setTag('fieldset');
|
|
|
|
$composite->setLegend('My legend');
|
2012-04-13 23:47:17 +02:00
|
|
|
|
2012-02-16 16:40:19 +01:00
|
|
|
$parser = new CSSContentParser($composite->Field());
|
|
|
|
$root = $parser->getBySelector('fieldset.composite');
|
|
|
|
$legend = $parser->getBySelector('fieldset.composite legend');
|
2012-04-13 23:47:17 +02:00
|
|
|
|
2012-02-16 16:40:19 +01:00
|
|
|
$this->assertNotNull($legend);
|
|
|
|
$this->assertEquals('My legend', (string)$legend[0]);
|
|
|
|
}
|
2008-11-11 03:35:54 +01:00
|
|
|
}
|