/** * `order` ~ Sort the results on the provided column / direction. */ public function testFilterOrder() { $exhibit = $this->_exhibit(); $record1 = new NeatlineRecord($exhibit); $record2 = new NeatlineRecord($exhibit); $record3 = new NeatlineRecord($exhibit); $record1->weight = 3; $record2->weight = 2; $record3->weight = 1; $record1->added = '2003-01-01'; $record2->added = '2002-01-01'; $record3->added = '2001-01-01'; $record1->save(); $record2->save(); $record3->save(); // Order on `weight`, by default ascending. $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit->id, 'order' => 'weight')); $this->assertEquals($record3->id, $result['records'][0]['id']); $this->assertEquals($record2->id, $result['records'][1]['id']); $this->assertEquals($record1->id, $result['records'][2]['id']); $this->assertCount(3, $result['records']); // Order on `weight ASC`. $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit->id, 'order' => 'weight ASC')); $this->assertEquals($record3->id, $result['records'][0]['id']); $this->assertEquals($record2->id, $result['records'][1]['id']); $this->assertEquals($record1->id, $result['records'][2]['id']); $this->assertCount(3, $result['records']); // Order on `weight DESC`. $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit->id, 'order' => 'weight DESC')); $this->assertEquals($record1->id, $result['records'][0]['id']); $this->assertEquals($record2->id, $result['records'][1]['id']); $this->assertEquals($record3->id, $result['records'][2]['id']); $this->assertCount(3, $result['records']); }
/** * `getExhibit` should return the parent exhibit. */ public function testGetExhibit() { $exhibit = $this->_exhibit(); $record = new NeatlineRecord($exhibit); $retrieved = $record->getExhibit(); $this->assertEquals($exhibit->id, $retrieved->id); }
/** * `getItem` should return the parent item. */ public function testGetItem() { $item = $this->_item(); $record = new NeatlineRecord(null, $item); $retrieved = $record->getItem(); $this->assertEquals($item->id, $retrieved->id); }
/** * `query` ~ Fulltext search in `title`, `body`, and `slug`. */ public function testFilterQuery() { $exhibit = $this->_exhibit(); $record1 = new NeatlineRecord($exhibit); $record2 = new NeatlineRecord($exhibit); $record3 = new NeatlineRecord($exhibit); $record1->title = 'title1'; $record2->title = 'title2'; $record3->title = 'title3'; $record1->body = 'body1'; $record2->body = 'body2'; $record3->body = 'body3'; $record1->slug = 'slug1'; $record2->slug = 'slug2'; $record3->slug = 'slug3'; $record1->save(); $record2->save(); $record3->save(); // Should search in `title` field. $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit->id, 'query' => 'title1')); $this->assertEquals($record1->id, $result['records'][0]['id']); $this->assertCount(1, $result['records']); // Should search in `body` field. $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit->id, 'query' => 'body1')); $this->assertEquals($record1->id, $result['records'][0]['id']); $this->assertCount(1, $result['records']); // Should search in `slug` field. $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit->id, 'query' => 'slug1')); $this->assertEquals($record1->id, $result['records'][0]['id']); $this->assertCount(1, $result['records']); }
/** * `hasDate` ~ Match records with start and/or end dates. */ public function testFilterHasSlug() { $exhibit = $this->_exhibit(); $record1 = new NeatlineRecord($exhibit); $record2 = new NeatlineRecord($exhibit); $record3 = new NeatlineRecord($exhibit); $record4 = new NeatlineRecord($exhibit); $record1->start_date = '2014'; // Start $record2->end_date = '2015'; // End $record3->start_date = '2014'; // Both $record3->end_date = '2015'; // Both $record1->added = '2004-01-01'; $record2->added = '2003-01-01'; $record3->added = '2002-01-01'; $record4->added = '2001-01-01'; $record1->save(); $record2->save(); $record3->save(); $record4->save(); // Query for `hasDate`. $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit->id, 'hasDate' => true)); $this->assertEquals($result['records'][0]['id'], $record1->id); $this->assertEquals($result['records'][1]['id'], $record2->id); $this->assertEquals($result['records'][2]['id'], $record3->id); $this->assertCount(3, $result['records']); }
/** * When a coverage is defined, `toArrayForSave` should set the value. */ public function testDefinedCoverage() { $record = new NeatlineRecord(); $record->coverage = 'POINT(1 1)'; $record->save(); $record = $this->_reload($record); // Should set coverage. $this->assertEquals('POINT(1 1)', $record->coverage); }
/** * `compileItem` should write the "Title" element on the parent item to * the `item_title` field. */ public function testCompileItem() { $exhibit = $this->_exhibit(); $item = $this->_item('title'); $record = new NeatlineRecord($exhibit, $item); $record->save(); // `item_title` should be set. $this->assertEquals('title', $record->item_title); }
/** * Create a record. * @REST */ public function postAction() { // Create record. $record = new NeatlineRecord(); $post = Zend_Json::decode($this->_request->getRawBody()); $record->saveForm($post); // Respond with record data. echo Zend_Json::encode($record->toArray()); }
/** * `pullStyles` should update the stylesheet with record values. */ public function testPullStyles() { $exhibit = $this->_exhibit(); $exhibit->styles = "\n .tag1 {\n fill-color: 1;\n fill-color-select: 2;\n }\n .tag2 {\n stroke-color: 3;\n stroke-color-select: 4;\n }\n .tag3 {\n zindex: 5;\n weight: 6;\n }\n "; $record = new NeatlineRecord($exhibit); $record->setArray(array('tags' => 'tag1,tag2', 'fill_color' => '7', 'fill_color_select' => '8', 'stroke_color' => '9', 'stroke_color_select' => '10')); $exhibit->pullStyles($record); $this->assertEquals(array('tag1' => array('fill_color' => '7', 'fill_color_select' => '8'), 'tag2' => array('stroke_color' => '9', 'stroke_color_select' => '10'), 'tag3' => array('zindex' => '5', 'weight' => '6')), nl_readCSS($exhibit->styles)); }
/** * PUT should propagate the exhibit stylesheet. */ public function testUpdateStyles() { $exhibit = $this->_exhibit(); $record = new NeatlineRecord($exhibit); $record->tags = 'tag1'; $record->save(); $values = array('styles' => "\n .tag1 {\n fill-color: color;\n }\n "); $this->_setPut($values); $this->dispatch('neatline/exhibits/' . $exhibit->id); $record = $this->_reload($record); // `styles` should be updated. $this->assertEquals('color', $record->fill_color); }
/** * `zoom` ~ Match records that are visible at a given zoom level. */ public function testFilterZoom() { $exhibit = $this->_exhibit(); $record1 = new NeatlineRecord($exhibit); $record2 = new NeatlineRecord($exhibit); $record3 = new NeatlineRecord($exhibit); $record4 = new NeatlineRecord($exhibit); $record1->added = '2004-01-01'; $record2->added = '2003-01-01'; $record3->added = '2002-01-01'; $record4->added = '2001-01-01'; // Both null. $record1->min_zoom = null; $record1->max_zoom = null; // Min set, max null. $record2->min_zoom = 10; $record2->max_zoom = null; // Min null, max set. $record3->min_zoom = null; $record3->max_zoom = 15; // Both set. $record4->min_zoom = 20; $record4->max_zoom = 30; $record1->save(); $record2->save(); $record3->save(); $record4->save(); // Zoom = null $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit->id)); $this->assertEquals($record1->id, $result['records'][0]['id']); $this->assertEquals($record2->id, $result['records'][1]['id']); $this->assertEquals($record3->id, $result['records'][2]['id']); $this->assertEquals($record4->id, $result['records'][3]['id']); $this->assertCount(4, $result['records']); // Zoom < min_zoom. $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit->id, 'zoom' => 9)); $this->assertEquals($record1->id, $result['records'][0]['id']); $this->assertEquals($record3->id, $result['records'][1]['id']); $this->assertCount(2, $result['records']); // Zoom > min_zoom. $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit->id, 'zoom' => 16)); $this->assertEquals($record1->id, $result['records'][0]['id']); $this->assertEquals($record2->id, $result['records'][1]['id']); $this->assertCount(2, $result['records']); // min_zoom < Zoom < max_zoom. $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit->id, 'zoom' => 25)); $this->assertEquals($record1->id, $result['records'][0]['id']); $this->assertEquals($record2->id, $result['records'][1]['id']); $this->assertEquals($record4->id, $result['records'][2]['id']); $this->assertCount(3, $result['records']); }
/** * For any given Omeka item, `Neatline_Job_ImportItems` should check to * see if a record already exists in the exhibit for the item; if so, the * record should be re-compiled, but not duplicated. */ public function testRecompileRecords() { $item = $this->_item(); $exhibit = $this->_exhibit(); // Create existing item-backed record. $record = new NeatlineRecord($exhibit, $item); $record->__save(); Zend_Registry::get('bootstrap')->getResource('jobs')->send('Neatline_Job_ImportItems', array('exhibit_id' => $exhibit->id, 'query' => array('range' => $item->id))); // Should not duplicate the record. $records = $this->_getRecordsByExhibit($exhibit); $this->assertCount(1, $records); // Should recompile the record. $this->assertNotNull($records[0]['item_title']); }
/** * `hasSlug` ~ Match records that have non-empty slugs. */ public function testFilterHasSlug() { $exhibit = $this->_exhibit(); $record1 = new NeatlineRecord($exhibit); $record2 = new NeatlineRecord($exhibit); $record1->slug = 'slug'; $record2->slug = null; $record1->save(); $record2->save(); // Query for `hasSlug`. $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit->id, 'hasSlug' => true)); $this->assertEquals($result['records'][0]['id'], $record1->id); $this->assertCount(1, $result['records']); }
/** * `tags` ~ Match records tagged with all comma-delimited values. */ public function testFilterTags() { $exhibit = $this->_exhibit(); $record1 = new NeatlineRecord($exhibit); $record2 = new NeatlineRecord($exhibit); $record3 = new NeatlineRecord($exhibit); $record1->tags = 'tag1'; $record2->tags = 'tag1,tag2'; $record3->tags = 'tag3'; $record1->save(); $record2->save(); $record3->save(); // Query for tag1 and tag2. $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit->id, 'tags' => array('tag1', 'tag2'))); $this->assertEquals($record2->id, $result['records'][0]['id']); $this->assertCount(1, $result['records']); }
/** * `getSelect` should order records by `added`. */ public function testOrderByAdded() { $record1 = new NeatlineRecord(); $record2 = new NeatlineRecord(); $record3 = new NeatlineRecord(); $record1->added = '2003-01-01'; $record2->added = '2002-01-01'; $record3->added = '2001-01-01'; $record1->save(); $record2->save(); $record3->save(); // Query for the records. $records = $this->_records->fetchObjects($this->_records->getSelect()); // Should be in reverse chronological order. $this->assertEquals($record1->id, $records[0]->id); $this->assertEquals($record2->id, $records[1]->id); $this->assertEquals($record3->id, $records[2]->id); }
/** * When a `limit` and `start` values are passed, the result set should be * truncated to the `limit` length, starting from the `start` value. */ public function testFilterLimit() { $exhibit = $this->_exhibit(); $record1 = new NeatlineRecord($exhibit); $record2 = new NeatlineRecord($exhibit); $record3 = new NeatlineRecord($exhibit); $record4 = new NeatlineRecord($exhibit); $record5 = new NeatlineRecord($exhibit); $record1->added = '2005-01-01'; $record2->added = '2004-01-01'; $record3->added = '2003-01-01'; $record4->added = '2002-01-01'; $record5->added = '2001-01-01'; $record1->save(); $record2->save(); $record3->save(); $record4->save(); $record5->save(); // Records 1-2 (implicit start=0). $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit->id, 'limit' => 2)); $this->assertEquals($record1->id, $result['records'][0]['id']); $this->assertEquals($record2->id, $result['records'][1]['id']); $this->assertEquals(0, $result['start']); $this->assertCount(2, $result['records']); // Records 1-2 (explicit start=0). $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit->id, 'limit' => 2, 'start' => 0)); $this->assertEquals($record1->id, $result['records'][0]['id']); $this->assertEquals($record2->id, $result['records'][1]['id']); $this->assertEquals(0, $result['start']); $this->assertCount(2, $result['records']); // Records 3-4. $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit->id, 'limit' => 2, 'start' => 2)); $this->assertEquals($record3->id, $result['records'][0]['id']); $this->assertEquals($record4->id, $result['records'][1]['id']); $this->assertEquals(2, $result['start']); $this->assertCount(2, $result['records']); // Record 5. $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit->id, 'limit' => 2, 'start' => 4)); $this->assertEquals($record5->id, $result['records'][0]['id']); $this->assertEquals(4, $result['start']); $this->assertCount(1, $result['records']); }
/** * `exhibit_id` ~ Match records that belong to the exhibit with the passed * ID. Records in other exhibits should be excluded. */ public function testFilterExhibit() { $exhibit1 = $this->_exhibit(); $exhibit2 = $this->_exhibit(); $record1 = new NeatlineRecord($exhibit1); $record2 = new NeatlineRecord($exhibit1); $record3 = new NeatlineRecord($exhibit2); $record1->added = '2003-01-01'; $record2->added = '2002-01-01'; $record3->added = '2001-01-01'; $record1->save(); $record2->save(); $record3->save(); // Query for exhibit1 records. $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit1->id)); // Exhibit2 records should be absent. $this->assertEquals($record1->id, $result['records'][0]['id']); $this->assertEquals($record2->id, $result['records'][1]['id']); $this->assertCount(2, $result['records']); }
/** * `widget` ~ Match records that are activated on a widget. */ public function testFilterWidget() { $exhibit = $this->_exhibit(); $record1 = new NeatlineRecord($exhibit); $record2 = new NeatlineRecord($exhibit); $record3 = new NeatlineRecord($exhibit); $record1->widgets = 'Widget1'; $record2->widgets = 'Widget1,Widget2'; $record3->widgets = 'Widget3'; $record1->added = '2003-01-01'; $record2->added = '2002-01-01'; $record3->added = '2001-01-01'; $record1->save(); $record2->save(); $record3->save(); // Query for `tag1` and `tag2`. $result = $this->_records->queryRecords(array('exhibit_id' => $exhibit->id, 'widget' => 'Widget1')); $this->assertEquals($record1->id, $result['records'][0]['id']); $this->assertEquals($record2->id, $result['records'][1]['id']); $this->assertCount(2, $result['records']); }
/** * Import Omeka items. */ public function perform() { $_records = $this->_db->getTable('NeatlineRecord'); $_exhibits = $this->_db->getTable('NeatlineExhibit'); $_items = $this->_db->getTable('Item'); // Load the exhibit, alias the query. $exhibit = $_exhibits->find($this->_options['exhibit_id']); $query = $this->_options['query']; $i = 0; while ($items = $_items->findBy($query, 10, $i)) { foreach ($items as $item) { // Try to find an existing record. $record = $_records->findBySql('exhibit_id=? && item_id=?', array($exhibit->id, $item->id), true); // Otherwise, create one. if (!$record) { $record = new NeatlineRecord($exhibit, $item); $record->added = $item->added; } $record->save(); } $i++; } }
public function testRecords() { for ($i = 0; $i < 6; $i++) { $record = new NeatlineRecord($this->exhibit); $record->added = '200' . $i . '-01-01'; $record->title = 'Record' . $i; $record->save(); } // Records 1-2. $this->request->setQuery(array('limit' => '2', 'start' => '0')); $this->_writeRecordsApiFixture($this->exhibit, 'EditorRecordsShowPagination.p12.json'); // Records 2-3. $this->request->setQuery(array('limit' => '2', 'start' => '1')); $this->_writeRecordsApiFixture($this->exhibit, 'EditorRecordsShowPagination.p23.json'); // Records 3-4. $this->request->setQuery(array('limit' => '2', 'start' => '2')); $this->_writeRecordsApiFixture($this->exhibit, 'EditorRecordsShowPagination.p34.json'); // Records 5-6. $this->request->setQuery(array('limit' => '2', 'start' => '4')); $this->_writeRecordsApiFixture($this->exhibit, 'EditorRecordsShowPagination.p56.json'); // Record 6. $this->request->setQuery(array('limit' => '2', 'start' => '5')); $this->_writeRecordsApiFixture($this->exhibit, 'EditorRecordsShowPagination.p6.json'); }
/** * The `limit` and `start` parameters should be passed to the query. */ public function testLimitFilter() { $record1 = new NeatlineRecord($this->exhibit); $record2 = new NeatlineRecord($this->exhibit); $record3 = new NeatlineRecord($this->exhibit); $record1->added = '2003-01-01'; $record2->added = '2002-01-01'; $record3->added = '2001-01-01'; $record1->save(); $record2->save(); $record3->save(); $this->request->setQuery(array('limit' => 1, 'start' => 1)); $this->dispatch('neatline/records'); $json = $this->_getResponseArray(); // Should apply limit filter. $this->assertEquals($record2->id, $json['records'][0]['id']); $this->assertCount(1, $json['records']); }
/** * Does the user own the record? * * @param User $user The user. * @param NeatlineRecord $record The record. * @return boolean */ private function _userOwnsRecord($user, $record) { $ownsRecord = $record->isOwnedBy($user); $ownsExhibit = $record->getExhibit()->isOwnedBy($user); return $ownsRecord || $ownsExhibit; }
/** * When data is saved to a new, unsaved record, values from the `all` * selector should be pulled to the record before it is used to update the * exhibit CSS. */ public function testPullAllTagWhenUnsaved() { $exhibit = $this->_exhibit(); $exhibit->styles = "\n .all {\n fill-color: 1;\n }\n "; $exhibit->save(); // Save data to unsaved record. $record = new NeatlineRecord($exhibit); $record->saveForm(array('fill_color' => '2')); // Should pull CSS value. $this->assertEquals('1', $record->fill_color); // CSS should be unchanged. $this->assertEquals(array('all' => array('fill_color' => '1')), nl_readCSS($exhibit->styles)); }
/** * Rules with `none` values should be pulled as NULL. */ public function testNoneCssValues() { $exhibit = $this->_exhibit(); $exhibit->styles = "\n .tag {\n point-image: none;\n }\n "; $exhibit->save(); $record = new NeatlineRecord($exhibit); // Pull `tag`. $record->pullStyles(array('tag')); $record->save(); $record = $this->_reload($record); // `none` should be cast to NULL. $this->assertNull($record->point_image); }
/** * Only update records that belong to the exhibit should be updated. */ public function testExhibitIsolation() { $exhibit1 = $this->_exhibit(); $exhibit2 = $this->_exhibit(); $exhibit1->styles = "\n .tag1 {\n fill-color: color;\n }\n "; $record1 = new NeatlineRecord($exhibit1); $record2 = new NeatlineRecord($exhibit2); $record1->tags = 'tag1'; $record2->tags = 'tag1'; $record1->save(); $record2->save(); $exhibit1->pushStyles(); $record1 = $this->_reload($record1); $record2 = $this->_reload($record2); // Just exhibit 1 records should be updated. $this->assertEquals('color', $record1->fill_color); $this->assertEquals('#00aeff', $record2->fill_color); }
/** * Create a data record. * * @param NeatlineExhibit $exhibit The parent exhibit. * @param Item $item The parent item. * @return NeatlineRecord $record The record. */ protected function _record($exhibit = null, $item = null) { // Get parent exhibit. if (is_null($exhibit)) { $exhibit = $this->_exhibit(); } // Create record. $record = new NeatlineRecord($exhibit, $item); $record->save(); return $record; }
/** * Data from the "Coverage" element shouldn't clobber existing coverages. */ public function testImportDublinCorePreserveExistingCoverages() { $this->_skipIfPlugin('NeatlineFeatures'); $exhibit = $this->_exhibit(); $item = $this->_item(); $this->_addCoverageElement($item, 'POINT(1 2)'); $record = new NeatlineRecord($exhibit, $item); $record->coverage = 'POINT(3 4)'; $record->save(); // Shouldn't modify existing coverage. $this->assertEquals('POINT(3 4)', $record->coverage); }