|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace dokuwiki\plugin\struct\test; |
| 4 | + |
| 5 | +use dokuwiki\plugin\struct\meta; |
| 6 | +use dokuwiki\plugin\struct\meta\AccessTable; |
| 7 | + |
| 8 | +/** |
| 9 | + * Tests for the integration with Bureaucracy plugin |
| 10 | + * |
| 11 | + * @group plugin_struct |
| 12 | + * @group plugins |
| 13 | + * |
| 14 | + */ |
| 15 | +class Bureaucracy_struct_test extends StructTest { |
| 16 | + |
| 17 | + /** @var array alway enable the needed plugins */ |
| 18 | + protected $pluginsEnabled = array('struct', 'sqlite', 'bureaucracy'); |
| 19 | + |
| 20 | + /** @var array of lookup data */ |
| 21 | + protected $lookup = array(); |
| 22 | + |
| 23 | + public function setUp() { |
| 24 | + parent::setUp(); |
| 25 | + |
| 26 | + $this->loadSchemaJSON('bureaucracy_lookup', '', 0, true); |
| 27 | + $this->loadSchemaJSON('bureaucracy'); |
| 28 | + |
| 29 | + //insert some data to lookup |
| 30 | + for($i = 1; $i <= 10; ++$i) { |
| 31 | + $data = array( |
| 32 | + 'lookup_first' => 'value first ' . $i, |
| 33 | + 'lookup_second' => 'value second ' . $i |
| 34 | + ); |
| 35 | + |
| 36 | + $lookupData = AccessTable::byTableName('bureaucracy_lookup', 0); |
| 37 | + $lookupData->saveData($data); |
| 38 | + $this->lookup[] = $lookupData; |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + public function test_bureaucracy_lookup_replacement_empty() { |
| 43 | + //page created by bureaucracy |
| 44 | + $id = 'bureaucracy_lookup_replacement_empty'; |
| 45 | + //id of template page |
| 46 | + $template_id = 'template'; |
| 47 | + |
| 48 | + //create template |
| 49 | + saveWikiText($template_id, 'Value:@@bureaucracy.lookup_select@@', 'summary'); |
| 50 | + |
| 51 | + //build form |
| 52 | + $fields = array(); |
| 53 | + |
| 54 | + $lookup_field = plugin_load('helper', 'struct_field'); |
| 55 | + $lookup_field->opt['label'] = 'bureaucracy.lookup_select'; |
| 56 | + //empty value |
| 57 | + $lookup_field->opt['value'] = ''; |
| 58 | + //left pagename undefined |
| 59 | + //$lookup_field->opt['pagename']; |
| 60 | + |
| 61 | + //$args are ommited in struct_field |
| 62 | + $lookup_field->initialize(array()); |
| 63 | + $fields[] = $lookup_field; |
| 64 | + |
| 65 | + //helper_plugin_bureaucracy_actiontemplate |
| 66 | + $actiontemplate = plugin_load('helper', 'bureaucracy_actiontemplate'); |
| 67 | + $actiontemplate->run($fields, '', array($template_id, $id, '_')); |
| 68 | + |
| 69 | + $page_content = io_readWikiPage(wikiFN($id), $id); |
| 70 | + |
| 71 | + $this->assertEquals('Value:', $page_content); |
| 72 | + } |
| 73 | + |
| 74 | + public function test_bureaucracy_lookup_replacement() { |
| 75 | + //page created by bureaucracy |
| 76 | + $id = 'bureaucracy_lookup_replacement'; |
| 77 | + //id of template page |
| 78 | + $template_id = 'template'; |
| 79 | + //pid of selected value |
| 80 | + $lookup_pid = $this->lookup[0]->getPid(); |
| 81 | + //selected value |
| 82 | + $lookup_value = $this->lookup[0]->getData()['lookup_first']->getValue(); |
| 83 | + |
| 84 | + //create template |
| 85 | + saveWikiText($template_id, 'Value:@@bureaucracy.lookup_select@@', 'summary'); |
| 86 | + |
| 87 | + //build form |
| 88 | + $fields = array(); |
| 89 | + |
| 90 | + $lookup_field = plugin_load('helper', 'struct_field'); |
| 91 | + $lookup_field->opt['label'] = 'bureaucracy.lookup_select'; |
| 92 | + $lookup_field->opt['value'] = $lookup_pid; |
| 93 | + //left pagename undefined |
| 94 | + //$lookup_field->opt['pagename']; |
| 95 | + |
| 96 | + //$args are ommited in struct_field |
| 97 | + $lookup_field->initialize(array()); |
| 98 | + $fields[] = $lookup_field; |
| 99 | + |
| 100 | + //helper_plugin_bureaucracy_actiontemplate |
| 101 | + |
| 102 | + $actiontemplate = plugin_load('helper', 'bureaucracy_actiontemplate'); |
| 103 | + $actiontemplate->run($fields, '', array($template_id, $id, '_')); |
| 104 | + |
| 105 | + $page_content = io_readWikiPage(wikiFN($id), $id); |
| 106 | + |
| 107 | + $this->assertEquals('Value:' . $lookup_value, $page_content); |
| 108 | + } |
| 109 | +} |
0 commit comments