diff --git a/test/ViewMainTest.php b/test/ViewMainTest.php new file mode 100644 index 0000000..d5cf620 --- /dev/null +++ b/test/ViewMainTest.php @@ -0,0 +1,64 @@ +m = new PluginWonderfulViewMain(); + } + + function testCreateNonce() { + $this->m->_create_nonce(); + $result = _get_nonce('plugin-wonderful'); + $this->assertTrue(!empty($result)); + $this->assertEquals($result, $this->m->_pw_nonce); + } + + function providerTestRenderMemberIDSettings() { + return array( + array( + array( + 'plugin-wonderful-memberid' => "123", + 'plugin-wonderful-use-standardcode' => 0, + 'plugin-wonderful-enable-body-copy-embedding' => 0 + ) + ), + array( + array( + 'plugin-wonderful-memberid' => "123", + 'plugin-wonderful-use-standardcode' => 1, + 'plugin-wonderful-enable-body-copy-embedding' => 1 + ) + ), + ); + } + + /** + * @dataProvider providerTestRenderMemberIDSettings + */ + function testRenderMemberIDSettings($options) { + foreach ($options as $key => $value) { + update_option($key, $value); + } + + ob_start(); + $this->m->_render_memberid_settings(); + $source = ob_get_clean(); + + $this->assertTrue(!empty($source)); + $this->assertTrue(($xml = _to_xml($source, true)) !== false); + + foreach (array( + '//input[@id="memberid" and @value="123"]' => true, + '//input[@name="use-standardcode" and ' . (($options['plugin-wonderful-use-standardcode'] == 1) ? '@checked' : 'not(@checked)') . ']' => true, + '//input[@name="enable-body-copy-embedding" and ' . (($options['plugin-wonderful-enable-body-copy-embedding'] == 1) ? '@checked' : 'not(@checked)') . ']' => true, + ) as $xpath => $value) { + $this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); + } + } +} + +?> \ No newline at end of file diff --git a/views/PluginWonderfulViewMain.php b/views/PluginWonderfulViewMain.php new file mode 100644 index 0000000..2dbbab2 --- /dev/null +++ b/views/PluginWonderfulViewMain.php @@ -0,0 +1,17 @@ +_pw_nonce = wp_create_nonce('plugin-wonderful'); + } + + function _partial_path($name) { + return dirname(__FILE__) . '/' . __CLASS__ . '/' . $name . '.php'; + } + + function _render_memberid_settings() { + include($this->_partial_path('memberid-settings')); + } +} + +?> \ No newline at end of file diff --git a/views/PluginWonderfulViewMain/memberid-settings.php b/views/PluginWonderfulViewMain/memberid-settings.php new file mode 100644 index 0000000..ce0a7fb --- /dev/null +++ b/views/PluginWonderfulViewMain/memberid-settings.php @@ -0,0 +1,42 @@ +
\ No newline at end of file