Permalink
Browse files

Fix transient TestOfPluginController::testUpdateDeletePluginOption fa…

…ilure
  • Loading branch information...
1 parent 5dae34c commit 1b46f86100021f90152f3404a0fc7152d0c1eb49 @ginatrapani ginatrapani committed with Sep 12, 2012
Showing with 10 additions and 7 deletions.
  1. +5 −2 tests/TestOfPluginOptionController.php
  2. +5 −5 webapp/_lib/controller/class.PluginOptionController.php
@@ -329,9 +329,11 @@ public function testUpdateDeletePluginOptionNoCSRFToken() {
* test update/delete plugin options
*/
public function testUpdateDeletePluginOption() {
- // update two options out of three, third has same data
+ // update one option, delete another, leave third alone because it has same data
$controller = $this->getController();
+ // create a plugin
$builder = $this->buildPlugin();
+ // add three options for newly-made plugin
$builder_pos = $this->buildPluginOptions($builder->columns[ 'last_insert_id' ]);
$_GET['plugin_id'] = $builder->columns[ 'last_insert_id' ];
$_GET['csrf_token'] = parent::CSRF_TOKEN;
@@ -348,7 +350,8 @@ public function testUpdateDeletePluginOption() {
$this->assertIsA($json_response, 'stdClass');
// // {"status":"success","results":{"updated":1}}
$this->assertEqual($json_response->status, 'success');
- $this->assertEqual($json_response->results->updated, 2);
+ $this->assertEqual($json_response->results->updated, 1);
+ $this->assertEqual($json_response->results->deleted, 1);
$sql = "select * from " . $this->table_prefix . "options where namespace = 'plugin_options-5'";
$stmt = $this->pdo->query($sql);
@@ -70,7 +70,7 @@ public function setPluginOptions($plugin_id) {
$plugin_folder_name = $plugin_dao->getPluginFolder($plugin_id);
$plugin_option_dao = DAOFactory::getDAO('PluginOptionDAO');
$options = $plugin_option_dao->getOptions($plugin_folder_name);
- $cnt = 0;
+ $updated_total = 0;
$inserted = array();
$deleted = 0;
foreach ($_GET as $key => $value ) {
@@ -80,7 +80,7 @@ public function setPluginOptions($plugin_id) {
$name = preg_replace('/^option_/', '', $key);
$id_name = "id_option_" . $name;
if (isset($_GET[$id_name])) {
- foreach($options as $option) {
+ foreach ($options as $option) {
//error_log($option->option_name . ' ' . $name);
if ($option->option_name == $name) {
if ( $option->option_value != $value ) {
@@ -90,8 +90,8 @@ public function setPluginOptions($plugin_id) {
$deleted++;
} else {
$plugin_option_dao->updateOption($id, $name, $value);
+ $updated_total++;
}
- $cnt++;
}
}
}
@@ -102,12 +102,12 @@ public function setPluginOptions($plugin_id) {
return;
} else {
$inserted[$name] = $insert_id;
- $cnt++;
+ $updated_total++;
}
}
}
}
- $this->json['results'] = array('updated' => $cnt, 'inserted' => $inserted, 'deleted' => $deleted);
+ $this->json['results'] = array('updated' => $updated_total, 'inserted' => $inserted, 'deleted' => $deleted);
$this->json['status'] = 'success';
}

0 comments on commit 1b46f86

Please sign in to comment.