tag_test.php.svn-base

来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 554 行 · 第 1/2 页

SVN-BASE
554
字号
<?php// $Id: tag_test.php 1509 2007-05-08 22:11:49Z lastcraft $require_once(dirname(__FILE__) . '/../autorun.php');require_once(dirname(__FILE__) . '/../tag.php');require_once(dirname(__FILE__) . '/../encoding.php');Mock::generate('SimpleMultipartEncoding');class TestOfTag extends UnitTestCase {        function testStartValuesWithoutAdditionalContent() {        $tag = new SimpleTitleTag(array('a' => '1', 'b' => ''));        $this->assertEqual($tag->getTagName(), 'title');        $this->assertIdentical($tag->getAttribute('a'), '1');        $this->assertIdentical($tag->getAttribute('b'), '');        $this->assertIdentical($tag->getAttribute('c'), false);        $this->assertIdentical($tag->getContent(), '');    }        function testTitleContent() {        $tag = &new SimpleTitleTag(array());        $this->assertTrue($tag->expectEndTag());        $tag->addContent('Hello');        $tag->addContent('World');        $this->assertEqual($tag->getText(), 'HelloWorld');    }        function testMessyTitleContent() {        $tag = &new SimpleTitleTag(array());        $this->assertTrue($tag->expectEndTag());        $tag->addContent('<b>Hello</b>');        $tag->addContent('<em>World</em>');        $this->assertEqual($tag->getText(), 'HelloWorld');    }        function testTagWithNoEnd() {        $tag = &new SimpleTextTag(array());        $this->assertFalse($tag->expectEndTag());    }        function testAnchorHref() {        $tag = &new SimpleAnchorTag(array('href' => 'http://here/'));        $this->assertEqual($tag->getHref(), 'http://here/');                $tag = &new SimpleAnchorTag(array('href' => ''));        $this->assertIdentical($tag->getAttribute('href'), '');        $this->assertIdentical($tag->getHref(), '');                $tag = &new SimpleAnchorTag(array());        $this->assertIdentical($tag->getAttribute('href'), false);        $this->assertIdentical($tag->getHref(), '');    }        function testIsIdMatchesIdAttribute() {        $tag = &new SimpleAnchorTag(array('href' => 'http://here/', 'id' => 7));        $this->assertIdentical($tag->getAttribute('id'), '7');        $this->assertTrue($tag->isId(7));    }}class TestOfWidget extends UnitTestCase {        function testTextEmptyDefault() {        $tag = &new SimpleTextTag(array('type' => 'text'));        $this->assertIdentical($tag->getDefault(), '');        $this->assertIdentical($tag->getValue(), '');    }        function testSettingOfExternalLabel() {        $tag = &new SimpleTextTag(array('type' => 'text'));        $tag->setLabel('it');        $this->assertTrue($tag->isLabel('it'));    }        function testTextDefault() {        $tag = &new SimpleTextTag(array('value' => 'aaa'));        $this->assertEqual($tag->getDefault(), 'aaa');        $this->assertEqual($tag->getValue(), 'aaa');    }        function testSettingTextValue() {        $tag = &new SimpleTextTag(array('value' => 'aaa'));        $tag->setValue('bbb');        $this->assertEqual($tag->getValue(), 'bbb');        $tag->resetValue();        $this->assertEqual($tag->getValue(), 'aaa');    }        function testFailToSetHiddenValue() {        $tag = &new SimpleTextTag(array('value' => 'aaa', 'type' => 'hidden'));        $this->assertFalse($tag->setValue('bbb'));        $this->assertEqual($tag->getValue(), 'aaa');    }        function testSubmitDefaults() {        $tag = &new SimpleSubmitTag(array('type' => 'submit'));        $this->assertIdentical($tag->getName(), false);        $this->assertEqual($tag->getValue(), 'Submit');        $this->assertFalse($tag->setValue('Cannot set this'));        $this->assertEqual($tag->getValue(), 'Submit');        $this->assertEqual($tag->getLabel(), 'Submit');                $encoding = &new MockSimpleMultipartEncoding();        $encoding->expectNever('add');        $tag->write($encoding);    }        function testPopulatedSubmit() {        $tag = &new SimpleSubmitTag(                array('type' => 'submit', 'name' => 's', 'value' => 'Ok!'));        $this->assertEqual($tag->getName(), 's');        $this->assertEqual($tag->getValue(), 'Ok!');        $this->assertEqual($tag->getLabel(), 'Ok!');                $encoding = &new MockSimpleMultipartEncoding();        $encoding->expectOnce('add', array('s', 'Ok!'));        $tag->write($encoding);    }        function testImageSubmit() {        $tag = &new SimpleImageSubmitTag(                array('type' => 'image', 'name' => 's', 'alt' => 'Label'));        $this->assertEqual($tag->getName(), 's');        $this->assertEqual($tag->getLabel(), 'Label');                $encoding = &new MockSimpleMultipartEncoding();        $encoding->expectAt(0, 'add', array('s.x', 20));        $encoding->expectAt(1, 'add', array('s.y', 30));        $tag->write($encoding, 20, 30);    }        function testImageSubmitTitlePreferredOverAltForLabel() {        $tag = &new SimpleImageSubmitTag(                array('type' => 'image', 'name' => 's', 'alt' => 'Label', 'title' => 'Title'));        $this->assertEqual($tag->getLabel(), 'Title');    }        function testButton() {        $tag = &new SimpleButtonTag(                array('type' => 'submit', 'name' => 's', 'value' => 'do'));        $tag->addContent('I am a button');        $this->assertEqual($tag->getName(), 's');        $this->assertEqual($tag->getValue(), 'do');        $this->assertEqual($tag->getLabel(), 'I am a button');        $encoding = &new MockSimpleMultipartEncoding();        $encoding->expectOnce('add', array('s', 'do'));        $tag->write($encoding);    }}class TestOfTextArea extends UnitTestCase {        function testDefault() {        $tag = &new SimpleTextAreaTag(array('name' => 'a'));        $tag->addContent('Some text');        $this->assertEqual($tag->getName(), 'a');        $this->assertEqual($tag->getDefault(), 'Some text');    }        function testWrapping() {        $tag = &new SimpleTextAreaTag(array('cols' => '10', 'wrap' => 'physical'));        $tag->addContent("Lot's of text that should be wrapped");        $this->assertEqual(                $tag->getDefault(),                "Lot's of\r\ntext that\r\nshould be\r\nwrapped");        $tag->setValue("New long text\r\nwith two lines");        $this->assertEqual(                $tag->getValue(),                "New long\r\ntext\r\nwith two\r\nlines");    }        function testWrappingRemovesLeadingcariageReturn() {        $tag = &new SimpleTextAreaTag(array('cols' => '20', 'wrap' => 'physical'));        $tag->addContent("\rStuff");        $this->assertEqual($tag->getDefault(), 'Stuff');        $tag->setValue("\nNew stuff\n");        $this->assertEqual($tag->getValue(), "New stuff\r\n");    }        function testBreaksAreNewlineAndCarriageReturn() {        $tag = &new SimpleTextAreaTag(array('cols' => '10'));        $tag->addContent("Some\nText\rwith\r\nbreaks");        $this->assertEqual($tag->getValue(), "Some\r\nText\r\nwith\r\nbreaks");    }}class TestOfCheckbox extends UnitTestCase {        function testCanSetCheckboxToNamedValueWithBooleanTrue() {        $tag = &new SimpleCheckboxTag(array('name' => 'a', 'value' => 'A'));        $this->assertEqual($tag->getValue(), false);        $tag->setValue(true);        $this->assertIdentical($tag->getValue(), 'A');    }}class TestOfSelection extends UnitTestCase {        function testEmpty() {        $tag = &new SimpleSelectionTag(array('name' => 'a'));        $this->assertIdentical($tag->getValue(), '');    }        function testSingle() {        $tag = &new SimpleSelectionTag(array('name' => 'a'));        $option = &new SimpleOptionTag(array());        $option->addContent('AAA');        $tag->addTag($option);        $this->assertEqual($tag->getValue(), 'AAA');    }        function testSingleDefault() {        $tag = &new SimpleSelectionTag(array('name' => 'a'));        $option = &new SimpleOptionTag(array('selected' => ''));        $option->addContent('AAA');        $tag->addTag($option);        $this->assertEqual($tag->getValue(), 'AAA');    }        function testSingleMappedDefault() {        $tag = &new SimpleSelectionTag(array('name' => 'a'));        $option = &new SimpleOptionTag(array('selected' => '', 'value' => 'aaa'));        $option->addContent('AAA');        $tag->addTag($option);        $this->assertEqual($tag->getValue(), 'aaa');    }        function testStartsWithDefault() {        $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->assertEqual($tag->getValue(), 'BBB');    }        function testSettingOption() {        $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->setValue('AAA');        $this->assertEqual($tag->getValue(), 'AAA');    }        function testSettingMappedOption() {        $tag = &new SimpleSelectionTag(array('name' => 'a'));        $a = &new SimpleOptionTag(array('value' => 'aaa'));        $a->addContent('AAA');        $tag->addTag($a);        $b = &new SimpleOptionTag(array('value' => 'bbb', 'selected' => ''));        $b->addContent('BBB');        $tag->addTag($b);        $c = &new SimpleOptionTag(array('value' => 'ccc'));        $c->addContent('CCC');        $tag->addTag($c);        $tag->setValue('AAA');        $this->assertEqual($tag->getValue(), 'aaa');        $tag->setValue('ccc');        $this->assertEqual($tag->getValue(), 'ccc');    }        function testSelectionDespiteSpuriousWhitespace() {        $tag = &new SimpleSelectionTag(array('name' => 'a'));        $a = &new SimpleOptionTag(array());        $a->addContent(' AAA ');        $tag->addTag($a);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?