1<?php 2 3namespace dokuwiki\plugin\bureaucracy\test; 4 5/** 6 * @group plugin_bureaucracy 7 * @group plugins 8 */ 9class bureaucracy_field_time_test extends BureaucracyTest 10{ 11 12 public function dataProvider() 13 { 14 return [ 15 [ 16 'time:@@timeLabel@@', 17 'time timeLabel', 18 '10:32', 19 'time:10:32', 20 [], 21 'valid time without seconds', 22 ], 23 [ 24 'time:@@timeLabel@@', 25 'time timeLabel', 26 '10:32:44', 27 'time:10:32:44', 28 [], 29 'valid time with seconds', 30 ], 31 [ 32 'time:@@timeLabel@@', 33 'time timeLabel', 34 '1032', 35 null, 36 ['timeLabel'], 37 'invalid time', 38 ], 39 ]; 40 } 41 42 /** 43 * @dataProvider dataProvider 44 * 45 * @param string $templateSyntax 46 * @param string $formSyntax 47 * @param string $postedValue 48 * @param string $expectedWikiText 49 * @param string[] $expectedValidationErrors 50 * @param string $msg 51 */ 52 public function test_field_time_submit( 53 $templateSyntax, 54 $formSyntax, 55 $postedValue, 56 $expectedWikiText, 57 $expectedValidationErrors, 58 $msg 59 ) { 60 $actualValidationErrors = []; 61 62 $actualWikiText = parent::send_form_action_template( 63 $formSyntax, 64 $templateSyntax, 65 $actualValidationErrors, 66 $postedValue 67 ); 68 69 if (empty($expectedValidationErrors)) { 70 $this->assertEquals($expectedWikiText, $actualWikiText, $msg); 71 } 72 $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg); 73 } 74 75 public function test_field_time_render() 76 { 77 $formSyntax = 'time "timeLabel"'; 78 $instr = p_get_instructions("<form>\n$formSyntax\n</form>"); 79 80 $actualHTML = p_render('xhtml', $instr, $info); 81 82 $expectedFieldHTML = '<label><span>timeLabel <sup>*</sup></span> <input type="text" name="bureaucracy[0]" class="timefield edit required" maxlength="8" required="required" /></label>'; 83 $expectedHTML = self::FORM_PREFIX_HTML . "\n$expectedFieldHTML\n" . self::FORM_SUFFIX_HTML; 84 $this->assertEquals(trim($expectedHTML), trim($actualHTML)); 85 } 86} 87