Skip to content

Commit

Permalink
Fix transient TestOfPluginController::testUpdateDeletePluginOption fa…
Browse files Browse the repository at this point in the history
…ilure
  • Loading branch information
ginatrapani committed Sep 12, 2012
1 parent 37a061b commit e9026cf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions tests/TestOfPluginOptionController.php
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions webapp/_lib/controller/class.PluginOptionController.php
Expand Up @@ -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 ) {
Expand All @@ -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 ) {
Expand All @@ -90,8 +90,8 @@ public function setPluginOptions($plugin_id) {
$deleted++;
} else {
$plugin_option_dao->updateOption($id, $name, $value);
$updated_total++;
}
$cnt++;
}
}
}
Expand All @@ -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';
}

Expand Down

0 comments on commit e9026cf

Please sign in to comment.