2011-05-02 06:33:05 +02:00
|
|
|
<?php
|
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
class SearchVariantVersionedTest extends SapphireTest
|
|
|
|
{
|
2016-04-15 05:46:19 +02:00
|
|
|
/**
|
|
|
|
* @var SearchVariantVersionedTest_Index
|
|
|
|
*/
|
2015-11-21 07:19:20 +01:00
|
|
|
private static $index = null;
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
protected $extraDataObjects = array(
|
|
|
|
'SearchVariantVersionedTest_Item'
|
|
|
|
);
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2015-06-29 07:09:24 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
// Check versioned available
|
|
|
|
if (!class_exists('Versioned')) {
|
|
|
|
return $this->markTestSkipped('The versioned decorator is not installed');
|
|
|
|
}
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
if (self::$index === null) {
|
|
|
|
self::$index = singleton('SearchVariantVersionedTest_Index');
|
|
|
|
}
|
2012-07-19 03:38:43 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
SearchUpdater::bind_manipulation_capture();
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
Config::inst()->update('Injector', 'SearchUpdateProcessor', array(
|
|
|
|
'class' => 'SearchUpdateImmediateProcessor'
|
|
|
|
));
|
2014-03-24 21:55:13 +01:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
FullTextSearch::force_index_list(self::$index);
|
|
|
|
SearchUpdater::clear_dirty_indexes();
|
|
|
|
}
|
2014-03-24 21:55:13 +01:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
public function testPublishing()
|
|
|
|
{
|
|
|
|
// Check that write updates Stage
|
2014-03-24 21:55:13 +01:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
$item = new SearchVariantVersionedTest_Item(array('TestText' => 'Foo'));
|
|
|
|
$item->write();
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
SearchUpdater::flush_dirty_indexes();
|
|
|
|
$this->assertEquals(self::$index->getAdded(array('ID', '_versionedstage')), array(
|
|
|
|
array('ID' => $item->ID, '_versionedstage' => 'Stage')
|
|
|
|
));
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
// Check that publish updates Live
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
self::$index->reset();
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
$item->publish("Stage", "Live");
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
SearchUpdater::flush_dirty_indexes();
|
|
|
|
$this->assertEquals(self::$index->getAdded(array('ID', '_versionedstage')), array(
|
|
|
|
array('ID' => $item->ID, '_versionedstage' => 'Live')
|
|
|
|
));
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
// Just update a SiteTree field, and check it updates Stage
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
self::$index->reset();
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
$item->Title = "Pow!";
|
|
|
|
$item->write();
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
SearchUpdater::flush_dirty_indexes();
|
2016-04-15 05:46:19 +02:00
|
|
|
|
|
|
|
$expected = array(array(
|
|
|
|
'ID' => $item->ID,
|
|
|
|
'_versionedstage' => 'Stage'
|
2015-11-21 07:19:20 +01:00
|
|
|
));
|
2016-04-15 05:46:19 +02:00
|
|
|
$added = self::$index->getAdded(array('ID', '_versionedstage'));
|
|
|
|
$this->assertEquals($expected, $added);
|
2017-03-08 23:40:13 +01:00
|
|
|
|
|
|
|
// Test unpublish
|
|
|
|
|
|
|
|
self::$index->reset();
|
|
|
|
|
|
|
|
$item->deleteFromStage('Live');
|
|
|
|
|
|
|
|
SearchUpdater::flush_dirty_indexes();
|
|
|
|
|
2017-03-09 11:32:56 +01:00
|
|
|
$this->assertCount(1, self::$index->deleted);
|
2017-03-08 23:40:13 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
'SiteTree',
|
|
|
|
self::$index->deleted[0]['base']
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
$item->ID,
|
|
|
|
self::$index->deleted[0]['id']
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
'Live',
|
|
|
|
self::$index->deleted[0]['state']['SearchVariantVersioned']
|
|
|
|
);
|
2015-11-21 07:19:20 +01:00
|
|
|
}
|
2012-08-28 23:21:51 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
public function testExcludeVariantState()
|
|
|
|
{
|
|
|
|
$index = singleton('SearchVariantVersionedTest_IndexNoStage');
|
|
|
|
FullTextSearch::force_index_list($index);
|
2012-08-28 23:21:51 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
// 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());
|
2012-08-28 23:21:51 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
// 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')
|
|
|
|
));
|
|
|
|
}
|
2011-05-02 06:33:05 +02:00
|
|
|
}
|
2015-06-29 07:09:24 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
class SearchVariantVersionedTest_Item extends SiteTree implements TestOnly
|
|
|
|
{
|
|
|
|
// TODO: Currently theres a failure if you addClass a non-table class
|
|
|
|
private static $db = array(
|
|
|
|
'TestText' => 'Varchar'
|
|
|
|
);
|
2015-06-29 07:09:24 +02:00
|
|
|
}
|
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
class SearchVariantVersionedTest_Index extends SearchIndex_Recording
|
|
|
|
{
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->addClass('SearchVariantVersionedTest_Item');
|
|
|
|
$this->addFilterField('TestText');
|
|
|
|
}
|
2015-06-29 07:09:24 +02:00
|
|
|
}
|
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
class SearchVariantVersionedTest_IndexNoStage extends SearchIndex_Recording
|
|
|
|
{
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->addClass('SearchVariantVersionedTest_Item');
|
|
|
|
$this->addFilterField('TestText');
|
|
|
|
$this->excludeVariantState(array('SearchVariantVersioned' => 'Stage'));
|
|
|
|
}
|
|
|
|
}
|