コード例 #1
0
 /**
  * `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']);
 }
コード例 #2
0
ファイル: FilterOrderTest.php プロジェクト: saden1/Neatline
 /**
  * `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']);
 }
コード例 #3
0
ファイル: FilterHasDateTest.php プロジェクト: saden1/Neatline
 /**
  * `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']);
 }
コード例 #4
0
 /**
  * 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);
 }
コード例 #5
0
ファイル: CompileItemTest.php プロジェクト: saden1/Neatline
 /**
  * `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);
 }
コード例 #6
0
ファイル: PutTest.php プロジェクト: saden1/Neatline
 /**
  * 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);
 }
コード例 #7
0
ファイル: FilterZoomTest.php プロジェクト: saden1/Neatline
 /**
  * `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']);
 }
コード例 #8
0
ファイル: FilterHasSlugTest.php プロジェクト: saden1/Neatline
 /**
  * `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']);
 }
コード例 #9
0
ファイル: FilterTagsTest.php プロジェクト: saden1/Neatline
 /**
  * `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']);
 }
コード例 #10
0
ファイル: GetSelectTest.php プロジェクト: saden1/Neatline
 /**
  * `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);
 }
コード例 #11
0
ファイル: FilterLimitTest.php プロジェクト: saden1/Neatline
 /**
  * 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']);
 }
コード例 #12
0
ファイル: FilterExhibitTest.php プロジェクト: saden1/Neatline
 /**
  * `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']);
 }
コード例 #13
0
ファイル: FilterWidgetTest.php プロジェクト: saden1/Neatline
 /**
  * `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']);
 }
コード例 #14
0
 /**
  * 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++;
     }
 }
コード例 #15
0
 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');
 }
コード例 #16
0
ファイル: SaveFormTest.php プロジェクト: saden1/Neatline
 /**
  * When a record is saved with new tags - eg, when the tags string used to
  * be `tag1`, and is changed to `tag1,tag2` - the existing CSS rules for
  * the `tag2` should be applied to the record before it is used to update
  * the exhibit CSS.
  */
 public function testPullStyles()
 {
     $exhibit = $this->_exhibit();
     $exhibit->styles = "\n            .tag1 {\n              fill-color: 1;\n            }\n        ";
     $exhibit->save();
     // Record 1 synchronized with CSS.
     $record1 = new NeatlineRecord($exhibit);
     $record1->fill_color = '1';
     $record1->tags = 'tag1';
     $record1->save();
     // Record 2 not synchronized.
     $record2 = new NeatlineRecord($exhibit);
     $record2->fill_color = '2';
     $record2->save();
     // Add `tag1` to record 2, along with un-synchronized style.
     $record2->saveForm(array('tags' => 'tag1', 'fill_color' => '2'));
     $record1 = $this->_reload($record1);
     $record2 = $this->_reload($record2);
     // Record 1 should be unchanged.
     $this->assertEquals('1', $record1->fill_color);
     // Record 2 should pull `tag` styles.
     $this->assertEquals('1', $record2->fill_color);
 }
コード例 #17
0
ファイル: ListTest.php プロジェクト: saden1/Neatline
 /**
  * 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']);
 }
コード例 #18
0
ファイル: PullStylesTest.php プロジェクト: saden1/Neatline
 /**
  * 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);
 }
コード例 #19
0
 /**
  * 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);
 }
コード例 #20
0
ファイル: PushStylesTest.php プロジェクト: saden1/Neatline
 /**
  * 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);
 }
コード例 #21
0
 /**
  * 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;
 }