1<?php 2 3namespace dokuwiki\plugin\bureaucracyau\test; 4 5 6class BureaucracyauTest extends \DokuWikiTest 7{ 8 9 const FORM_PREFIX_HTML = '<form class="bureaucracyau__plugin" id="bureaucracyau__plugin1" enctype="multipart/form-data" method="post" action="" accept-charset="utf-8"><div class="no"> 10<input type="hidden" name="sectok" value="" /><input type="hidden" name="bureaucracyau[$$id]" value="1" /><fieldset ><legend></legend>'; 11 const FORM_SUFFIX_HTML = '</fieldset> 12</div></form>'; 13 14 protected $pluginsEnabled = ['bureaucracyau']; 15 16 /** 17 * Simulate sending of bureaucracyau form 18 * 19 * @param string|array $form_syntax syntax to build a bureaucracyau form 20 * @param string $template_syntax syntax used as a page template for the "action template" 21 * @param array & $validation_errors field labels that were invalid 22 * @param string|array ...$values values passed to form handler 23 * 24 * @return string content of newly created page 25 */ 26 protected function send_form_action_template($form_syntax, $template_syntax, &$validation_errors, ...$values) 27 { 28 $id = uniqid('page', true); 29 $template_id = uniqid('template', true); 30 31 //create full form syntax 32 if (is_array($form_syntax)) { 33 $form_syntax = implode("\n", $form_syntax); 34 } 35 $form_syntax = "<form>\naction template $template_id $id\n$form_syntax\n</form>"; 36 37 saveWikiText($template_id, $template_syntax, 'summary'); 38 39 /** @var \syntax_plugin_bureaucracyau $syntax_plugin */ 40 $syntax_plugin = plugin_load('syntax', 'bureaucracyau'); 41 $data = $syntax_plugin->handle($form_syntax, 0, 0, new \Doku_Handler()); 42 43 $actionData = $data['actions'][0]; 44 /** @var \helper_plugin_bureaucracyau_action $action */ 45 $action = plugin_load('helper', $actionData['actionname']); 46 //this is the only form 47 $form_id = 0; 48 49 /** @var \helper_plugin_bureaucracyau_field $field */ 50 foreach ($data['fields'] as $i => $field) { 51 if (!isset($values[$i])) { 52 $values[$i] = null; 53 } 54 55 $isValid = $field->handle_post($values[$i], $data['fields'], $i, $form_id); 56 if (!$isValid) { 57 $validation_errors[] = $field->getParam('label'); 58 } 59 } 60 61 $action->run( 62 $data['fields'], 63 $data['thanks'], 64 $actionData['argv'] 65 ); 66 67 return rawWiki($id); 68 } 69} 70