1<?php 2 3namespace dokuwiki\plugin\bureaucracy\test; 4 5use \Doku_Form; 6 7/** 8 * @group plugin_bureaucracyau 9 * @group plugins 10 */ 11class bureaucracyau_field_date_test extends BureaucracyTest 12{ 13 14 public function dataProvider() 15 { 16 return [ 17 [ 18 'Date:@@dateLabel@@', 19 'date "dateLabel"', 20 '2018-05-15', 21 'Date:2018-05-15', 22 [], 23 'valid date', 24 ], 25 [ 26 'Date:@@dateLabel@@', 27 'date "dateLabel"', 28 '2018.05.15', 29 null, 30 ['dateLabel'], 31 'invalid date', 32 ], 33 [ 34 'Date: @DATE(@@dateLabel@@)@', 35 'date "dateLabel"', 36 '2018-02-15', 37 'Date: 2018/02/15 00:00', 38 [], 39 'formatted date with $conf[\'dformat\'] format', 40 ], 41 [ 42 'Month: @DATE(@@dateLabel@@,%%m)@', 43 'date "dateLabel"', 44 '2018-02-15', 45 'Month: 02', 46 [], 47 'formatted date with custom format', 48 ], 49 ]; 50 } 51 52 /** 53 * @dataProvider dataProvider 54 * 55 * @param string $templateSyntax 56 * @param string $formSyntax 57 * @param string $postedValue 58 * @param string $expectedWikiText 59 * @param string $expectedValidationErrors 60 * @param string $msg 61 * 62 */ 63 public function test_field_date_submit( 64 $templateSyntax, 65 $formSyntax, 66 $postedValue, 67 $expectedWikiText, 68 $expectedValidationErrors, 69 $msg 70 ) { 71 $actualValidationErrors = []; 72 73 $actualWikiText = parent::send_form_action_template( 74 $formSyntax, 75 $templateSyntax, 76 $actualValidationErrors, 77 $postedValue 78 ); 79 80 if (empty($expectedValidationErrors)) { 81 $this->assertEquals($expectedWikiText, $actualWikiText, $msg); 82 } 83 $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg); 84 } 85 86 public function test_field_date_render() 87 { 88 $formSyntax = 'date "dateLabel"'; 89 $instr = p_get_instructions("<form>\n$formSyntax\n</form>"); 90 91 $actualHTML = p_render('xhtml', $instr, $info); 92 93 $expectedFieldHTML = '<label><span>dateLabel <sup>*</sup></span> <input type="text" name="bureaucracy[0]" class="datepicker edit required" maxlength="10" required="required" /></label>'; 94 $expectedHTML = self::FORM_PREFIX_HTML . "\n$expectedFieldHTML\n" . self::FORM_SUFFIX_HTML; 95 $this->assertEquals(trim($expectedHTML), trim($actualHTML)); 96 } 97} 98