[ Index ] |
PHP Cross Reference of DokuWiki |
[Summary view] [Print] [Text view]
1 <?php 2 3 namespace dokuwiki\test\Form; 4 5 use dokuwiki\Form; 6 use DOMWrap\Document; 7 8 class CheckableElementTest extends \DokuWikiTest 9 { 10 11 function testDefaults() 12 { 13 $form = new Form\Form(); 14 $form->addRadioButton('foo', 'label text first')->val('first')->attr('checked', 'checked'); 15 $form->addRadioButton('foo', 'label text second')->val('second'); 16 17 $html = $form->toHTML(); 18 $pq = (new Document())->html($html); 19 20 $input = $pq->find('input[name=foo]'); 21 $this->assertTrue($input->count() == 2); 22 23 $label = $pq->find('label'); 24 $this->assertTrue($label->count() == 2); 25 26 $inputs = $pq->find('input[name=foo]'); 27 $this->assertEquals('first', $inputs->get(0)->attr('value')); 28 $this->assertEquals('second', $inputs->get(1)->attr('value')); 29 $this->assertEquals('checked', $inputs->get(0)->attr('checked')); 30 $this->assertEquals('', $inputs->get(1)->attr('checked')); 31 $this->assertEquals('radio', $inputs->get(0)->attr('type')); 32 } 33 34 /** 35 * check that posted values overwrite preset default 36 */ 37 function testPrefill() 38 { 39 global $INPUT; 40 $INPUT->post->set('foo', 'second'); 41 42 $form = new Form\Form(); 43 $form->addRadioButton('foo', 'label text first')->val('first')->attr('checked', 'checked'); 44 $form->addRadioButton('foo', 'label text second')->val('second'); 45 46 $html = $form->toHTML(); 47 $pq = (new Document())->html($html); 48 49 $inputs = $pq->find('input[name=foo]'); 50 $this->assertEquals('first', $inputs->get(0)->attr('value')); 51 $this->assertEquals('second', $inputs->get(1)->attr('value')); 52 $this->assertEquals('', $inputs->get(0)->attr('checked')); 53 $this->assertEquals('checked', $inputs->get(1)->attr('checked')); 54 $this->assertEquals('radio', $inputs->get(0)->attr('type')); 55 } 56 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body