/** * This tests updateFeatures. * * @return void * @author Eric Rochester <*****@*****.**> **/ public function testUpdateFeatures() { $utils = new NeatlineFeatures_Utils_View(); $utils->setCoverageElement(); $et_table = $this->db->getTable('ElementText'); $item = new Item(); $item->save(); $this->toDelete($item); // First test with no features. $features = $this->table->updateFeatures($item, array()); $this->assertEmpty($features); // Now test with two features. $this->setupCoverageData($item, "Just Text.", 0, 0); $this->setupCoverageData($item, "WKT: POINT\n\nAnd Text.", 0, 1, 1); $features = $this->table->updateFeatures($item, $utils->getPost()); $this->assertCount(2, $features); $this->assertFalse((bool) $features[0]->is_map); $this->assertEquals("Just Text.", $et_table->find($features[0]->element_text_id)->getText()); $this->assertTrue((bool) $features[1]->is_map); $this->assertEquals("WKT: POINT\n\nAnd Text.", $et_table->find($features[1]->element_text_id)->getText()); // Finally, wipe those out and test with just one feature. $etexts = $et_table->fetchObjects($this->db->select()->from($et_table->getTableName())->where('element_id=?', $this->_coverage->id)->where('record_id=?', $item->id)); foreach ($etexts as $et) { $et->delete(); } $this->setupCoverageData($item, "Other Text.", 0, 0); $this->table->updateFeatures($item, $utils->getPost()); $features = $this->table->getItemFeatures($item); $this->assertCount(1, $features); $this->assertFalse((bool) $features[0]->is_map); $this->assertEquals("Other Text.", $et_table->find($features[0]->element_text_id)->getText()); }
/** * This tests the POST data returned by the getPost function. * * @return void * @author Eric Rochester <*****@*****.**> **/ public function testGetPost() { $utils = new NeatlineFeatures_Utils_View(); $utils->setCoverageElement(); // No Elements in _POST. if (array_key_exists('Elements', $_POST)) { unset($_POST['Elements']); } $this->assertNull($utils->getPost()); // No element ID in Elements. $_POST['Elements'] = array(); $this->assertNull($utils->getPost()); // I CAN HAZ VALUE! $cid = (string) $this->_coverage->id; $_POST['Elements'][$cid] = 'hi'; $this->assertEquals('hi', $utils->getPost()); }
/** * This saves the is_map field, whenever the item is saved in a POST * request. * * @param $record Omeka_Record The record that was just saved. * * @return void * @author Eric Rochester <*****@*****.**> **/ public function hookAfterSaveItem($args) { // NeatlineFeatures_Functions::flog('/tmp/nlfeatures.log', "(hook) after_save_item"); $record = $args['record']; $utils = new NeatlineFeatures_Utils_View(); $utils->setCoverageElement(); $post = $utils->getPost(); if (!is_null($post)) { $this->_db->getTable('NeatlineFeature')->updateFeatures($record, $utils->getPost()); } }