/** * This tests that we can iterate over mixed coverages. * * This is a work-around for this spec no longer working, due to O2's * popping up a new window when you click "View Public Page." Technically, * this test should have been a unittest all along, but having it as a * feature keep the planning cleaner. * * @kml * @file_fixture @javascript * Scenario: Mixed Feature Coverages * Given I am logged into the admin console * And I replace "themes/default/items/show.php" with "plugins/NeatlineFeatures/features/data/show-display-coverage-test.php" * And I click "Add a new item" * And I enter "Cucumber: Test Iterate Mixed Feature Coverages" for the "Elements-50-0-text" # Title * And I enter "Iterate Mixed Feature Coverages" for the "Elements-49-0-text" # Subject * And I click "Use Map" checkbox in "#Elements-38-0-widget" * And I draw a line on "div#Elements-38-0-map.olMap" * And I click "add_element_38" * And I wait 15 seconds * And I enter "UVa" into "Elements-38-1-free" * And I click on "Add Item" * And I click "Test Iterate Mixed Feature Coverages" * When I click "View Public Page" * Then I should see the following output in unordered list "#item-coverage": * | true | * | false | * * @return void * @author Eric Rochester **/ public function testTestMixedFeatureCoverage() { $table = $this->db->getTable('NeatlineFeature'); $utils = new NeatlineFeatures_Utils_View(); $utils->setCoverageElement(); $item = new Item(); $item->save(); $this->toDelete($item); $this->_addElementTextDelete($item, $this->_title, "Unittest: Display All Feature Coverages", 1); $this->_addFeature($utils, $table, $item, "<kml xmlns=\"http://earth.google.com/kml/2.0\"><Folder><name>OpenLayers export</name><description>Exported on Thu Mar 07 2013 11:18:43 GMT-0500 (EST)</description><Placemark><name>OpenLayers.Feature.Vector_158</name><description>No description available</description><Polygon><outerBoundaryIs><LinearRing><coordinates>-10194865.083145,4313188.6314755 -9803507.4983789,3295658.9110849 -9744803.8606641,5017632.2840536 -10194865.083145,4313188.6314755</coordinates></LinearRing></outerBoundaryIs></Polygon></Placemark><Placemark><name>OpenLayers.Feature.Vector_182</name><description>No description available</description><LineString><coordinates>-8003262.6084573,5487261.3857724 -10097025.686953,6269976.5553037 -10958012.373438,4724114.0954794</coordinates></LineString></Placemark><Placemark><name>OpenLayers.Feature.Vector_194</name><description>No description available</description><LineString><coordinates>-10958012.373438,4724114.0954794 -10488383.271719,3119547.9979404</coordinates></LineString></Placemark></Folder></kml>|3|-9490421.4305667|3972279.4853711|osm\ncoverage a", 0); $this->_addElementTextDelete($item, $this->_coverage, "Charlottesville, VA", 1); $this->dispatch('/'); set_current_record('item', $item); $covs = metadata('item', array('Dublin Core', 'Coverage'), array('all' => true, 'no_filter' => true, 'no_escape' => true)); $this->assertCount(2, $covs); $this->assertTrue(NeatlineFeatures_Functions::isKmlCoverage($covs[0])); $this->assertFalse(NeatlineFeatures_Functions::isKmlCoverage($covs[1])); }
/** * This returns the string to display a coverage field, whether a map or * not. * * @param string $text The original text for the element. * @param Omeka_Record $record The record that this text applies * to. * @param ElementText|NULL $elementText The ElementText record that stores * this text. (This is optional and defaults to NULL.) * * @return string * @author Eric Rochester <*****@*****.**> **/ public static function displayCoverage($text, $record, $elementText = NULL) { $util = new NeatlineFeatures_Utils_View(); $util->setCoverageElement(); $util->setViewOptions($text, $record, $elementText); $output = $util->getView(); return $output; }
/** * 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 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()); } }