function testShowData() { $handler = new Doku_Handler(); $xhtml = new Doku_Renderer_xhtml(); $plugin = new syntax_plugin_data_entry(); $result = $plugin->handle($this->exampleEntry, 0, 10, $handler); $plugin->_showData($result, $xhtml); $doc = phpQuery::newDocument($xhtml->doc); $this->assertEquals(1, pq('div.inline.dataplugin_entry.projects', $doc)->length); $this->assertEquals(1, pq('dl dt.type')->length); $this->assertEquals(1, pq('dl dd.type')->length); $this->assertEquals(1, pq('dl dt.volume')->length); $this->assertEquals(1, pq('dl dd.volume')->length); $this->assertEquals(1, pq('dl dt.employee')->length); $this->assertEquals(1, pq('dl dd.employee')->length); $this->assertEquals(1, pq('dl dt.customer')->length); $this->assertEquals(1, pq('dl dd.customer')->length); $this->assertEquals(1, pq('dl dt.deadline')->length); $this->assertEquals(1, pq('dl dd.deadline')->length); $this->assertEquals(1, pq('dl dt.server')->length); $this->assertEquals(1, pq('dl dd.server')->length); $this->assertEquals(1, pq('dl dt.website')->length); $this->assertEquals(1, pq('dl dd.website')->length); $this->assertEquals(1, pq('dl dt.task')->length); $this->assertEquals(1, pq('dl dd.task')->length); $this->assertEquals(1, pq('dl dt.tests')->length); $this->assertEquals(1, pq('dl dd.tests')->length); }
public static function editToWiki($data) { $nudata = array(); $len = 0; foreach ($data['data'] as $field) { if ($field['title'] === '') { continue; } $s = syntax_plugin_data_entry::_normalize($field['title']); if (trim($field['type']) !== '' || substr($s, -1, 1) === 's' && $field['multi'] === '') { $s .= '_' . syntax_plugin_data_entry::_normalize($field['type']); } if ($field['multi'] === '1') { $s .= 's'; } if (is_array($field['value'])) { $field['value'] = join(', ', $field['value']); } $nudata[] = array($s, syntax_plugin_data_entry::_normalize($field['value']), isset($field['comment']) ? trim($field['comment']) : ''); $len = max($len, utf8_strlen($nudata[count($nudata) - 1][0])); } $ret = '---- dataentry ' . trim($data['classes']) . ' ----' . DOKU_LF; foreach ($nudata as $field) { $ret .= $field[0] . str_repeat(' ', $len + 1 - utf8_strlen($field[0])) . ': ' . $field[1]; if ($field[2] !== '') { $ret .= ' #' . $field[2]; } $ret .= DOKU_LF; } $ret .= '----'; return $ret; }
function _handle_edit_post($event) { if (!isset($_POST['data_edit'])) { return; } global $TEXT; require_once 'syntax/entry.php'; $TEXT = syntax_plugin_data_entry::editToWiki($_POST['data_edit']); }
function testComments() { $entry = "---- dataentry projects ----\n" . "volume : 1 Mrd # how much do they pay?\n" . "server : http://www.microsoft.com # Comment\n" . "Website_url : http://www.microsoft.com\\#test # Comment\n" . "Site_url : https://www.microsoft.com/page\\#test\n" . "tests_ : \\#5 done\n" . "----\n"; $plugin = new syntax_plugin_data_entry(); $handler = new Doku_Handler(); $result = $plugin->handle($entry, 0, 10, $handler); $this->assertEquals(10, $result['pos'], 'Position has changed'); $this->assertEquals('projects', $result['classes'], 'wrong class name detected'); $data = array('volume' => '1 Mrd', 'server' => 'http://www.microsoft.com', 'website' => 'http://www.microsoft.com#test', 'site' => 'https://www.microsoft.com/page#test', 'tests' => '#5 done', '----' => ''); $this->assertEquals($data, $result['data'], 'Data array corrupted'); }
/** * Handles the data posted from the editor to recreate the entry syntax * * @param array $data data given via POST * @return string */ public static function editToWiki($data) { $nudata = array(); $len = 0; // we check the maximum lenght for nice alignment later foreach ($data['data'] as $field) { if (is_array($field['value'])) { $field['value'] = join(', ', $field['value']); } $field = array_map('trim', $field); if ($field['title'] === '') { continue; } $name = syntax_plugin_data_entry::_normalize($field['title']); if ($field['type'] !== '') { $name .= '_' . syntax_plugin_data_entry::_normalize($field['type']); } elseif (substr($name, -1, 1) === 's') { $name .= '_'; // when the field name ends in 's' we need to secure it against being assumed as multi } if ($field['multi'] === '1') { $name .= 's'; } // 's' is added to either type or name for multi $nudata[] = array($name, syntax_plugin_data_entry::_normalize($field['value']), $field['comment']); $len = max($len, utf8_strlen($nudata[count($nudata) - 1][0])); } $ret = '---- dataentry ' . trim($data['classes']) . ' ----' . DOKU_LF; foreach ($nudata as $field) { $ret .= $field[0] . str_repeat(' ', $len + 1 - utf8_strlen($field[0])) . ': ' . $field[1]; if ($field[2] !== '') { $ret .= ' # ' . $field[2]; } $ret .= DOKU_LF; } $ret .= "----\n"; return $ret; }