1 | <?php |
||||||
2 | |||||||
3 | namespace SilverStripe\FullTextSearch\Tests; |
||||||
4 | |||||||
5 | use SilverStripe\Core\Config\Config; |
||||||
6 | use SilverStripe\CMS\Model\SiteTree; |
||||||
7 | use SilverStripe\Dev\SapphireTest; |
||||||
8 | use SilverStripe\FullTextSearch\Search\FullTextSearch; |
||||||
9 | use SilverStripe\FullTextSearch\Search\Indexes\SearchIndex_Recording; |
||||||
10 | use SilverStripe\FullTextSearch\Search\Variants\SearchVariantVersioned; |
||||||
11 | use SilverStripe\FullTextSearch\Tests\SearchVariantVersionedTest\SearchVariantVersionedTest_Index; |
||||||
12 | use SilverStripe\FullTextSearch\Tests\SearchVariantVersionedTest\SearchVariantVersionedTest_Item; |
||||||
13 | use SilverStripe\FullTextSearch\Tests\SearchVariantVersionedTest\SearchVariantVersionedTest_IndexNoStage; |
||||||
14 | use SilverStripe\FullTextSearch\Search\Processors\SearchUpdateProcessor; |
||||||
15 | use SilverStripe\FullTextSearch\Search\Processors\SearchUpdateImmediateProcessor; |
||||||
16 | use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater; |
||||||
17 | |||||||
18 | class SearchVariantVersionedTest extends SapphireTest |
||||||
19 | { |
||||||
20 | /** |
||||||
21 | * @var SearchVariantVersionedTest_Index |
||||||
22 | */ |
||||||
23 | private static $index = null; |
||||||
24 | |||||||
25 | protected static $extra_dataobjects = array( |
||||||
26 | SearchVariantVersionedTest_Item::class |
||||||
27 | ); |
||||||
28 | |||||||
29 | protected function setUp() |
||||||
30 | { |
||||||
31 | parent::setUp(); |
||||||
32 | |||||||
33 | if (self::$index === null) { |
||||||
34 | self::$index = singleton(SearchVariantVersionedTest_Index::class); |
||||||
35 | } |
||||||
36 | |||||||
37 | Config::modify()->set(Injector::class, SearchUpdateProcessor::class, array( |
||||||
0 ignored issues
–
show
|
|||||||
38 | 'class' => SearchUpdateImmediateProcessor::class |
||||||
39 | )); |
||||||
40 | |||||||
41 | FullTextSearch::force_index_list(self::$index); |
||||||
42 | SearchUpdater::clear_dirty_indexes(); |
||||||
43 | } |
||||||
44 | |||||||
45 | public function testPublishing() |
||||||
46 | { |
||||||
47 | // Check that write updates Stage |
||||||
48 | |||||||
49 | $item = new SearchVariantVersionedTest_Item(array('TestText' => 'Foo')); |
||||||
50 | $item->write(); |
||||||
51 | |||||||
52 | SearchUpdater::flush_dirty_indexes(); |
||||||
53 | $this->assertEquals(array( |
||||||
54 | array('ID' => $item->ID, '_versionedstage' => 'Stage') |
||||||
55 | ), self::$index->getAdded(array('ID', '_versionedstage'))); |
||||||
56 | |||||||
57 | // Check that publish updates Live |
||||||
58 | |||||||
59 | self::$index->reset(); |
||||||
60 | |||||||
61 | $item->copyVersionToStage('Stage', 'Live'); |
||||||
0 ignored issues
–
show
The method
copyVersionToStage() does not exist on SilverStripe\FullTextSea...riantVersionedTest_Item . Since you implemented __call , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
62 | |||||||
63 | SearchUpdater::flush_dirty_indexes(); |
||||||
64 | $this->assertEquals(array( |
||||||
65 | array('ID' => $item->ID, '_versionedstage' => 'Stage'), |
||||||
66 | array('ID' => $item->ID, '_versionedstage' => 'Live') |
||||||
67 | ), self::$index->getAdded(array('ID', '_versionedstage'))); |
||||||
68 | |||||||
69 | // Just update a SiteTree field, and check it updates Stage |
||||||
70 | |||||||
71 | self::$index->reset(); |
||||||
72 | |||||||
73 | $item->Title = "Pow!"; |
||||||
74 | $item->write(); |
||||||
75 | |||||||
76 | SearchUpdater::flush_dirty_indexes(); |
||||||
77 | |||||||
78 | $expected = array(array( |
||||||
79 | 'ID' => $item->ID, |
||||||
80 | '_versionedstage' => 'Stage' |
||||||
81 | )); |
||||||
82 | $added = self::$index->getAdded(array('ID', '_versionedstage')); |
||||||
83 | $this->assertEquals($expected, $added); |
||||||
84 | |||||||
85 | // Test unpublish |
||||||
86 | |||||||
87 | self::$index->reset(); |
||||||
88 | |||||||
89 | $item->deleteFromStage('Live'); |
||||||
0 ignored issues
–
show
The method
deleteFromStage() does not exist on SilverStripe\FullTextSea...riantVersionedTest_Item . Since you implemented __call , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
90 | |||||||
91 | SearchUpdater::flush_dirty_indexes(); |
||||||
92 | |||||||
93 | $this->assertCount(1, self::$index->deleted); |
||||||
94 | $this->assertEquals( |
||||||
95 | SiteTree::class, |
||||||
96 | self::$index->deleted[0]['base'] |
||||||
97 | ); |
||||||
98 | $this->assertEquals( |
||||||
99 | $item->ID, |
||||||
100 | self::$index->deleted[0]['id'] |
||||||
101 | ); |
||||||
102 | $this->assertEquals( |
||||||
103 | 'Live', |
||||||
104 | self::$index->deleted[0]['state'][SearchVariantVersioned::class] |
||||||
105 | ); |
||||||
106 | } |
||||||
107 | |||||||
108 | public function testExcludeVariantState() |
||||||
109 | { |
||||||
110 | $index = singleton(SearchVariantVersionedTest_IndexNoStage::class); |
||||||
111 | FullTextSearch::force_index_list($index); |
||||||
112 | |||||||
113 | // Check that write doesn't update stage |
||||||
114 | $item = new SearchVariantVersionedTest_Item(array('TestText' => 'Foo')); |
||||||
115 | $item->write(); |
||||||
116 | SearchUpdater::flush_dirty_indexes(); |
||||||
117 | $this->assertEquals(array(), $index->getAdded(array('ID', '_versionedstage'))); |
||||||
118 | |||||||
119 | // Check that publish updates Live |
||||||
120 | $index->reset(); |
||||||
121 | |||||||
122 | $item->copyVersionToStage('Stage', 'Live'); |
||||||
123 | |||||||
124 | SearchUpdater::flush_dirty_indexes(); |
||||||
125 | $this->assertEquals(array( |
||||||
126 | array('ID' => $item->ID, '_versionedstage' => 'Live') |
||||||
127 | ), $index->getAdded(array('ID', '_versionedstage'))); |
||||||
128 | } |
||||||
129 | |||||||
130 | public function testCanBeDisabledViaConfig() |
||||||
131 | { |
||||||
132 | $variant = new SearchVariantVersioned; |
||||||
133 | |||||||
134 | Config::modify()->set(SearchVariantVersioned::class, 'enabled', true); |
||||||
135 | $this->assertTrue($variant->appliesToEnvironment()); |
||||||
136 | |||||||
137 | Config::modify()->set(SearchVariantVersioned::class, 'enabled', false); |
||||||
138 | $this->assertFalse($variant->appliesToEnvironment()); |
||||||
139 | } |
||||||
140 | } |
||||||
141 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths