$changed = true; $ap->flag_active = $active_check_state; } if ($changed) { $ap->matchesDb = false; $ap->updateDb(); } if ($_REQUEST['authoritative_plant_id'] != 'NEW') { ///////////////////// // second, any auth plant extras // deleted ones - in comma-sep deletion list $deleted_authoritative_plant_extra_ids = explode(',', $_REQUEST['deleted_authoritative_plant_extra_ids']); if ($deleted_authoritative_plant_extra_ids) { foreach ($deleted_authoritative_plant_extra_ids as $deleted_authoritative_plant_extra_id) { if ($deleted_authoritative_plant_extra_id) { $del_ape = Authoritative_Plant_Extra::getOneFromDb(['authoritative_plant_extra_id' => $deleted_authoritative_plant_extra_id], $DB); if ($del_ape->matchesDb) { $del_ape->doDelete(); } } } } // edited ones - foreach ap->extras update it from $_REQUEST data $ap->cacheExtras(); foreach ($ap->extras as $db_ape) { if ($db_ape->type != 'image') { // images can only be added and removed - not edited/modified $req_ape_value = trim($_REQUEST['authoritative_plant_extra_' . $db_ape->authoritative_plant_extra_id . '-value']); if ($db_ape->value != $req_ape_value) { $db_ape->value = $req_ape_value; $db_ape->updateDb();
function testRenderAsListItemEdit_DESCRIPTION() { $pe = Authoritative_Plant_Extra::getOneFromDb(['authoritative_plant_extra_id' => 5104], $this->DB); $canonical = ''; $canonical .= '<li id="authoritative_plant_extra_5104" class="authoritative-plant-extra-edit authoritative-plant-extra" data-authoritative_plant_extra_id="5104" data-created_at="' . $pe->created_at . '" data-updated_at="' . $pe->updated_at . '" data-authoritative_plant_id="5001" data-type="description" data-value="description of american chestnut" data-ordering="1.00000" data-flag_active="1" data-flag_delete="0">' . "\n"; $canonical .= ' ' . util_orderingUpDownControls('authoritative_plant_extra_5104') . "\n"; $canonical .= ' <div class="authoritative-plant-extra embedded">' . "\n"; $canonical .= ' <div id="form-edit-authoritative-plant-extra-5104" class="form-edit-authoritative-plant-extra" data-authoritative_plant_extra_id="5104">' . "\n"; $canonical .= ' <div class="field-label">description : </div><div class="field-value"><input type="text" name="authoritative_plant_extra-description_5104" id="authoritative_plant_extra-description_5104" value="description of american chestnut"/></div>' . "\n"; $canonical .= ' </div>' . "\n"; $canonical .= ' <button class="btn btn-danger button-mark-authoritative-plant-extra-for-delete" title="Mark this for removal - the actual removal occurs on update" data-do-mark-title="Mark this for removal - the actual removal occurs on update" data-remove-mark-title="Undo the mark for removal" data-for_dom_id="authoritative_plant_extra_5104" data-authoritative_plant_extra_id="5104"><i class="icon-remove-sign icon-white"></i></button>' . "\n"; $canonical .= ' </div>' . "\n"; $canonical .= '</li>'; $rendered = $pe->renderAsListItemEdit(); // echo "<pre>\n".htmlentities($canonical)."\n------------------\n".htmlentities($rendered)."\n</pre>"; $this->assertEqual($canonical, $rendered); }
function testBaseDataUpdate() { $this->doLoginAdmin(); $this->get('http://localhost/digitalfieldnotebooks/app_code/authoritative_plant.php?action=edit&authoritative_plant_id=5001'); $this->checkBasicAsserts(); /////////////////////////////// //// set form fields ////// NOTE: the identifier to use for setField is the value of the name attribute of the field $this->assertTrue($this->setField('authoritative_plant-class_5001', '')); $this->assertTrue($this->setField('authoritative_plant-order_5001', 'neworder')); $this->assertTrue($this->setField('authoritative_plant-species_5001', 'newspecies')); // // alter common name $this->assertTrue($this->setField('authoritative_plant_extra_5103-value', 'altered common name')); // // alter description $this->assertTrue($this->setField('authoritative_plant_extra_5104-value', 'altered description')); // // alter specimen $this->assertTrue($this->setField('specimen-name_8001', 'altered specimen name')); // JS-driven - can't test here // $this->todo('add new APE'); // $this->todo('delete existing APE'); // // $this->todo('add new specimen'); // $this->todo('delete specimen'); // $this->showContent(); // exit; //// NOTE: the identifier to use for buttons is the value of the value attribute of the button /////////////////////////////// //// submit the form $this->click('<i class="icon-ok-sign icon-white"></i> ' . util_lang('update', 'properize')); // $this->showContent(); // exit; //// /////////////////////////////// //// check the resulting page $this->checkBasicAsserts(); $this->assertNoText('class :'); $this->assertText('neworder'); $this->assertText('newspecies'); $this->assertText('altered common name'); $this->assertText('altered description'); $this->assertText('altered specimen name'); // JS-driven - can't test here // $this->todo('web - check add new APE'); // $this->todo('web - check delete existing APE'); // $this->todo('web - add new specimen'); // $this->todo('web - delete specimen'); /////////////////////////////// //// check the db records $ap = Authoritative_Plant::getOneFromDb(['authoritative_plant_id' => 5001], $this->DB); $this->assertEqual($ap->class, ''); $this->assertEqual($ap->order, 'neworder'); $this->assertEqual($ap->genus, 'AP_A_genus'); $this->assertEqual($ap->species, 'newspecies'); $apeCN = Authoritative_Plant_Extra::getOneFromDb(['authoritative_plant_extra_id' => 5103], $this->DB); $apeDe = Authoritative_Plant_Extra::getOneFromDb(['authoritative_plant_extra_id' => 5104], $this->DB); $spec = Specimen::getOneFromDb(['specimen_id' => 8001], $this->DB); $this->assertEqual('altered common name', $apeCN->value); $this->assertEqual('altered description', $apeDe->value); $this->assertEqual('altered specimen name', $spec->name); // JS-driven - can't test here // $this->todo('db - check add new APE'); // $this->todo('db - check delete existing APE'); // $this->todo('db - add new specimen'); // $this->todo('db - delete specimen'); }