Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08099e4
commit 8f0df22
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
use dokuwiki\Form; | ||
|
||
class form_buttonelement_test extends DokuWikiTest { | ||
|
||
function test_simple() { | ||
$form = new Form\Form(); | ||
$form->addButton('foo', 'Hello <b>World</b>')->val('bam')->attr('type', 'submit'); | ||
|
||
$html = $form->toHTML(); | ||
$pq = phpQuery::newDocumentXHTML($html); | ||
|
||
$input = $pq->find('button[name=foo]'); | ||
$this->assertTrue($input->length == 1); | ||
$this->assertEquals('bam', $input->val()); | ||
$this->assertEquals('submit', $input->attr('type')); | ||
$this->assertEquals('Hello <b>World</b>', $input->text()); // tags were escaped | ||
|
||
$b = $input->find('b'); // no tags found | ||
$this->assertTrue($b->length == 0); | ||
} | ||
|
||
function test_html() { | ||
$form = new Form\Form(); | ||
$form->addButtonHTML('foo', 'Hello <b>World</b>')->val('bam')->attr('type', 'submit'); | ||
|
||
$html = $form->toHTML(); | ||
$pq = phpQuery::newDocumentXHTML($html); | ||
|
||
$input = $pq->find('button[name=foo]'); | ||
$this->assertTrue($input->length == 1); | ||
$this->assertEquals('bam', $input->val()); | ||
$this->assertEquals('submit', $input->attr('type')); | ||
$this->assertEquals('Hello World', $input->text()); // tags are stripped here | ||
|
||
$b = $input->find('b'); // tags found | ||
$this->assertTrue($b->length == 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
namespace dokuwiki\Form; | ||
|
||
/** | ||
* Class ButtonElement | ||
* | ||
* Represents a simple button | ||
* | ||
* @package dokuwiki\Form | ||
*/ | ||
class ButtonElement extends Element { | ||
|
||
/** @var string HTML content */ | ||
protected $content = ''; | ||
|
||
/** | ||
* @param string $name | ||
* @param string $content HTML content of the button. You have to escape it yourself. | ||
*/ | ||
function __construct($name, $content = '') { | ||
parent::__construct('button', array('name' => $name, 'value' => 1)); | ||
$this->content = $content; | ||
} | ||
|
||
/** | ||
* The HTML representation of this element | ||
* | ||
* @return string | ||
*/ | ||
public function toHTML() { | ||
return '<button ' . buildAttributes($this->attrs()) . '>'.$this->content.'</button>'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters