working on selenium tests

This commit is contained in:
John Bintz 2009-08-19 21:40:28 -04:00
parent e1a010d536
commit 7037dd6ac8
3 changed files with 264 additions and 77 deletions

View File

@ -12,8 +12,6 @@ class WhatDidTheySayAdmin {
'it', 'it',
'de' 'de'
), ),
'only_allowed_users' => false,
'users' => array(),
'capabilities' => array( 'capabilities' => array(
'submit_transcriptions' => 'administrator', 'submit_transcriptions' => 'administrator',
'approve_transcriptions' => 'administrator', 'approve_transcriptions' => 'administrator',
@ -124,19 +122,20 @@ class WhatDidTheySayAdmin {
*/ */
function user_has_cap($capabilities, $requested_capabilities, $capability_name) { function user_has_cap($capabilities, $requested_capabilities, $capability_name) {
$options = get_option('what-did-they-say-options'); $options = get_option('what-did-they-say-options');
if (is_array($options)) {
$role_cascade = array('administrator', 'editor', 'author', 'contributor', 'subscriber');
$allowed_roles = array();
$capture_roles = false;
$role_cascade = array('administrator', 'editor', 'author', 'contributor', 'subscriber'); for ($i = 0; $i < count($role_cascade); ++$i) {
$allowed_roles = array(); if (in_array($role_cascade, $capabilities)) { $capture_roles = true; }
$capture_roles = false; if ($capture_roles) { $allowed_roles[] = $role_cascade[$i]; }
}
for ($i = 0; $i < count($role_cascade); ++$i) { foreach ($requested_capabilities as $requested_capability) {
if (in_array($role_cascade, $capabilities)) { $capture_roles = true; } if (in_array($options['capabilities'][$requested_capability], $allowed_roles)) {
if ($capture_roles) { $allowed_roles[] = $role_cascade[$i]; } $capabilities[$requested_capability] = true;
} }
foreach ($requested_capabilities as $requested_capability) {
if (in_array($options['capabilities'][$requested_capability], $allowed_roles)) {
$capabilities[$requested_capability] = true;
} }
} }
@ -227,7 +226,7 @@ class WhatDidTheySayAdmin {
} }
} }
$updated = __('Transcripts updated', 'what-did-they-say'); $updated = __('Transcripts updated.', 'what-did-they-say');
break; break;
} }
} }
@ -301,7 +300,7 @@ class WhatDidTheySayAdmin {
$options['capabilities'][$capability] = $info['capabilities'][$capability]; $options['capabilities'][$capability] = $info['capabilities'][$capability];
} }
} }
$updated = __('User capabilities updated', 'what-did-they-say'); $updated = __('User capabilities updated.', 'what-did-they-say');
} }
break; break;
} }
@ -312,6 +311,25 @@ class WhatDidTheySayAdmin {
return $updated; return $updated;
} }
/**
* Handle resettings what-did-they-say-options.
* @param array $info The part of the $_POST array for What Did They Say?!?
* @return string|false A string if a message is to be displayed, or false if no message.
*/
function handle_update_reset_options($info) {
$updated = false;
if (current_user_can('manage_options')) {
switch ($info['action']) {
case "reset_options":
delete_option('what-did-they-say-options');
$this->install();
$updated = __('<strong>What Did They Say?!?</strong> options reset.', 'what-did-they-say');
break;
}
}
return $updated;
}
/** /**
* Read a data file containing all the known languages on Earth. * Read a data file containing all the known languages on Earth.
* The data originally came from http://www.langtag.net/, specifically http://www.langtag.net/registries/lsr-language.txt. * The data originally came from http://www.langtag.net/, specifically http://www.langtag.net/registries/lsr-language.txt.
@ -337,8 +355,9 @@ class WhatDidTheySayAdmin {
$options = get_option('what-did-they-say-options'); $options = get_option('what-did-they-say-options');
if (empty($options)) { if (empty($options)) {
$this->default_options['languages'] = $this->build_default_languages(); $this->default_options['languages'] = $this->build_default_languages();
ksort($this->default_options['languages']);
update_option('what-did-they-say-options', $this->default_options); update_option('what-did-they-say-options', $this->default_options);
} }
} }
/** /**
@ -397,6 +416,7 @@ class WhatDidTheySayAdmin {
*/ */
function manage_admin() { function manage_admin() {
$options = get_option('what-did-they-say-options'); $options = get_option('what-did-they-say-options');
$nonce = wp_create_nonce('what-did-they-say'); $nonce = wp_create_nonce('what-did-they-say');
include(dirname(__FILE__) . '/admin.inc'); include(dirname(__FILE__) . '/admin.inc');
} }
@ -408,6 +428,7 @@ class WhatDidTheySayAdmin {
global $post; global $post;
$options = get_option('what-did-they-say-options'); $options = get_option('what-did-they-say-options');
$transcripts = $this->what_did_they_say->get_transcripts($post->ID); $transcripts = $this->what_did_they_say->get_transcripts($post->ID);
$queued_transcriptions = $this->what_did_they_say->get_queued_transcriptions_for_post($post->ID); $queued_transcriptions = $this->what_did_they_say->get_queued_transcriptions_for_post($post->ID);

View File

@ -1,7 +1,7 @@
<div class="wrap"> <div class="wrap">
<h2><?php _e('What Did They Say?!? Settings', 'what-did-they-sahy') ?></h2> <h2><?php _e('What Did They Say?!? Settings', 'what-did-they-sahy') ?></h2>
<?php if (current_user_can('edit_users')) { ?> <?php if (current_user_can('edit_users') && is_array($options)) { ?>
<form method="post"> <form method="post">
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" /> <input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[action]" value="capabilities" /> <input type="hidden" name="wdts[action]" value="capabilities" />
@ -31,74 +31,86 @@
</table> </table>
</form> </form>
<?php } ?> <?php } ?>
<h3><?php _e('Languages', 'what-did-they-say') ?></h3>
<table class="widefat fixed"> <?php if (is_array($options)) { ?>
<tr class="thead"> <h3><?php _e('Languages', 'what-did-they-say') ?></h3>
<th scope="col" class="manage-col"><?php _e('Language', 'what-did-they-say') ?></th>
<th scope="col" class="manage-col"><?php _e('Default?', 'what-did-they-say') ?></th> <table class="widefat fixed">
<th scope="col" class="manage-col"><?php _e('Rename?', 'what-did-they-say') ?></th> <tr class="thead">
<th scope="col" class="manage-col"><?php _e('Make default?', 'what-did-they-say') ?></th> <th scope="col" class="manage-col"><?php _e('Language', 'what-did-they-say') ?></th>
<th scope="col" class="manage-col"><?php _e('Delete?', 'what-did-they-say') ?></th> <th scope="col" class="manage-col"><?php _e('Default?', 'what-did-they-say') ?></th>
</tr> <th scope="col" class="manage-col"><?php _e('Rename?', 'what-did-they-say') ?></th>
<?php foreach ($options['languages'] as $code => $info) { <th scope="col" class="manage-col"><?php _e('Make default?', 'what-did-they-say') ?></th>
$default = isset($info['default']); <th scope="col" class="manage-col"><?php _e('Delete?', 'what-did-they-say') ?></th>
$name = $info['name']; </tr>
?> <?php foreach ($options['languages'] as $code => $info) {
$default = isset($info['default']);
$name = $info['name'];
?>
<tr>
<th scope="row">
<span><?php echo $name ?></span>
<form method="post" style="display: none">
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[code]" value="<?php echo $code ?>" />
<input type="hidden" name="wdts[action]" value="rename" />
<input type="text" name="wdts[name]" value="<?php echo $name ?>" style="width: 50%" />
<input type="submit" class="button" value="Rename" />
</form>
</th>
<td>
<?php if ($default) { _e('(yes)', 'what-did-they-say'); } ?>
</td>
<td style="vertical-align: inherit">
<a class="rename button" href="#"><?php _e('Rename', 'what-did-they-say') ?></a>
</td>
<td>
<form method="post">
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[code]" value="<?php echo $code ?>" />
<input type="hidden" name="wdts[action]" value="default" />
<input type="submit" class="button" value="<?php _e('Default', 'what-did-they-say') ?>" />
</form>
</td>
<td>
<form method="post" class="verify">
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[code]" value="<?php echo $code ?>" />
<input type="hidden" name="wdts[action]" value="delete" />
<input type="submit" class="button" value="<?php _e('Delete', 'what-did-they-say') ?>" />
</form>
</td>
</tr>
<?php } ?>
<tr> <tr>
<th scope="row"> <th scope="row"><?php _e('Add new:', 'what-did-they-say') ?></th>
<span><?php echo $name ?></span> <td colspan="4">
<form method="post" style="display: none">
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[code]" value="<?php echo $code ?>" />
<input type="hidden" name="wdts[action]" value="rename" />
<input type="text" name="wdts[name]" value="<?php echo $name ?>" style="width: 50%" />
<input type="submit" class="button" value="Rename" />
</form>
</th>
<td>
<?php if ($default) { _e('(yes)', 'what-did-they-say'); } ?>
</td>
<td style="vertical-align: inherit">
<a class="rename button" href="#"><?php _e('Rename', 'what-did-they-say') ?></a>
</td>
<td>
<form method="post"> <form method="post">
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" /> <input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[code]" value="<?php echo $code ?>" /> <input type="hidden" name="wdts[action]" value="add" />
<input type="hidden" name="wdts[action]" value="default" /> <select name="wdts[code]">
<input type="submit" class="button" value="<?php _e('Default', 'what-did-they-say') ?>" /> <option value="">-- select --</option>
</form> <?php foreach ($this->all_languages as $code => $language) { ?>
</td> <option value="<?php echo $code ?>"><?php echo $language ?></option>
<td> <?php } ?>
<form method="post" class="verify"> </select>
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" /> <input type="submit" value="<?php _e('Add New Language', 'what-did-they-say') ?>" class="button" />
<input type="hidden" name="wdts[code]" value="<?php echo $code ?>" />
<input type="hidden" name="wdts[action]" value="delete" />
<input type="submit" class="button" value="<?php _e('Delete', 'what-did-they-say') ?>" />
</form> </form>
</td> </td>
</tr> </tr>
<?php } ?> </table>
<tr> <?php } ?>
<th scope="row"><?php _e('Add new:', 'what-did-they-say') ?></th> <?php if (current_user_can('manage_options')) { ?>
<td colspan="4"> <h3><?php _e('Reset Settings to Default', 'what-did-they-say') ?></h3>
<form method="post"> <p><?php _e('Click the button below to reset capabilities and languages to their defaults. This will not affect any transcriptions you have already created, but some transcriptions may become inaccessible if you don\'t redefine the original language.', 'what-did-they-say') ?></p>
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" /> <form method="post" id="reset-wdts">
<input type="hidden" name="wdts[action]" value="add" /> <input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<select name="wdts[code]"> <input type="hidden" name="wdts[action]" value="reset_options" />
<option value="">-- select --</option> <input type="submit" class="button" value="<?php _e('Reset What Did They Say?!?', 'what-did-they-say') ?>" />
<?php foreach ($this->all_languages as $code => $language) { ?> </form>
<option value="<?php echo $code ?>"><?php echo $language ?></option> <?php } ?>
<?php } ?>
</select>
<input type="submit" value="<?php _e('Add New Language', 'what-did-they-say') ?>" class="button" />
</form>
</td>
</tr>
</table>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
$$('form.verify').each(function(f) { $$('form.verify').each(function(f) {
Event.observe(f, 'submit', function(e) { Event.observe(f, 'submit', function(e) {
@ -118,5 +130,13 @@
} }
}); });
}); });
if ($('reset-wdts')) {
Event.observe($('reset-wdts'), 'submit', function(e) {
if (!confirm('<?php _e('Are you sure? You could leave transcriptions inaccessible.', 'what-did-they-say') ?>')) {
Event.stop(e);
}
});
}
</script> </script>

View File

@ -0,0 +1,146 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="" />
<title>TestWhatDidTheySay</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">TestWhatDidTheySay</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/wp-admin/</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Installed</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>What Did They Say?!?</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//table[@id='all-plugins-table']/tbody/tr[15]/td[2]/div/span[1]/a</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>//a[contains(@href,'what-did-they-say') and contains(@href,'activate')]</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Plugin activated.</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//a[contains(text(), &quot;What Did They Say?!?&quot;)]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>link=exact:What Did They Say?!?</td>
<td></td>
</tr>
<!--Reset-->
<tr>
<td>assertTextPresent</td>
<td>Reset Settings to Default</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//input[@value='Reset What Did They Say?!?']</td>
<td></td>
</tr>
<tr>
<td>assertConfirmation</td>
<td>Are you sure? You could leave transcriptions inaccessible.</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>What Did They Say?!? options reset</td>
<td></td>
</tr>
<!--Capabilities-->
<tr>
<td>select</td>
<td>wdts[capabilities][submit_transcriptions]</td>
<td>label=Editor</td>
</tr>
<tr>
<td>select</td>
<td>wdts[capabilities][approve_transcriptions]</td>
<td>label=Editor</td>
</tr>
<tr>
<td>select</td>
<td>wdts[capabilities][change_languages]</td>
<td>label=Editor</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>//input[@value='Change capabilities']</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>User capabilities updated.</td>
<td></td>
</tr>
<tr>
<td>assertSelectedLabel</td>
<td>wdts[capabilities][submit_transcriptions]</td>
<td>Editor</td>
</tr>
<tr>
<td>assertSelectedLabel</td>
<td>wdts[capabilities][approve_transcriptions]</td>
<td>Editor</td>
</tr>
<tr>
<td>assertSelectedLabel</td>
<td>wdts[capabilities][change_languages]</td>
<td>Editor</td>
</tr>
<!--Make new language default-->
<tr>
<td>assertText</td>
<td>//th/span[contains(text(), &quot;English&quot;)]/../../td[1]</td>
<td>(yes)</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>//th/span[contains(text(), &quot;German&quot;)]/../..//input[@value=&quot;Default&quot;]</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>German set as default.</td>
<td></td>
</tr>
<tr>
<td>assertNotText</td>
<td>//th/span[contains(text(), &quot;English&quot;)]/../../td[1]</td>
<td>(yes)</td>
</tr>
<tr>
<td>assertText</td>
<td>//th/span[contains(text(), &quot;German&quot;)]/../../td[1]</td>
<td>(yes)</td>
</tr>
<!--Add a new language-->
</tbody></table>
</body>
</html>