diff options
Diffstat (limited to 'platform/www/lib/plugins/bureaucracy/_test')
17 files changed, 1740 insertions, 0 deletions
diff --git a/platform/www/lib/plugins/bureaucracy/_test/BureaucracyTest.php b/platform/www/lib/plugins/bureaucracy/_test/BureaucracyTest.php new file mode 100644 index 0000000..5a381e6 --- /dev/null +++ b/platform/www/lib/plugins/bureaucracy/_test/BureaucracyTest.php @@ -0,0 +1,69 @@ +<?php + +namespace dokuwiki\plugin\bureaucracy\test; + + +class BureaucracyTest extends \DokuWikiTest +{ + + const FORM_PREFIX_HTML = '<form class="bureaucracy__plugin" id="bureaucracy__plugin1" enctype="multipart/form-data" method="post" action="" accept-charset="utf-8"><div class="no"> +<input type="hidden" name="sectok" value="" /><input type="hidden" name="bureaucracy[$$id]" value="1" /><fieldset ><legend></legend>'; + const FORM_SUFFIX_HTML = '</fieldset> +</div></form>'; + + protected $pluginsEnabled = ['bureaucracy']; + + /** + * Simulate sending of bureaucracy form + * + * @param string|array $form_syntax syntax to build a bureaucracy form + * @param string $template_syntax syntax used as a page template for the "action template" + * @param array & $validation_errors field labels that were invalid + * @param string|array ...$values values passed to form handler + * + * @return string content of newly created page + */ + protected function send_form_action_template($form_syntax, $template_syntax, &$validation_errors, ...$values) + { + $id = uniqid('page', true); + $template_id = uniqid('template', true); + + //create full form syntax + if (is_array($form_syntax)) { + $form_syntax = implode("\n", $form_syntax); + } + $form_syntax = "<form>\naction template $template_id $id\n$form_syntax\n</form>"; + + saveWikiText($template_id, $template_syntax, 'summary'); + + /** @var \syntax_plugin_bureaucracy $syntax_plugin */ + $syntax_plugin = plugin_load('syntax', 'bureaucracy'); + $data = $syntax_plugin->handle($form_syntax, 0, 0, new \Doku_Handler()); + + $actionData = $data['actions'][0]; + /** @var \helper_plugin_bureaucracy_action $action */ + $action = plugin_load('helper', $actionData['actionname']); + //this is the only form + $form_id = 0; + + /** @var \helper_plugin_bureaucracy_field $field */ + foreach ($data['fields'] as $i => $field) { + if (!isset($values[$i])) { + $values[$i] = null; + } + + $isValid = $field->handle_post($values[$i], $data['fields'], $i, $form_id); + if (!$isValid) { + $validation_errors[] = $field->getParam('label'); + } + } + + $action->run( + $data['fields'], + $data['thanks'], + $actionData['argv'] + ); + + return rawWiki($id); + } +} diff --git a/platform/www/lib/plugins/bureaucracy/_test/actions_template.test.php b/platform/www/lib/plugins/bureaucracy/_test/actions_template.test.php new file mode 100644 index 0000000..befefc3 --- /dev/null +++ b/platform/www/lib/plugins/bureaucracy/_test/actions_template.test.php @@ -0,0 +1,88 @@ +<?php +/** + * @group plugin_bureaucracy + * @group plugins + */ +class syntax_plugin_bureaucracy_action_template_test extends DokuWikiTest { + + protected $pluginsEnabled = array('bureaucracy'); + + public function testPrepareLanguagePlaceholderNoTranslate() { + $action = $this->getTemplateClass(); + $action->prepareLanguagePlaceholder(); + + $this->assertEquals('en', $action->values['__lang__']); + $this->assertEquals('/@LANG@/', $action->patterns['__lang__']); + $this->assertEquals('', $action->values['__trans__']); + $this->assertEquals('/@TRANS@/', $action->patterns['__trans__']); + } + + public function testPrepareLanguagePlaceholderTranslateDefaultNS() { + global $conf; + global $ID; + + $conf['plugin']['translation']['translations'] = 'de'; + $ID = 'bla'; + + plugin_enable('translation'); + if (null === plugin_load('helper', 'translation')) return; + + $action = $this->getTemplateClass(); + $action->prepareLanguagePlaceholder(); + + $this->assertEquals('en', $action->values['__lang__']); + $this->assertEquals('/@LANG@/', $action->patterns['__lang__']); + $this->assertEquals('', $action->values['__trans__']); + $this->assertEquals('/@TRANS@/', $action->patterns['__trans__']); + } + + public function testPrepareLanguagePlaceholderTranslateLanguageNS() { + global $conf; + global $ID; + + $conf['plugin']['translation']['translations'] = 'de'; + $ID = 'de:bla'; + + plugin_enable('translation'); + $translation = plugin_load('helper', 'translation'); + if (null === $translation) return; + + $action = $this->getTemplateClass(); + $action->prepareLanguagePlaceholder(); + + $this->assertEquals('en', $action->values['__lang__']); + $this->assertEquals('/@LANG@/', $action->patterns['__lang__']); + $this->assertEquals('de', $action->values['__trans__']); + $this->assertEquals('/@TRANS@/', $action->patterns['__trans__']); + } + + public function testProcessFields() { + $data = array(); + /** @var helper_plugin_bureaucracy_fieldstatic $staticfield */ + $staticfield = plugin_load('helper', 'bureaucracy_fieldstatic'); + $staticfield->initialize(array('text', 'text1')); + $data[] = $staticfield; + + $action = $this->getTemplateClass(); + $action->prepareFieldReplacements($data, '_', ''); + + $this->assertEquals('/(@@|##)text1(?:\|(.*?))\1/si', $action->patterns['text1']); + $this->assertEquals('$2', $action->values['text1']); + $this->assertEmpty($action->targetpages); + } + + /** + * @return helper_plugin_bureaucracy_actiontemplate + */ + private function getTemplateClass() { + /** @var helper_plugin_bureaucracy_actiontemplate $templateaction */ + $templateaction = plugin_load('helper', 'bureaucracy_actiontemplate'); + $templateaction->patterns = array(); + $templateaction->values = array(); + $templateaction->targetpages = array(); + $templateaction->pagename = array(); + return $templateaction; + } + + +} diff --git a/platform/www/lib/plugins/bureaucracy/_test/actions_template_noreplace.test.php b/platform/www/lib/plugins/bureaucracy/_test/actions_template_noreplace.test.php new file mode 100644 index 0000000..dc54878 --- /dev/null +++ b/platform/www/lib/plugins/bureaucracy/_test/actions_template_noreplace.test.php @@ -0,0 +1,113 @@ +<?php + +namespace dokuwiki\plugin\bureaucracy\test; + +/** + * @group plugin_bureaucracy + * @group plugins + */ +class bureaucracy_actions_template_test extends BureaucracyTest { + + public function dataProvider() + { + return [ + [ + 'This is <noreplace>test</noreplace>.', + '', + '', + 'This is test.', + [], + '<noreplace></noreplace> not removed.', + ], + [ + '%Y-%m-%d <noreplace>%Y-%m-%d</noreplace>.', + '', + '', + date('Y-m-d') . ' %Y-%m-%d.', + [], + 'Date replaced inside <noreplace></noreplace>.', + ], + [ + '@@test@@ <noreplace>@@test@@</noreplace>.', + 'textbox test', + 'something', + 'something @@test@@.', + [], + 'Field value replaced inside <noreplace></noreplace>.', + ], + [ + '<noreplace>@ID@ @USER@ @MAIL@</noreplace>', + '', + '', + '@ID@ @USER@ @MAIL@', + [], + 'DokuWiki replacement paterns for templates replaced inside <noreplace></noreplace>.', + ], + [ + '<noreplace>@FORMPAGE_ID@ @FORMPAGE_NS@ @FORMPAGE_CURNS@</noreplace>', + '', + '', + '@FORMPAGE_ID@ @FORMPAGE_NS@ @FORMPAGE_CURNS@', + [], + '@FORMPAGE_*@ replacement paterns replaced inside <noreplace></noreplace>.', + ], + [ + '<noreplace><noinclude>TEST</noinclude></noreplace>', + '', + '', + '<noinclude>TEST</noinclude>', + [], + 'noinclude tag inside <replaced inside <noreplace></noreplace>.', + ], + [ + '<noreplace>@NSBASE@</noreplace>', + '', + '', + '@NSBASE@', + [], + '"@NSBASE@" replaced inside <noreplace></noreplace>.', + ], + [ + '<noreplace>%%</noreplace>', + '', + '', + '%%', + [], + '"%%" replaced inside <noreplace></noreplace>.', + ] + ]; + } + + /** + * @dataProvider dataProvider + * + * @param string $templateSyntax + * @param string $formSyntax + * @param string $postedValue + * @param string $expectedWikiText + * @param string $msg + * + */ + public function test_noreplace_tag( + $templateSyntax, + $formSyntax, + $postedValue, + $expectedWikiText, + $expectedValidationErrors, + $msg + ) { + $actualValidationErrors = []; + + $actualWikiText = parent::send_form_action_template( + $formSyntax, + $templateSyntax, + $actualValidationErrors, + $postedValue + ); + + if (empty($expectedValidationErrors)) { + $this->assertEquals($expectedWikiText, $actualWikiText, $msg); + } + $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg); + } +} diff --git a/platform/www/lib/plugins/bureaucracy/_test/field_date.test.php b/platform/www/lib/plugins/bureaucracy/_test/field_date.test.php new file mode 100644 index 0000000..3164630 --- /dev/null +++ b/platform/www/lib/plugins/bureaucracy/_test/field_date.test.php @@ -0,0 +1,97 @@ +<?php + +namespace dokuwiki\plugin\bureaucracy\test; + +use \Doku_Form; + +/** + * @group plugin_bureaucracy + * @group plugins + */ +class bureaucracy_field_date_test extends BureaucracyTest +{ + + public function dataProvider() + { + return [ + [ + 'Date:@@dateLabel@@', + 'date "dateLabel"', + '2018-05-15', + 'Date:2018-05-15', + [], + 'valid date', + ], + [ + 'Date:@@dateLabel@@', + 'date "dateLabel"', + '2018.05.15', + null, + ['dateLabel'], + 'invalid date', + ], + [ + 'Date: @DATE(@@dateLabel@@)@', + 'date "dateLabel"', + '2018-02-15', + 'Date: 2018/02/15 00:00', + [], + 'formatted date with $conf[\'dformat\'] format', + ], + [ + 'Month: @DATE(@@dateLabel@@,%%m)@', + 'date "dateLabel"', + '2018-02-15', + 'Month: 02', + [], + 'formatted date with custom format', + ], + ]; + } + + /** + * @dataProvider dataProvider + * + * @param string $templateSyntax + * @param string $formSyntax + * @param string $postedValue + * @param string $expectedWikiText + * @param string $expectedValidationErrors + * @param string $msg + * + */ + public function test_field_date_submit( + $templateSyntax, + $formSyntax, + $postedValue, + $expectedWikiText, + $expectedValidationErrors, + $msg + ) { + $actualValidationErrors = []; + + $actualWikiText = parent::send_form_action_template( + $formSyntax, + $templateSyntax, + $actualValidationErrors, + $postedValue + ); + + if (empty($expectedValidationErrors)) { + $this->assertEquals($expectedWikiText, $actualWikiText, $msg); + } + $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg); + } + + public function test_field_date_render() + { + $formSyntax = 'date "dateLabel"'; + $instr = p_get_instructions("<form>\n$formSyntax\n</form>"); + + $actualHTML = p_render('xhtml', $instr, $info); + + $expectedFieldHTML = '<label><span>dateLabel <sup>*</sup></span> <input type="text" name="bureaucracy[0]" class="datepicker edit required" maxlength="10" required="required" /></label>'; + $expectedHTML = self::FORM_PREFIX_HTML . "\n$expectedFieldHTML\n" . self::FORM_SUFFIX_HTML; + $this->assertEquals(trim($expectedHTML), trim($actualHTML)); + } +} diff --git a/platform/www/lib/plugins/bureaucracy/_test/field_email.test.php b/platform/www/lib/plugins/bureaucracy/_test/field_email.test.php new file mode 100644 index 0000000..c3c522a --- /dev/null +++ b/platform/www/lib/plugins/bureaucracy/_test/field_email.test.php @@ -0,0 +1,92 @@ +<?php + +namespace dokuwiki\plugin\bureaucracy\test; + +use \Doku_Form; + +/** + * @group plugin_bureaucracy + * @group plugins + */ +class bureaucracy_field_email_test extends BureaucracyTest +{ + + public function dataProvider() + { + return [ + [ + 'Mail: @@emailLabel@@', + 'valid@example.com', + 'Mail: valid@example.com', + [], + 'valid email', + ], + [ + 'Mail: @@emailLabel@@', + '@MAIL@', + 'Mail: @MAIL@', + [], + '@MAIL@ placeholder for user\'s email adress', + ], + [ + 'Mail: @@emailLabel@@', + 'invalid@example', + 'Mail: invalid@example', + [], + 'local email addresses are allowed', + ], + [ + 'Mail: @@emailLabel@@', + 'invalid[at]example.com', + null, + ['emailLabel'], + 'invalid email', + ], + ]; + } + + /** + * @dataProvider dataProvider + * + * @param string $templateSyntax + * @param $postedValue + * @param string $expectedWikiText + * @param string $expectedValidationErrors + * @param string $msg + * + */ + public function test_field_email_submit( + $templateSyntax, + $postedValue, + $expectedWikiText, + $expectedValidationErrors, + $msg + ) { + $actualValidationErrors = []; + + $label = 'emailLabel'; + $actualWikiText = parent::send_form_action_template( + "email \"$label\"", + $templateSyntax, + $actualValidationErrors, + $postedValue + ); + + if (empty($expectedValidationErrors)) { + $this->assertEquals($expectedWikiText, $actualWikiText, $msg); + } + $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg); + } + + public function test_field_email_render() + { + $formSyntax = 'email emailLabel'; + $instr = p_get_instructions("<form>\n$formSyntax\n</form>"); + + $actualHTML = p_render('xhtml', $instr, $info); + + $expectedFieldHTML = '<label><span>emailLabel <sup>*</sup></span> <input type="text" name="bureaucracy[0]" class="edit required" required="required" /></label>'; + $expectedHTML = self::FORM_PREFIX_HTML . "\n$expectedFieldHTML\n" . self::FORM_SUFFIX_HTML; + $this->assertEquals(trim($expectedHTML), trim($actualHTML)); + } +} diff --git a/platform/www/lib/plugins/bureaucracy/_test/field_file.test.php b/platform/www/lib/plugins/bureaucracy/_test/field_file.test.php new file mode 100644 index 0000000..628bff4 --- /dev/null +++ b/platform/www/lib/plugins/bureaucracy/_test/field_file.test.php @@ -0,0 +1,137 @@ +<?php +/** + * @group plugin_bureaucracy + * @group plugins + */ +class syntax_plugin_bureaucracy_fieldfile_test extends DokuWikiTest { + + protected $pluginsEnabled = array('bureaucracy'); + + /** + * Parse doku $syntax and check if any resulting xhtml element can be selected by $pqSelector + * + * @param $syntax + * @param $pqSelector + */ + protected function assertPqSelector($syntax, $pqSelector) { + $xhtml = p_render('xhtml', p_get_instructions($syntax), $info); + $doc = phpQuery::newDocument($xhtml); + $result = pq($pqSelector, $doc); + $this->assertEquals(1, $result->length, "selector: \"$pqSelector\" not found in\n$xhtml\n"); + } + + /** + * Chceck if defined namespace doesn't violate $standardArgs + */ + function test_syntax() { + $standardArgs = array( + '!' => 'input[type=file].edit', + '^' => 'input[type=file][required].edit.required', + '@' => 'input[type=file][required].edit.required', + '! /regex/' => 'input[type=file].edit', + '@ /regex/ "**Example error"' => 'input[type=file][required].edit.required' + ); + + //upload namespace not defined + foreach ($standardArgs as $arg => $pqSelector) { + $input = "<form>\nfile \"Some label\" $arg\n</form>"; + $this->assertPqSelector($input, $pqSelector); + } + + //upload namespace defined, nothing shoud change in syntax + foreach ($standardArgs as $arg => $pqSelector) { + $input = "<form>\nfile \"Some label\" upload:here $arg\n</form>"; + $this->assertPqSelector($input, $pqSelector); + } + + //upload namespace in "" + foreach ($standardArgs as $arg => $pqSelector) { + $input = "<form>\nfile \"Some label\" \"upload:here\" $arg\n</form>"; + $this->assertPqSelector($input, $pqSelector); + } + } + + /** + * Parse the bureaucracy form syntax and simulate a file upload + * + * @param $form_syntax bureaucracy form syntax containg only one file field + * @return string a name of the uploaded file + */ + protected function simulate_file_upload($form_syntax) { + $media = 'img.png'; + $media_src = mediaFN('wiki:dokuwiki-128.png'); + + $syntax_plugin = new syntax_plugin_bureaucracy(); + $data = $syntax_plugin->handle($form_syntax, 0, 0, new Doku_Handler()); + + $actionData = $data['actions'][0]; + $action = plugin_load('helper', $actionData['actionname']); + + $fileField = $data['fields'][0]; + + //mock file upload + $file = array( + 'name' => $media, + 'type' => 'image/png', + 'size' => filesize($media_src), + 'tmp_name' => $media_src + ); + //this is the only field + $index = 0; + //this is the only form + $form_id = 0; + $fileField->handle_post($file, $data['fields'], $index, $form_id); + + //upload file + $action->run( + $data['fields'], + $data['thanks'], + $actionData['argv'] + ); + + return $media; + } + + function test_action_template_upload_default() { + $template_id = 'template_upload_default'; + $id = 'upload_default'; + + saveWikiText($template_id, 'Value:@@Some label@@', 'summary'); + + $form_syntax = "<form>action template $template_id $id\nfile \"Some label\"\n</form>"; + $media = $this->simulate_file_upload($form_syntax); + + //check if file exists where we suspect it to be + $this->assertTrue(file_exists(mediaFN("$id:$media"))); + } + + function test_action_template_upload_absolute() { + $template_id = 'template_upload_absolute'; + $id = 'upload_absolute'; + $upload_ns = 'upload:ns'; + + saveWikiText($template_id, 'Value:@@Some label@@', 'summary'); + + $form_syntax = "<form>action template $template_id $id\nfile \"Some label\" $upload_ns\n</form>"; + $media = $this->simulate_file_upload($form_syntax); + + //check if file exists where we suspect it to be + $this->assertTrue(file_exists(mediaFN("$upload_ns:$media"))); + } + + function test_action_template_upload_relative() { + $template_id = 'template_upload_relative'; + $id = 'upload_relative'; + $upload_ns_rel = 'upload:ns'; + $upload_ns = ".:$upload_ns_rel"; + + saveWikiText($template_id, 'Value:@@Some label@@', 'summary'); + + $form_syntax = "<form>action template $template_id $id\nfile \"Some label\" \"$upload_ns\"\n</form>"; + $media = $this->simulate_file_upload($form_syntax); + + //check if file exists where we suspect it to be + $this->assertTrue(file_exists(mediaFN("$id:$upload_ns:$media"))); + } + +} diff --git a/platform/www/lib/plugins/bureaucracy/_test/field_hidden.test.php b/platform/www/lib/plugins/bureaucracy/_test/field_hidden.test.php new file mode 100644 index 0000000..386b28b --- /dev/null +++ b/platform/www/lib/plugins/bureaucracy/_test/field_hidden.test.php @@ -0,0 +1,77 @@ +<?php + +namespace dokuwiki\plugin\bureaucracy\test; + +use \Doku_Form; + +/** + * @group plugin_bureaucracy + * @group plugins + */ +class bureaucracy_field_hidden_test extends BureaucracyTest +{ + + public function dataProvider() + { + return [ + [ + 'hidden:@@hiddenLabel@@', + 'default value of the hidden field', + 'default value of the hidden field', + 'hidden:default value of the hidden field', + [], + 'valid hidden', + ], + ]; + } + + /** + * @dataProvider dataProvider + * + * @param string $templateSyntax + * @param $postedValue + * @param string $expectedWikiText + * @param string $expectedValidationErrors + * @param string $msg + * + */ + public function test_field_hidden_submit( + $templateSyntax, + $defaultValue, + $postedValue, + $expectedWikiText, + $expectedValidationErrors, + $msg + ) { + $actualValidationErrors = []; + + $label = 'hiddenLabel'; + $actualWikiText = parent::send_form_action_template( + "hidden \"$label\" \"=$defaultValue\"", + $templateSyntax, + $actualValidationErrors, + $postedValue + ); + + if (empty($expectedValidationErrors)) { + $this->assertEquals($expectedWikiText, $actualWikiText, $msg); + } + $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg); + } + + public function test_field_time_render() + { + $formSyntax = 'hidden hiddenLabel "=default value of the hidden field"'; + $instr = p_get_instructions("<form>\n$formSyntax\n</form>"); + + $actualHTML = p_render('xhtml', $instr, $info); + + $hiddenFormPrefix = '<form class="bureaucracy__plugin" id="bureaucracy__plugin1" enctype="multipart/form-data" method="post" action="" accept-charset="utf-8"><div class="no"> +<input type="hidden" name="sectok" value="" /><input type="hidden" name="bureaucracy[$$id]" value="1" />'; + $expectedFieldHTML = '<input type="hidden" name="bureaucracy[0]" value="default value of the hidden field" />'; + $hiddenFormSuffix = '</div></form>'; + $expectedHTML = "$hiddenFormPrefix$expectedFieldHTML$hiddenFormSuffix"; + + $this->assertEquals(trim($expectedHTML), trim($actualHTML)); + } +} diff --git a/platform/www/lib/plugins/bureaucracy/_test/field_multiselect.test.php b/platform/www/lib/plugins/bureaucracy/_test/field_multiselect.test.php new file mode 100644 index 0000000..9445dc2 --- /dev/null +++ b/platform/www/lib/plugins/bureaucracy/_test/field_multiselect.test.php @@ -0,0 +1,81 @@ +<?php + +namespace dokuwiki\plugin\bureaucracy\test; + +use Doku_Form; + +/** + * @group plugin_bureaucracy + * @group plugins + */ +class bureaucracy_field_multiselect_test extends BureaucracyTest +{ + + public function dataProvider() + { + return [ + [ + 'fruits: @@multiSelectLabel@@', + 'multiselect "multiSelectLabel" "Peaches|Apples|Oranges" =Peaches,Oranges', + ['Peaches','Apples'], + 'fruits: Peaches, Apples', + [], + 'default separator', + ], + [ + 'fruits: @@multiSelectLabel(;)@@', + 'multiselect "multiSelectLabel" "Peaches|Apples|Oranges" =Peaches,Oranges', + ['Peaches','Apples'], + 'fruits: Peaches;Apples', + [], + 'custom separator', + ], + ]; + } + + /** + * @dataProvider dataProvider + * + * @param string $templateSyntax + * @param string $formSyntax + * @param $postedValue + * @param string $expectedWikiText + * @param string $expectedValidationErrors + * @param string $msg + * + */ + public function test_field_multiselect_submit( + $templateSyntax, + $formSyntax, + $postedValue, + $expectedWikiText, + $expectedValidationErrors, + $msg + ) { + $actualValidationErrors = []; + + $actualWikiText = parent::send_form_action_template( + $formSyntax, + $templateSyntax, + $actualValidationErrors, + $postedValue + ); + + $this->assertEquals($expectedWikiText, $actualWikiText, $msg); + $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg); + } + + public function test_field_multiselect_render() + { + $formSyntax = 'multiselect "multiSelectLabel" "Peaches|Apples|Oranges" =Peaches,Oranges'; + $instr = p_get_instructions("<form>\n$formSyntax\n</form>"); + + $actualHTML = p_render('xhtml', $instr, $info); + + $expectedFieldHTML = '<label><span>multiSelectLabel <sup>*</sup></span> <select name="bureaucracy[0][]" multiple="multiple"> +<option value="Peaches" selected="selected">Peaches</option><option value="Apples">Apples</option><option value="Oranges" selected="selected">Oranges</option> +</select></label>'; + $expectedHTML = self::FORM_PREFIX_HTML . "\n$expectedFieldHTML\n" . self::FORM_SUFFIX_HTML; + $this->assertEquals(trim($expectedHTML), trim($actualHTML)); + } +} diff --git a/platform/www/lib/plugins/bureaucracy/_test/field_radio.test.php b/platform/www/lib/plugins/bureaucracy/_test/field_radio.test.php new file mode 100644 index 0000000..34839f6 --- /dev/null +++ b/platform/www/lib/plugins/bureaucracy/_test/field_radio.test.php @@ -0,0 +1,74 @@ +<?php + +namespace dokuwiki\plugin\bureaucracy\test; + +use Doku_Form; + +/** + * @group plugin_bureaucracy + * @group plugins + */ +class bureaucracy_field_radio_test extends BureaucracyTest +{ + + public function dataProvider() + { + return [ + [ + 'fruits:@@radioLabel@@', + 'radio "radioLabel" "Peaches|Apples|Oranges"', + 'Peaches', + 'fruits:Peaches', + [], + 'first option chosen', + ], + ]; + } + + /** + * @dataProvider dataProvider + * + * @param string $templateSyntax + * @param string $formSyntax + * @param $postedValue + * @param string $expectedWikiText + * @param string $expectedValidationErrors + * @param string $msg + * + */ + public function test_field_radio_submit( + $templateSyntax, + $formSyntax, + $postedValue, + $expectedWikiText, + $expectedValidationErrors, + $msg + ) { + $actualValidationErrors = []; + + $label = 'radio'; + $actualWikiText = parent::send_form_action_template( + $formSyntax, + $templateSyntax, + $actualValidationErrors, + $postedValue + ); + + $this->assertEquals($expectedWikiText, $actualWikiText, $msg); + $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg); + } + + public function test_field_date_render() + { + $formSyntax = 'radio "radioLabel" "Peaches|Apples|Oranges"'; + $instr = p_get_instructions("<form>\n$formSyntax\n</form>"); + + $actualHTML = p_render('xhtml', $instr, $info); + + $expectedFieldHTML = '<label class="radiolabel "><span>radioLabel <sup>*</sup></span></label><label><input type="radio" name="bureaucracy[0]" value="Peaches" /> <span>Peaches</span></label> +<label><input type="radio" name="bureaucracy[0]" value="Apples" /> <span>Apples</span></label> +<label><input type="radio" name="bureaucracy[0]" value="Oranges" /> <span>Oranges</span></label>'; + $expectedHTML = self::FORM_PREFIX_HTML . "\n$expectedFieldHTML\n" . self::FORM_SUFFIX_HTML; + $this->assertEquals(trim($expectedHTML), trim($actualHTML)); + } +} diff --git a/platform/www/lib/plugins/bureaucracy/_test/field_time.test.php b/platform/www/lib/plugins/bureaucracy/_test/field_time.test.php new file mode 100644 index 0000000..b027d8c --- /dev/null +++ b/platform/www/lib/plugins/bureaucracy/_test/field_time.test.php @@ -0,0 +1,86 @@ +<?php + +namespace dokuwiki\plugin\bureaucracy\test; + +/** + * @group plugin_bureaucracy + * @group plugins + */ +class bureaucracy_field_time_test extends BureaucracyTest +{ + + public function dataProvider() + { + return [ + [ + 'time:@@timeLabel@@', + 'time timeLabel', + '10:32', + 'time:10:32', + [], + 'valid time without seconds', + ], + [ + 'time:@@timeLabel@@', + 'time timeLabel', + '10:32:44', + 'time:10:32:44', + [], + 'valid time with seconds', + ], + [ + 'time:@@timeLabel@@', + 'time timeLabel', + '1032', + null, + ['timeLabel'], + 'invalid time', + ], + ]; + } + + /** + * @dataProvider dataProvider + * + * @param string $templateSyntax + * @param string $formSyntax + * @param string $postedValue + * @param string $expectedWikiText + * @param string[] $expectedValidationErrors + * @param string $msg + */ + public function test_field_time_submit( + $templateSyntax, + $formSyntax, + $postedValue, + $expectedWikiText, + $expectedValidationErrors, + $msg + ) { + $actualValidationErrors = []; + + $actualWikiText = parent::send_form_action_template( + $formSyntax, + $templateSyntax, + $actualValidationErrors, + $postedValue + ); + + if (empty($expectedValidationErrors)) { + $this->assertEquals($expectedWikiText, $actualWikiText, $msg); + } + $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg); + } + + public function test_field_time_render() + { + $formSyntax = 'time "timeLabel"'; + $instr = p_get_instructions("<form>\n$formSyntax\n</form>"); + + $actualHTML = p_render('xhtml', $instr, $info); + + $expectedFieldHTML = '<label><span>timeLabel <sup>*</sup></span> <input type="text" name="bureaucracy[0]" class="timefield edit required" maxlength="8" required="required" /></label>'; + $expectedHTML = self::FORM_PREFIX_HTML . "\n$expectedFieldHTML\n" . self::FORM_SUFFIX_HTML; + $this->assertEquals(trim($expectedHTML), trim($actualHTML)); + } +} diff --git a/platform/www/lib/plugins/bureaucracy/_test/field_user.test.php b/platform/www/lib/plugins/bureaucracy/_test/field_user.test.php new file mode 100644 index 0000000..a7ade9b --- /dev/null +++ b/platform/www/lib/plugins/bureaucracy/_test/field_user.test.php @@ -0,0 +1,209 @@ +<?php + +namespace dokuwiki\plugin\bureaucracy\test; + +/** + * @group plugin_bureaucracy + * @group plugins + */ +class syntax_plugin_bureaucracy_fielduser_test extends BureaucracyTest +{ + + /** + * Create some users + */ + public function setUp(): void + { + parent::setUp(); + + /** @var \DokuWiki_Auth_Plugin $auth */ + global $auth; + + $auth->createUser("user1", "54321", "user1Name", "user1@example.com"); + $auth->createUser("user2", "543210", "user2Name", "user2@example.com"); + $auth->createUser("mwuser", "12345", "Wiki User", "wikiuser@example.com", ['group1', 'group2']); + } + + public function dataProvider() + { + return [ + [ + 'user:@@user@@', + 'user user', + 'mwuser', + 'user:mwuser', + [], + 'default substitution', + ], + [ + 'user:@@user@@', + 'user user', + '', + 'user:', + ['user'], + 'error for empty substitution', + ], + [ + 'user:@@user@@', + 'user user !', + '', + 'user:', + [], + 'ok for empty substitution in optional field', + ], + [ + 'user:@@user.name@@', + 'user user', + 'mwuser', + 'user:Wiki User', + [], + 'name substitution', + ], + [ + 'user:@@user.mail@@', + 'user user', + 'mwuser', + 'user:wikiuser@example.com', + [], + 'mail substitution', + ], + [ + 'user:@@user.grps@@', + 'user user', + 'mwuser', + 'user:group1, group2', + [], + 'groups substitution', + ], + [ + 'user:@@user.grps(;)@@', + 'user user', + 'mwuser', + 'user:group1;group2', + [], + 'groups substitution custom delimiter', + ], + [ + 'user:@@user.grps())@@', + 'user user', + 'mwuser', + 'user:group1)group2', + [], + 'groups substitution custom delimiter with brackets', + ], + [ + 'user:@@user.no_sutch_attribute@@', + 'user user', + 'mwuser', + 'user:@@user.no_sutch_attribute@@', + [], + 'template unknown attribute substitution', + ], + [ + 'user:##user##', + 'user user', + 'mwuser', + 'user:mwuser', + [], + 'hash substitution', + ], + [ + 'user:##user.mail##', + 'user user', + 'mwuser', + 'user:wikiuser@example.com', + [], + 'hash substitution with attribute', + ], + [ + 'user:##user@@', + 'user user', + 'mwuser', + 'user:##user@@', + [], + 'hash substitution sign mismatch', + ], + [ + "user:@@user@@\n\nmail:@@user.mail@@\n\ngrps:@@user.grps(\n)@@", + 'user user', + 'mwuser', + "user:mwuser\n\nmail:wikiuser@example.com\n\ngrps:group1\ngroup2", + [], + 'multiple replacements', + ], + [ + "grps1:@@user.grps(\n)@@\n\ngrps2:@@user.grps(())@@", + 'user user', + 'mwuser', + "grps1:group1\ngroup2\n\ngrps2:group1()group2", + [], + 'groups twice', + ], + [ + 'grps:@@user.grps(end))@@', + 'user user', + 'mwuser', + 'grps:group1end)group2', + [], + 'groups special glue', + ], + [ + 'grps:@@user.grps()@@', + 'user user', + 'mwuser', + 'grps:group1group2', + [], + 'groups with empty delimiter', + ], + [ + 'user:@@user@@', + 'user user', + 'non_existant_user', + 'user:non_existant_user', + ['user'], + 'error for non existant user', + ], + [ + 'user:@@user.name@@', + 'user user', + 'non_existant_user', + 'user:@@user.name@@', + ['user'], + 'error for non existant user with attribute', + ], + ]; + } + + + /** + * @dataProvider dataProvider + * + * @param string $templateSyntax + * @param string $formSyntax + * @param string $postedValue value of 'user' field + * @param string $expectedWikiText + * @param string $expectedValidationErrors + * @param string $msg + * + */ + public function test_field_user( + $templateSyntax, + $formSyntax, + $postedValue, + $expectedWikiText, + $expectedValidationErrors, + $msg + ) { + $actualValidationErrors = []; + + $actualWikiText = parent::send_form_action_template( + $formSyntax, + $templateSyntax, + $actualValidationErrors, + $postedValue + ); + + $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg); + $this->assertEquals($expectedWikiText, $actualWikiText, $msg); + } +} diff --git a/platform/www/lib/plugins/bureaucracy/_test/field_users.test.php b/platform/www/lib/plugins/bureaucracy/_test/field_users.test.php new file mode 100644 index 0000000..633be20 --- /dev/null +++ b/platform/www/lib/plugins/bureaucracy/_test/field_users.test.php @@ -0,0 +1,168 @@ +<?php + +namespace dokuwiki\plugin\bureaucracy\test; + +/** + * @group plugin_bureaucracy + * @group plugins + */ +class syntax_plugin_bureaucracy_fieldusers_test extends BureaucracyTest +{ + + /** + * Create some users + */ + public function setUp(): void + { + parent::setUp(); + + /** @var \DokuWiki_Auth_Plugin $auth */ + global $auth; + + $auth->createUser('user1', '54321', 'user1Name', 'user1@example.com'); + $auth->createUser('user2', '543210', 'user2Name', 'user2@example.com'); + $auth->createUser('mwuser', '12345', 'Wiki User', 'me@example.com', ['group1', 'group2']); + } + + public function dataProvider() + { + return [ + [ + 'users:@@users@@', + 'users users', + 'user1, user2', + 'users:user1, user2', + [], + 'default substitution', + ], + [ + 'users:@@users@@', + 'users users', + '', + 'users:', + ['users'], + 'error for empty substitution', + ], + [ + 'users:@@users(;)@@', + 'users users', + 'user1, user2', + 'users:user1;user2', + [], + 'custom delimiter', + ], + [ + "users:@@users(\n)@@", + 'users users', + 'user1, user2', + "users:user1\nuser2", + [], + 'newline delimiter', + ], + [ + 'users:@@users()@@', + 'users users', + 'user1, user2', + 'users:user1user2', + [], + 'empty delimiter', + ], + [ + 'users:@@users.name@@', + 'users users', + 'user1, user2', + 'users:user1Name, user2Name', + [], + 'names substitution default delitmiter', + ], + [ + 'users:@@users(;).name@@', + 'users users', + 'user1, user2', + 'users:user1Name;user2Name', + [], + 'names substitution custom delitmiter', + ], + [ + 'users:@@users.mail@@', + 'users users', + 'user1, user2', + 'users:user1@example.com, user2@example.com', + [], + 'mail substitution default delitmiter', + ], + [ + "mails:@@users.mail@@\n\nnames:@@users(\n).name@@", + 'users users', + 'user1, user2', + "mails:user1@example.com, user2@example.com\n\nnames:user1Name\nuser2Name", + [], + 'multiple replacements', + ], + [ + 'users:@@users@@', + 'users users', + 'not_existing1, not_existing2', + 'users:not_existing1, not_existing2', + ['users'], + 'unknown users should cause errors', + ], + [ + 'users:@@users.unknown_attribute@@', + 'users users', + 'user1, user2', + 'users:@@users.unknown_attribute@@', + [], + 'non existant attribute is not replaced', + ], + [ + 'users:@@*]]@@', // the label must be something to break a regex when not properly quoted + 'users "*]]"', + 'user1, user2', + 'users:user1, user2', + [], + 'ensure label desn\'t break regex', + ], + [ + 'users:@@tHis Is UsEr@@', + 'users "tHis Is UsEr"', + 'user1, user2', + 'users:user1, user2', + [], + 'label with spaces and mixed case', + ], + ]; + } + + /** + * @dataProvider dataProvider + * + * @param string $templateSyntax + * @param string $formSyntax + * @param string $postedValue value of 'users' field + * @param string $expectedWikiText + * @param string $expectedValidationErrors + * @param string $msg + * + */ + public function test_field_users( + $templateSyntax, + $formSyntax, + $postedValue, + $expectedWikiText, + $expectedValidationErrors, + $msg + ) { + $actualValidationErrors = []; + + $actualWikiText = parent::send_form_action_template( + $formSyntax, + $templateSyntax, + $actualValidationErrors, + $postedValue + ); + + $this->assertEquals($expectedWikiText, $actualWikiText, $msg); + $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg); + } +} diff --git a/platform/www/lib/plugins/bureaucracy/_test/field_yesno.test.php b/platform/www/lib/plugins/bureaucracy/_test/field_yesno.test.php new file mode 100644 index 0000000..26bd785 --- /dev/null +++ b/platform/www/lib/plugins/bureaucracy/_test/field_yesno.test.php @@ -0,0 +1,70 @@ +<?php + +namespace dokuwiki\plugin\bureaucracy\test; + +/** + * @group plugin_bureaucracy + * @group plugins + */ +class bureaucracy_field_yesno_test extends BureaucracyTest +{ + + public function dataProvider() + { + return [ + [ + 'cb:@@checkbox@@', + '"=Yes"', + '"!No"', + '1', + 'cb:Yes', + [], + 'default checked substitution', + ], + [ + 'cb:@@checkbox@@', + '"=Yes"', + '"!No"', + '0', + 'cb:No', + [], + 'default unchecked substitution', + ], + ]; + } + + /** + * @dataProvider dataProvider + * + * @param string $templateSyntax + * @param $YesValue + * @param $NoValue + * @param $isChecked + * @param string $expectedWikiText + * @param string $expectedValidationErrors + * @param string $msg + * + */ + public function test_field_yesno( + $templateSyntax, + $YesValue, + $NoValue, + $isChecked, + $expectedWikiText, + $expectedValidationErrors, + $msg + ) { + $actualValidationErrors = []; + + $label = 'checkbox'; + $actualWikiText = parent::send_form_action_template( + "yesno \"$label\" $YesValue $NoValue", + $templateSyntax, + $actualValidationErrors, + $isChecked + ); + + $this->assertEquals($expectedWikiText, $actualWikiText, $msg); + $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg); + } +}
\ No newline at end of file diff --git a/platform/www/lib/plugins/bureaucracy/_test/general.test.php b/platform/www/lib/plugins/bureaucracy/_test/general.test.php new file mode 100644 index 0000000..0b3e0cf --- /dev/null +++ b/platform/www/lib/plugins/bureaucracy/_test/general.test.php @@ -0,0 +1,61 @@ +<?php +/** + * General tests for the bureaucracy plugin + * + * @group plugin_bureaucracy + * @group plugins + */ +class general_plugin_bureaucracy_test extends DokuWikiTest { + + /** + * Simple test to make sure the plugin.info.txt is in correct format + */ + public function test_plugininfo() { + $file = __DIR__.'/../plugin.info.txt'; + $this->assertFileExists($file); + + $info = confToHash($file); + + $this->assertArrayHasKey('base', $info); + $this->assertArrayHasKey('author', $info); + $this->assertArrayHasKey('email', $info); + $this->assertArrayHasKey('date', $info); + $this->assertArrayHasKey('name', $info); + $this->assertArrayHasKey('desc', $info); + $this->assertArrayHasKey('url', $info); + + $this->assertEquals('bureaucracy', $info['base']); + $this->assertRegExp('/^https?:\/\//', $info['url']); + $this->assertTrue(mail_isvalid($info['email'])); + $this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']); + $this->assertTrue(false !== strtotime($info['date'])); + } + + /** + * Test to ensure that every conf['...'] entry in conf/default.php has a corresponding meta['...'] entry in + * conf/metadata.php. + */ + public function test_plugin_conf() { + $conf_file = __DIR__.'/../conf/default.php'; + if (file_exists($conf_file)){ + include($conf_file); + } + $meta_file = __DIR__.'/../conf/metadata.php'; + if (file_exists($meta_file)) { + include($meta_file); + } + + $this->assertEquals(gettype($conf), gettype($meta),'Both ' . DOKU_PLUGIN . 'bureaucracy/conf/default.php and ' . DOKU_PLUGIN . 'bureaucracy/conf/metadata.php have to exist and contain the same keys.'); + + if (gettype($conf) != 'NULL' && gettype($meta) != 'NULL') { + foreach($conf as $key => $value) { + $this->assertArrayHasKey($key, $meta, 'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'bureaucracy/conf/metadata.php'); + } + + foreach($meta as $key => $value) { + $this->assertArrayHasKey($key, $conf, 'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'bureaucracy/conf/default.php'); + } + } + + } +} diff --git a/platform/www/lib/plugins/bureaucracy/_test/input.txt b/platform/www/lib/plugins/bureaucracy/_test/input.txt new file mode 100644 index 0000000..6b395ed --- /dev/null +++ b/platform/www/lib/plugins/bureaucracy/_test/input.txt @@ -0,0 +1,38 @@ +<form> +action template userstpl users:%Y:@@What's your Name?@@:start + +Fieldset "A set of fields" +Textbox "Employee Name" "=Your Name" +number "Your Age" >13 <99 +email "Your E-Mail Address" +textbox "Occupation (optional)" ! +password "Some password" +file "File1" + +fieldset "HTML Checks <bold>bang</bold>" "<bold>bang</bold>" "<bold>bang</bold>" +textbox "HTML check 1 <bold>bang</bold>" "=<bold>bang</bold>" +password "HTML check 2 <bold>bang</bold>" "=<bold>bang</bold>" +textarea "HTML check 3 <bold>bang</bold>" "=<bold>bang</bold>" +static "HTML check 4 <bold>bang</bold>" +wiki "HTML check 5 <bold>bang</bold>" + +fieldset "even more fields" +select "Please select an option" "Peaches|Apples|Oranges" +static "Some static text that could be an agreement" +yesno "Read the agreement?" +textarea "Tell me about your self" +textbox "You need to write 'agree' here" /^agree$/ + +fieldset "Create Your User Page" +select "What's your Continent?" "Europe|N. America|S. America|Asia|Australia" +textbox "What's your Name?" +textarea "Enter a short bio" ! +yesno "Do have publication?" + +fieldset "Add your publications" "Do have publication?" +textarea "Publications:" +addpage users:publicationtemplate publications + +fieldset "Finish" +submit "Submit Query" +</form>
\ No newline at end of file diff --git a/platform/www/lib/plugins/bureaucracy/_test/replace_functions.test.php b/platform/www/lib/plugins/bureaucracy/_test/replace_functions.test.php new file mode 100644 index 0000000..d4104de --- /dev/null +++ b/platform/www/lib/plugins/bureaucracy/_test/replace_functions.test.php @@ -0,0 +1,142 @@ +<?php + +namespace dokuwiki\plugin\bureaucracy\test; + +use \Doku_Form; + +/** + * @group plugin_bureaucracy + * @group plugins + */ +class bureaucracy_replace_functions_test extends BureaucracyTest +{ + + public function dataProvider() + { + return [ + [ + '@curNS@', + '', + '', + '@curNS@', + [], + '"@function@" shouldn\'t be replaced.', + ], + [ + '@curNS()@', + '', + '', + '', + [], + '"@function()@" should return empty string.', + ], + [ + '(@noNS(test):page)@)', //test doubled bracket + '', + '', + '(page)', + [], + '"@curNS(test:page))@" should return empty string.', + ], + [ + '@curNS(test:static:value)@', + '', + '', + 'static', + [], + '@curNS()@ doesn\'t work.', + ], + [ + '@curNS(@@page@@)@', + 'textbox page', + 'some:test:page', + 'test', + [], + '@curNS()@ doesn\'t work.', + ], + [ + '@getNS(@@page@@)@', + 'textbox page', + 'some:test:page', + 'some:test', + [], + '@getNS()@ doesn\'t work.', + ], + [ + '@getNS(test:static:value)@', + '', + '', + 'test:static', + [], + '@getNS()@ doesn\'t work.', + ], + [ + '@noNS(test:static:value)@', + '', + '', + 'value', + [], + '@noNS()@ doesn\'t work.', + ], + [ + '@noNS(@@page@@)@', + 'textbox page', + 'some:test:page', + 'page', + [], + '@noNS()@ doesn\'t work.', + ] + ]; + } + + /** + * @dataProvider dataProvider + * + * @param string $templateSyntax + * @param string $formSyntax + * @param string $postedValue + * @param string $expectedWikiText + * @param string $expectedValidationErrors + * @param string $msg + * + */ + public function test_NS_functions( + $templateSyntax, + $formSyntax, + $postedValue, + $expectedWikiText, + $expectedValidationErrors, + $msg + ) { + $actualValidationErrors = []; + + $actualWikiText = parent::send_form_action_template( + $formSyntax, + $templateSyntax, + $actualValidationErrors, + $postedValue + ); + + if (empty($expectedValidationErrors)) { + $this->assertEquals($expectedWikiText, $actualWikiText, $msg); + } + $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg); + } + + public function test_p_get_first_heading_function() { + //create page with heading + $wikitext = "====== Header 1 ======\n"; + $page = 'some:test:page'; + saveWikiText($page, $wikitext, 'summary'); + + $actualValidationErrors = []; + $actualWikiText = parent::send_form_action_template( + 'textbox page', + '@p_get_first_heading(@@page@@)@', + $actualValidationErrors, + $page + ); + + $this->assertEquals('Header 1', $actualWikiText); + } +} diff --git a/platform/www/lib/plugins/bureaucracy/_test/syntax.test.php b/platform/www/lib/plugins/bureaucracy/_test/syntax.test.php new file mode 100644 index 0000000..9b552e0 --- /dev/null +++ b/platform/www/lib/plugins/bureaucracy/_test/syntax.test.php @@ -0,0 +1,138 @@ +<?php +/** + * @group plugin_bureaucracy + * @group plugins + */ +class syntax_plugin_bureaucracy_test extends DokuWikiTest { + + protected $pluginsEnabled = array('bureaucracy'); + + public function test_generalFormOutput() { + $input = file_get_contents(dirname(__FILE__) . '/input.txt'); + $xhtml = p_render('xhtml', p_get_instructions($input), $info); + + $doc = phpQuery::newDocument($xhtml); + + $this->assertEquals(1, pq('form.bureaucracy__plugin', $doc)->length); + $this->assertEquals(6, pq('form.bureaucracy__plugin fieldset', $doc)->length); + + // standard input types + $this->checkField($doc, 'Employee Name', 'input[type=text][value=Your Name].edit', true); + $this->checkField($doc, 'Your Age', 'input[type=text].edit', true); + $this->checkField($doc, 'Your E-Mail Address', 'input[type=text].edit', true); + $this->checkField($doc, 'Occupation (optional)', 'input[type=text].edit'); + $this->checkField($doc, 'Some password', 'input[type=password].edit', true); + + // select field + $select = $this->checkField($doc, 'Please select an option', 'select'); + $this->assertEquals(3, pq('option', $select)->length); + $this->assertEquals(1, pq('option:selected', $select)->length); + $this->assertEquals('Peaches', pq('option:selected', $select)->val()); + + // static text + $this->assertEquals(1, pq('p:contains(Some static text)', $doc)->length); + + // checkbox + $cb = $this->checkField($doc, 'Read the agreement?', 'input[type=checkbox][value=1]'); + $this->assertEquals('1', pq('input[type=hidden][value=0]', $cb->parent())->length); + + // text area + $this->checkField($doc, 'Tell me about your self', 'textarea.edit', true); + + // file field + $this->checkField($doc, 'File1', 'input[type=file].edit', true); + + // submit button + $this->assertEquals(1, pq('button[type=submit]:contains(Submit Query)')->length); + + } + + public function test_HTMLinclusion() { + $input = file_get_contents(dirname(__FILE__) . '/input.txt'); + $xhtml = p_render('xhtml', p_get_instructions($input), $info); + + $doc = phpQuery::newDocument($xhtml); + + // HTML Check - there should be no bold tag anywhere + $this->assertEquals(0, pq('bold', $doc)->length); + } + + private function checkField($doc, $name, $check, $required=false) { + + $field = pq('form.bureaucracy__plugin label span:contains(' . $name . ')', $doc); + $this->assertEquals(1, $field->length, "find span of $name"); + + if($required){ + $this->assertEquals(1, pq('sup', $field)->length, "is mandatory of $name"); + } + + $label = $field->parent(); + $this->assertTrue($label->is('label'), "find label of $name"); + + $input = pq($check, $label); + $this->assertEquals(1, $input->length, "find check of $name"); + + return $input; + } + + public function test_parseline() { + $match = 'textbox label0 "Test with spaces" +textbox LabelWithoutSpaces +textbox Label Without Spaces +textbox "Label with spaces" "Text with a quote""in text" +textbox Label2 " " +textbox Label3 """" +textbox Label4 " """ " """ " """ +textbox Label5 """ " +textbox Label6 "" " " +textbox Label7 " "" " +textbox Label7 " "" + "" ss" +textbox Label8'; + + $expected = array( + array('textbox', 'label0', 'Test with spaces'), + array('textbox', 'LabelWithoutSpaces'), + array('textbox', 'Label', 'Without', 'Spaces'), + array('textbox', 'Label with spaces', 'Text with a quote"in text'), + array('textbox', 'Label2', ' '), + array('textbox', 'Label3', '"'), + array('textbox', 'Label4', ' "', ' "', ' "'), + array('textbox', 'Label5', '" '), + array('textbox', 'Label6', '', ' '), + array('textbox', 'Label7', ' " '), + array('textbox', 'Label7', ' " + " ss'), + array('textbox', 'Label8') + ); + + $lines = explode("\n", $match); + $i = 0; + while(count($lines) > 0) { + $line = trim(array_shift($lines)); + + $syntaxcomponent = new syntax_plugin_bureaucracy(); + $actual = $this->callNonaccessibleMethod($syntaxcomponent, '_parse_line', array($line, &$lines)); + + $this->assertEquals($expected[$i], $actual); + $i++; + } + + } + + /** + * Test not accessible methods.. + * + * @param string|object $obj + * @param string $name + * @param array $args + * @return mixed + */ + protected function callNonaccessibleMethod($obj, $name, array $args) { + $class = new ReflectionClass($obj); + $method = $class->getMethod($name); + $method->setAccessible(true); + return $method->invokeArgs($obj, $args); + } + +} |