1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File contains: eZ\Publish\Core\Search\Legacy\Tests\Content\WordIndexer\Gateway\DoctrineDatabaseTest class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Publish\Core\Search\Legacy\Tests\Content\WordIndexer\Gateway; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase as ContentGateway; |
12
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Handler as ContentHandler; |
13
|
|
|
use eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Gateway\DoctrineDatabase; |
14
|
|
|
use eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex; |
15
|
|
|
use eZ\Publish\Core\Search\Legacy\Tests\Content\AbstractTestCase; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Test case for eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Gateway\DoctrineDatabase. |
19
|
|
|
*/ |
20
|
|
|
class DoctrineDatabaseTest extends AbstractTestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Database gateway to test. |
24
|
|
|
* |
25
|
|
|
* @var \eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Gateway\DoctrineDatabase |
26
|
|
|
*/ |
27
|
|
|
protected $databaseGateway; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var \eZ\Publish\SPI\Persistence\Content\Handler |
31
|
|
|
*/ |
32
|
|
|
private $contentHandler; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return \eZ\Publish\SPI\Persistence\Content\Handler |
36
|
|
|
*/ |
37
|
|
View Code Duplication |
protected function getContentHandler() |
38
|
|
|
{ |
39
|
|
|
if (!isset($this->contentHandler)) { |
40
|
|
|
$this->contentHandler = new ContentHandler( |
|
|
|
|
41
|
|
|
new ContentGateway( |
|
|
|
|
42
|
|
|
$this->getDatabaseHandler(), |
43
|
|
|
$this->getDatabaseConnection(), |
44
|
|
|
$this->getLanguageMaskGenerator() |
45
|
|
|
) |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $this->contentHandler; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return \eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Repository\SearchIndex |
54
|
|
|
*/ |
55
|
|
|
protected function getSearchIndex() |
56
|
|
|
{ |
57
|
|
|
return new SearchIndex($this->getDatabaseHandler()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns a ready to test DoctrineDatabase gateway. |
62
|
|
|
* |
63
|
|
|
* @return \eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Gateway\DoctrineDatabase |
64
|
|
|
*/ |
65
|
|
|
protected function getDatabaseGateway() |
66
|
|
|
{ |
67
|
|
|
if (!isset($this->databaseGateway)) { |
68
|
|
|
$this->databaseGateway = new DoctrineDatabase( |
69
|
|
|
$this->getDatabaseHandler(), |
70
|
|
|
$this->getContentTypeHandler(), |
71
|
|
|
$this->getDefinitionBasedTransformationProcessor(), |
72
|
|
|
$this->getSearchIndex(), |
73
|
|
|
[] // Means the default config should be used |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $this->databaseGateway; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @covers \eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Gateway\DoctrineDatabase::__construct |
82
|
|
|
*/ |
83
|
|
|
public function testCtor() |
84
|
|
|
{ |
85
|
|
|
$handler = $this->getDatabaseHandler(); |
86
|
|
|
$gateway = $this->getDatabaseGateway(); |
87
|
|
|
|
88
|
|
|
$this->assertAttributeSame( |
89
|
|
|
$handler, |
90
|
|
|
'dbHandler', |
91
|
|
|
$gateway |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Test indexing of Turkish characters. |
97
|
|
|
* The fixture must contain the words "eei eeİ eeı eeI". |
98
|
|
|
* |
99
|
|
|
* @see https://jira.ez.no/browse/EZP-30481 |
100
|
|
|
* @covers \eZ\Publish\Core\Search\Legacy\Content\WordIndexer\Gateway\DoctrineDatabase::buildWordIDArray |
101
|
|
|
*/ |
102
|
|
|
public function testBuildWordIDArrayWithTurkishChars() |
103
|
|
|
{ |
104
|
|
|
$gateway = $this->getDatabaseGateway(); |
105
|
|
|
|
106
|
|
|
$content = $this->getContentHandler()->load(100); |
107
|
|
|
$fullTextMapper = $this->getFullTextMapper($this->getContentTypeHandler()); |
108
|
|
|
$fullTextData = $fullTextMapper->mapContent($content); |
109
|
|
|
|
110
|
|
|
$gateway->index($fullTextData); |
111
|
|
|
|
112
|
|
|
// Assert words where saved in the index |
113
|
|
|
self::assertQueryResult( |
114
|
|
|
[ |
115
|
|
|
[ |
116
|
|
|
'word' => 'eei', |
117
|
|
|
'object_count' => '1', |
118
|
|
|
], |
119
|
|
|
[ |
120
|
|
|
'word' => 'eeI', |
121
|
|
|
'object_count' => '1', |
122
|
|
|
], |
123
|
|
|
], |
124
|
|
|
$this->getDatabaseHandler()->createSelectQuery() |
125
|
|
|
->select('word', 'object_count') |
126
|
|
|
->from('ezsearch_word') |
127
|
|
|
->where('word in (\'eei\', \'eeI\')') |
128
|
|
|
); |
129
|
|
|
|
130
|
|
|
// Assert the object-word-link entries where created - this does not happen correctly pre-EZP-30481 |
131
|
|
|
self::assertQueryResult( |
132
|
|
|
[ |
133
|
|
|
[ |
134
|
|
|
'word' => 'eei', |
135
|
|
|
'count' => '1', |
136
|
|
|
], |
137
|
|
|
[ |
138
|
|
|
'word' => 'eeI', |
139
|
|
|
'count' => '3', |
140
|
|
|
], |
141
|
|
|
], |
142
|
|
|
$this->getDatabaseHandler()->createSelectQuery() |
143
|
|
|
->select('ezsearch_word.word', 'COUNT(ezsearch_word.id) as count') |
144
|
|
|
->from('ezsearch_word, ezsearch_object_word_link') |
145
|
|
|
->where('ezsearch_word.id = ezsearch_object_word_link.word_id AND ezsearch_word.word in (\'eei\', \'eeI\') GROUP BY ezsearch_word.id') |
146
|
|
|
); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|