function testExcludeVariantState() { $index = singleton('SearchVariantVersionedTest_IndexNoStage'); FullTextSearch::force_index_list($index); // Check that write doesn't update stage $item = new SearchVariantVersionedTest_Item(array('TestText' => 'Foo')); $item->write(); SearchUpdater::flush_dirty_indexes(); $this->assertEquals($index->getAdded(array('ID', '_versionedstage')), array()); // Check that publish updates Live $index->reset(); $item->publish("Stage", "Live"); SearchUpdater::flush_dirty_indexes(); $this->assertEquals($index->getAdded(array('ID', '_versionedstage')), array(array('ID' => $item->ID, '_versionedstage' => 'Live'))); }
function testSavingDirect() { // Initial add $item = new SearchVariantSiteTreeSubsitesPolyhomeTest_Item(); $item->write(); SearchUpdater::flush_dirty_indexes(); $this->assertEquals(self::$index->getAdded(array('ID', '_subsite')), array(array('ID' => $item->ID, '_subsite' => 0))); // Check that adding to subsites works self::$index->reset(); $item->setField('AddToSubsite[0]', 1); $item->setField('AddToSubsite[' . self::$subsite_a->ID . ']', 1); $item->write(); SearchUpdater::flush_dirty_indexes(); $this->assertEquals(self::$index->getAdded(array('ID', '_subsite')), array(array('ID' => $item->ID, '_subsite' => 0), array('ID' => $item->ID, '_subsite' => self::$subsite_a->ID))); $this->assertEquals(self::$index->deleted, array(array('base' => 'SiteTree', 'id' => $item->ID, 'state' => array('SearchVariantVersioned' => 'Stage', 'SearchVariantSiteTreeSubsitesPolyhome' => self::$subsite_b->ID)))); }
public function testDelete() { // Setup mocks $serviceMock = $this->getServiceMock(); self::$index->setService($serviceMock); // Delete the live record (not the stage) Versioned::reading_stage('Stage'); Phockito::reset($serviceMock); $item = new SearchVariantVersionedTest_Item(array('Title' => 'Too')); $item->write(); $item->publish('Stage', 'Live'); Versioned::reading_stage('Live'); $id = $item->ID; $item->delete(); SearchUpdater::flush_dirty_indexes(); Phockito::verify($serviceMock, 1)->deleteById($this->getExpectedDocumentId($id, 'Live')); Phockito::verify($serviceMock, 0)->deleteById($this->getExpectedDocumentId($id, 'Stage')); // Delete the stage record Versioned::reading_stage('Stage'); Phockito::reset($serviceMock); $item = new SearchVariantVersionedTest_Item(array('Title' => 'Too')); $item->write(); $item->publish('Stage', 'Live'); $id = $item->ID; $item->delete(); SearchUpdater::flush_dirty_indexes(); Phockito::verify($serviceMock, 1)->deleteById($this->getExpectedDocumentId($id, 'Stage')); Phockito::verify($serviceMock, 0)->deleteById($this->getExpectedDocumentId($id, 'Live')); }
function testHasManyHook() { $container1 = new SearchUpdaterTest_Container(); $container1->write(); $container2 = new SearchUpdaterTest_Container(); $container2->write(); //self::$index->reset(); //SearchUpdater::clear_dirty_indexes(); $hasMany1 = new SearchUpdaterTest_HasMany(); $hasMany1->HasManyContainerID = $container1->ID; $hasMany1->write(); $hasMany2 = new SearchUpdaterTest_HasMany(); $hasMany2->HasManyContainerID = $container1->ID; $hasMany2->write(); SearchUpdater::flush_dirty_indexes(); $this->assertEquals(self::$index->getAdded(array('ID')), array(array('ID' => $container1->ID), array('ID' => $container2->ID))); self::$index->reset(); $hasMany1->Field1 = 'Updated'; $hasMany1->write(); $hasMany2->Field1 = 'Updated'; $hasMany2->write(); SearchUpdater::flush_dirty_indexes(); $this->assertEquals(self::$index->getAdded(array('ID')), array(array('ID' => $container1->ID))); }