1<?php 2 3namespace dokuwiki\test\Form; 4 5use dokuwiki\Form; 6 7class TextareaElementTest extends \DokuWikiTest 8{ 9 /** 10 * Create a form with a textarea element and return the raw inner HTML of the textarea. 11 */ 12 private function rawTextareaBody(string $value): string 13 { 14 $form = new Form\Form(); 15 $form->addTextarea('wikitext', 'label')->val($value); 16 17 $this->assertSame( 18 1, 19 preg_match('#<textarea[^>]*>(.*?)</textarea>#s', $form->toHTML(), $m), 20 'expected exactly one textarea' 21 ); 22 return $m[1]; 23 } 24 25 public function testStartTagIsFollowedByGuardNewline() 26 { 27 $this->assertStringStartsWith("\n", $this->rawTextareaBody('hello')); 28 } 29 30 public function testValueIsEmittedInFullAfterGuard() 31 { 32 // a value beginning with a newline must appear unaltered after the 33 // guard: the start tag is followed by the guard newline and then the 34 // form-encoded value (including its own leading newline) 35 $value = "\n## heading\n"; 36 $this->assertSame("\n" . formText($value), $this->rawTextareaBody($value)); 37 } 38} 39