public function test_build_update() { // arrange $initialdata = array(); $initialdata['new']['new1']['sort'] = 70; $initialdata['new']['new1']['label'] = 'testcolumn'; $initialdata['new']['new1']['ismulti'] = 0; $initialdata['new']['new1']['config'] = '{"prefix": "", "postfix": ""}'; $initialdata['new']['new1']['class'] = 'Text'; $initialdata['new']['new1']['isenabled'] = '1'; $testname = 'testTable'; $testname = Schema::cleanTableName($testname); $builder = new SchemaBuilder($testname, $initialdata); $result = $builder->build(); $this->assertSame($result, '1', 'Prerequiste setup in order to have basis which to change during act'); $updatedata = array(); $updatedata['id'] = "1"; $updatedata['cols']['1']['sort'] = 65; $updatedata['cols']['1']['label'] = 'testColumn'; $updatedata['cols']['1']['ismulti'] = 1; $updatedata['cols']['1']['config'] = '{"prefix": "pre", "postfix": "fix"}'; $updatedata['cols']['1']['class'] = 'Text'; $updatedata['cols']['1']['isenabled'] = '1'; // act $builder = new SchemaBuilder($testname, $updatedata); $result = $builder->build(); $res = $this->sqlite->query("SELECT * FROM types"); $actual_types = $this->sqlite->res2arr($res); $this->sqlite->res_close($res); $expected_types = array(array('id' => "1", 'class' => 'Text', 'ismulti' => "0", 'label' => "testcolumn", 'config' => '{"prefix": "", "postfix": ""}'), array('id' => "2", 'class' => 'Text', 'ismulti' => "1", 'label' => "testColumn", 'config' => '{"prefix": "pre", "postfix": "fix"}')); // assert $this->assertSame($result, '2'); $this->assertEquals($actual_types, $expected_types); }
/** * Dropdown constructor. * * @param array|null $config * @param string $label * @param bool $ismulti * @param int $tid */ public function __construct($config = null, $label = '', $ismulti = false, $tid = 0) { global $conf; parent::__construct($config, $label, $ismulti, $tid); $this->config['schema'] = Schema::cleanTableName($this->config['schema']); if ($this->usesLookup()) { $this->schema = new Schema($this->config['schema']); if (!$this->schema->getId()) { // schema does not exist msg(sprintf('Schema %s does not exist', $this->config['schema']), -1); $this->schema = null; $this->config['schema'] = ''; return; } // apply language replacement $field = str_replace('$LANG', $conf['lang'], $this->config['field']); $this->column = $this->schema->findColumn($field); if (!$this->column) { $field = str_replace('$LANG', 'en', $this->config['field']); // fallback to en $this->column = $this->schema->findColumn($field); } if (!$this->column) { // field does not exist msg(sprintf('Field %s.%s does not exist', $this->config['schema'], $this->config['field']), -1); $this->column = null; $this->config['field'] = ''; return; } if ($this->column->isMulti()) { // field is multi msg(sprintf('Field %s.%s is a multi field - not allowed for lookup', $this->config['schema'], $this->config['field']), -1); $this->column = null; $this->config['field'] = ''; return; } } }
/** * Render HTML output, e.g. helpful text and a form */ public function html() { global $INPUT; $table = Schema::cleanTableName($INPUT->str('table')); if ($table) { $schema = new Schema($table, 0, $INPUT->bool('lookup')); if ($schema->isLookup()) { $hl = 'edithl lookup'; } else { $hl = 'edithl page'; } echo $this->locale_xhtml('editor_edit'); echo '<h2>' . sprintf($this->getLang($hl), hsc($table)) . '</h2>'; echo '<ul class="tabs" id="plugin__struct_tabs">'; /** @noinspection HtmlUnknownAnchorTarget */ echo '<li class="active"><a href="#plugin__struct_editor">' . $this->getLang('tab_edit') . '</a></li>'; /** @noinspection HtmlUnknownAnchorTarget */ echo '<li><a href="#plugin__struct_json">' . $this->getLang('tab_export') . '</a></li>'; /** @noinspection HtmlUnknownAnchorTarget */ echo '<li><a href="#plugin__struct_delete">' . $this->getLang('tab_delete') . '</a></li>'; echo '</ul>'; echo '<div class="panelHeader"></div>'; $editor = new SchemaEditor($schema); echo $editor->getEditor(); echo $this->html_json($schema); echo $this->html_delete($schema); } else { echo $this->locale_xhtml('editor_intro'); echo $this->html_newschema(); } }
/** * @dataProvider cleanTableName_testdata * * @covers \dokuwiki\plugin\struct\meta\Schema::cleanTableName * * @param string $input_name * @param string $expected_cleaned_name */ public function test_cleanTableName($input_name, $expected_cleaned_name) { $actual_cleaned_name = Schema::cleanTableName($input_name); $this->assertSame($expected_cleaned_name, $actual_cleaned_name, $input_name); }