begin extracting parts of main.php out
This commit is contained in:
parent
cc35c3589e
commit
2e1df12bc1
64
test/ViewMainTest.php
Normal file
64
test/ViewMainTest.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
require_once('PHPUnit/Framework.php');
|
||||
require_once(dirname(__FILE__) . '/../views/PluginWonderfulViewMain.php');
|
||||
require_once(dirname(__FILE__) . '/../../mockpress/mockpress.php');
|
||||
|
||||
class ViewMainTest extends PHPUnit_Framework_TestCase {
|
||||
function setUp() {
|
||||
_reset_wp();
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
17
views/PluginWonderfulViewMain.php
Normal file
17
views/PluginWonderfulViewMain.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
class PluginWonderfulViewMain {
|
||||
function _create_nonce() {
|
||||
$this->_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'));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
42
views/PluginWonderfulViewMain/memberid-settings.php
Normal file
42
views/PluginWonderfulViewMain/memberid-settings.php
Normal file
@ -0,0 +1,42 @@
|
||||
<form id="pw-handler" action="" method="post">
|
||||
<input type="hidden" name="_pw_nonce" value="<?php echo $nonce ?>" />
|
||||
<input type="hidden" name="action" value="change-memberid" />
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row"><?php _e('Your member number', 'plugin-wonderful') ?></th>
|
||||
<td>
|
||||
<input id="memberid" name="memberid" value="<?php echo get_option("plugin-wonderful-memberid") ?>" />
|
||||
<em><?php _e('(you can find your member number by logging in to Project Wonderful and clicking on your profile image in the upper right of the page)', 'plugin-wonderful') ?></em>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e('Use Standard Adboxes?', 'plugin-wonderful') ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox"
|
||||
name="use-standardcode"
|
||||
value="yes"
|
||||
<?php echo (get_option("plugin-wonderful-use-standardcode") == 1) ? "checked='checked'" : "" ?> />
|
||||
<em><?php _e('(If you want to use standard code adboxes instead of advanced code, enable this option)', 'plugin-wonderful') ?></em>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e('Enable Body Copy Embedding?', 'plugin-wonderful') ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox"
|
||||
name="enable-body-copy-embedding"
|
||||
value="yes"
|
||||
<?php echo (get_option("plugin-wonderful-enable-body-copy-embedding") == 1) ? "checked='checked'" : "" ?> />
|
||||
<em><?php _e('(When enabled, you can embed ads directly in body copy using a PW() tag. Read below for more details.)', 'plugin-wonderful') ?></em>
|
||||
</label>
|
||||
</td>
|
||||
</tr> <tr>
|
||||
<td> </td>
|
||||
<td>
|
||||
<input type="submit" value="<?php _e('Change and Redownload Adbox Information', 'plugin-wonderful') ?>" class="button" /> <em>(<?php _e('if you\'ve modified adbox settings on Project Wonderful, just click this button to refresh your adbox code.', 'plugin-wonderful') ?>)</em>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
Loading…
Reference in New Issue
Block a user