tag_test.php
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· PHP 代码 · 共 554 行 · 第 1/2 页
PHP
554 行
$b = &new SimpleOptionTag(array('selected' => ''));
$b->addContent(' BBB ');
$tag->addTag($b);
$c = &new SimpleOptionTag(array());
$c->addContent(' CCC ');
$tag->addTag($c);
$this->assertEqual($tag->getValue(), ' BBB ');
$tag->setValue('AAA');
$this->assertEqual($tag->getValue(), ' AAA ');
}
function testFailToSetIllegalOption() {
$tag = &new SimpleSelectionTag(array('name' => 'a'));
$a = &new SimpleOptionTag(array());
$a->addContent('AAA');
$tag->addTag($a);
$b = &new SimpleOptionTag(array('selected' => ''));
$b->addContent('BBB');
$tag->addTag($b);
$c = &new SimpleOptionTag(array());
$c->addContent('CCC');
$tag->addTag($c);
$this->assertFalse($tag->setValue('Not present'));
$this->assertEqual($tag->getValue(), 'BBB');
}
function testNastyOptionValuesThatLookLikeFalse() {
$tag = &new SimpleSelectionTag(array('name' => 'a'));
$a = &new SimpleOptionTag(array('value' => '1'));
$a->addContent('One');
$tag->addTag($a);
$b = &new SimpleOptionTag(array('value' => '0'));
$b->addContent('Zero');
$tag->addTag($b);
$this->assertIdentical($tag->getValue(), '1');
$tag->setValue('Zero');
$this->assertIdentical($tag->getValue(), '0');
}
function testBlankOption() {
$tag = &new SimpleSelectionTag(array('name' => 'A'));
$a = &new SimpleOptionTag(array());
$tag->addTag($a);
$b = &new SimpleOptionTag(array());
$b->addContent('b');
$tag->addTag($b);
$this->assertIdentical($tag->getValue(), '');
$tag->setValue('b');
$this->assertIdentical($tag->getValue(), 'b');
$tag->setValue('');
$this->assertIdentical($tag->getValue(), '');
}
function testMultipleDefaultWithNoSelections() {
$tag = &new MultipleSelectionTag(array('name' => 'a', 'multiple' => ''));
$a = &new SimpleOptionTag(array());
$a->addContent('AAA');
$tag->addTag($a);
$b = &new SimpleOptionTag(array());
$b->addContent('BBB');
$tag->addTag($b);
$this->assertIdentical($tag->getDefault(), array());
$this->assertIdentical($tag->getValue(), array());
}
function testMultipleDefaultWithSelections() {
$tag = &new MultipleSelectionTag(array('name' => 'a', 'multiple' => ''));
$a = &new SimpleOptionTag(array('selected' => ''));
$a->addContent('AAA');
$tag->addTag($a);
$b = &new SimpleOptionTag(array('selected' => ''));
$b->addContent('BBB');
$tag->addTag($b);
$this->assertIdentical($tag->getDefault(), array('AAA', 'BBB'));
$this->assertIdentical($tag->getValue(), array('AAA', 'BBB'));
}
function testSettingMultiple() {
$tag = &new MultipleSelectionTag(array('name' => 'a', 'multiple' => ''));
$a = &new SimpleOptionTag(array('selected' => ''));
$a->addContent('AAA');
$tag->addTag($a);
$b = &new SimpleOptionTag(array());
$b->addContent('BBB');
$tag->addTag($b);
$c = &new SimpleOptionTag(array('selected' => '', 'value' => 'ccc'));
$c->addContent('CCC');
$tag->addTag($c);
$this->assertIdentical($tag->getDefault(), array('AAA', 'ccc'));
$this->assertTrue($tag->setValue(array('BBB', 'ccc')));
$this->assertIdentical($tag->getValue(), array('BBB', 'ccc'));
$this->assertTrue($tag->setValue(array()));
$this->assertIdentical($tag->getValue(), array());
}
function testFailToSetIllegalOptionsInMultiple() {
$tag = &new MultipleSelectionTag(array('name' => 'a', 'multiple' => ''));
$a = &new SimpleOptionTag(array('selected' => ''));
$a->addContent('AAA');
$tag->addTag($a);
$b = &new SimpleOptionTag(array());
$b->addContent('BBB');
$tag->addTag($b);
$this->assertFalse($tag->setValue(array('CCC')));
$this->assertTrue($tag->setValue(array('AAA', 'BBB')));
$this->assertFalse($tag->setValue(array('AAA', 'CCC')));
}
}
class TestOfRadioGroup extends UnitTestCase {
function testEmptyGroup() {
$group = &new SimpleRadioGroup();
$this->assertIdentical($group->getDefault(), false);
$this->assertIdentical($group->getValue(), false);
$this->assertFalse($group->setValue('a'));
}
function testReadingSingleButtonGroup() {
$group = &new SimpleRadioGroup();
$group->addWidget(new SimpleRadioButtonTag(
array('value' => 'A', 'checked' => '')));
$this->assertIdentical($group->getDefault(), 'A');
$this->assertIdentical($group->getValue(), 'A');
}
function testReadingMultipleButtonGroup() {
$group = &new SimpleRadioGroup();
$group->addWidget(new SimpleRadioButtonTag(
array('value' => 'A')));
$group->addWidget(new SimpleRadioButtonTag(
array('value' => 'B', 'checked' => '')));
$this->assertIdentical($group->getDefault(), 'B');
$this->assertIdentical($group->getValue(), 'B');
}
function testFailToSetUnlistedValue() {
$group = &new SimpleRadioGroup();
$group->addWidget(new SimpleRadioButtonTag(array('value' => 'z')));
$this->assertFalse($group->setValue('a'));
$this->assertIdentical($group->getValue(), false);
}
function testSettingNewValueClearsTheOldOne() {
$group = &new SimpleRadioGroup();
$group->addWidget(new SimpleRadioButtonTag(
array('value' => 'A')));
$group->addWidget(new SimpleRadioButtonTag(
array('value' => 'B', 'checked' => '')));
$this->assertTrue($group->setValue('A'));
$this->assertIdentical($group->getValue(), 'A');
}
function testIsIdMatchesAnyWidgetInSet() {
$group = &new SimpleRadioGroup();
$group->addWidget(new SimpleRadioButtonTag(
array('value' => 'A', 'id' => 'i1')));
$group->addWidget(new SimpleRadioButtonTag(
array('value' => 'B', 'id' => 'i2')));
$this->assertFalse($group->isId('i0'));
$this->assertTrue($group->isId('i1'));
$this->assertTrue($group->isId('i2'));
}
function testIsLabelMatchesAnyWidgetInSet() {
$group = &new SimpleRadioGroup();
$button1 = &new SimpleRadioButtonTag(array('value' => 'A'));
$button1->setLabel('one');
$group->addWidget($button1);
$button2 = &new SimpleRadioButtonTag(array('value' => 'B'));
$button2->setLabel('two');
$group->addWidget($button2);
$this->assertFalse($group->isLabel('three'));
$this->assertTrue($group->isLabel('one'));
$this->assertTrue($group->isLabel('two'));
}
}
class TestOfTagGroup extends UnitTestCase {
function testReadingMultipleCheckboxGroup() {
$group = &new SimpleCheckboxGroup();
$group->addWidget(new SimpleCheckboxTag(array('value' => 'A')));
$group->addWidget(new SimpleCheckboxTag(
array('value' => 'B', 'checked' => '')));
$this->assertIdentical($group->getDefault(), 'B');
$this->assertIdentical($group->getValue(), 'B');
}
function testReadingMultipleUncheckedItems() {
$group = &new SimpleCheckboxGroup();
$group->addWidget(new SimpleCheckboxTag(array('value' => 'A')));
$group->addWidget(new SimpleCheckboxTag(array('value' => 'B')));
$this->assertIdentical($group->getDefault(), false);
$this->assertIdentical($group->getValue(), false);
}
function testReadingMultipleCheckedItems() {
$group = &new SimpleCheckboxGroup();
$group->addWidget(new SimpleCheckboxTag(
array('value' => 'A', 'checked' => '')));
$group->addWidget(new SimpleCheckboxTag(
array('value' => 'B', 'checked' => '')));
$this->assertIdentical($group->getDefault(), array('A', 'B'));
$this->assertIdentical($group->getValue(), array('A', 'B'));
}
function testSettingSingleValue() {
$group = &new SimpleCheckboxGroup();
$group->addWidget(new SimpleCheckboxTag(array('value' => 'A')));
$group->addWidget(new SimpleCheckboxTag(array('value' => 'B')));
$this->assertTrue($group->setValue('A'));
$this->assertIdentical($group->getValue(), 'A');
$this->assertTrue($group->setValue('B'));
$this->assertIdentical($group->getValue(), 'B');
}
function testSettingMultipleValues() {
$group = &new SimpleCheckboxGroup();
$group->addWidget(new SimpleCheckboxTag(array('value' => 'A')));
$group->addWidget(new SimpleCheckboxTag(array('value' => 'B')));
$this->assertTrue($group->setValue(array('A', 'B')));
$this->assertIdentical($group->getValue(), array('A', 'B'));
}
function testSettingNoValue() {
$group = &new SimpleCheckboxGroup();
$group->addWidget(new SimpleCheckboxTag(array('value' => 'A')));
$group->addWidget(new SimpleCheckboxTag(array('value' => 'B')));
$this->assertTrue($group->setValue(false));
$this->assertIdentical($group->getValue(), false);
}
function testIsIdMatchesAnyIdInSet() {
$group = &new SimpleCheckboxGroup();
$group->addWidget(new SimpleCheckboxTag(array('id' => 1, 'value' => 'A')));
$group->addWidget(new SimpleCheckboxTag(array('id' => 2, 'value' => 'B')));
$this->assertFalse($group->isId(0));
$this->assertTrue($group->isId(1));
$this->assertTrue($group->isId(2));
}
}
class TestOfUploadWidget extends UnitTestCase {
function testValueIsFilePath() {
$upload = &new SimpleUploadTag(array('name' => 'a'));
$upload->setValue(dirname(__FILE__) . '/support/upload_sample.txt');
$this->assertEqual($upload->getValue(), dirname(__FILE__) . '/support/upload_sample.txt');
}
function testSubmitsFileContents() {
$encoding = &new MockSimpleMultipartEncoding();
$encoding->expectOnce('attach', array(
'a',
'Sample for testing file upload',
'upload_sample.txt'));
$upload = &new SimpleUploadTag(array('name' => 'a'));
$upload->setValue(dirname(__FILE__) . '/support/upload_sample.txt');
$upload->write($encoding);
}
}
class TestOfLabelTag extends UnitTestCase {
function testLabelShouldHaveAnEndTag() {
$label = &new SimpleLabelTag(array());
$this->assertTrue($label->expectEndTag());
}
function testContentIsTextOnly() {
$label = &new SimpleLabelTag(array());
$label->addContent('Here <tag>are</tag> words');
$this->assertEqual($label->getText(), 'Here are words');
}
}
?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?