|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the eZ Publish Kernel package. |
|
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; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Tests\Content\LanguageAwareTestCase; |
|
12
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway\DoctrineDatabase as ContentTypeGateway; |
|
13
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler as ContentTypeHandler; |
|
14
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Mapper as ContentTypeMapper; |
|
15
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter; |
|
16
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry; |
|
17
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Update\Handler as ContentTypeUpdateHandler; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Abstract test suite for legacy search. |
|
21
|
|
|
*/ |
|
22
|
|
|
class AbstractTestCase extends LanguageAwareTestCase |
|
23
|
|
|
{ |
|
24
|
|
|
private static $setup; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Field registry mock. |
|
28
|
|
|
* |
|
29
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry |
|
30
|
|
|
*/ |
|
31
|
|
|
private $converterRegistry; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var \eZ\Publish\SPI\Persistence\Content\Type\Handler |
|
35
|
|
|
*/ |
|
36
|
|
|
private $contentTypeHandler; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Only set up once for these read only tests on a large fixture. |
|
40
|
|
|
* |
|
41
|
|
|
* Skipping the reset-up, since setting up for these tests takes quite some |
|
42
|
|
|
* time, which is not required to spent, since we are only reading from the |
|
43
|
|
|
* database anyways. |
|
44
|
|
|
*/ |
|
45
|
|
|
public function setUp() |
|
46
|
|
|
{ |
|
47
|
|
|
if (!self::$setup) { |
|
48
|
|
|
parent::setUp(); |
|
49
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/../_fixtures/full_dump.php'); |
|
50
|
|
|
self::$setup = $this->handler; |
|
51
|
|
|
} else { |
|
52
|
|
|
$this->handler = self::$setup; |
|
53
|
|
|
$this->connection = $this->handler->getConnection(); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Assert that the elements are. |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function assertSearchResults($expectedIds, $searchResult) |
|
61
|
|
|
{ |
|
62
|
|
|
$ids = $this->getIds($searchResult); |
|
63
|
|
|
$this->assertEquals($expectedIds, $ids); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
protected function getIds($searchResult) |
|
67
|
|
|
{ |
|
68
|
|
|
$ids = array_map( |
|
69
|
|
|
function ($hit) { |
|
70
|
|
|
return $hit->valueObject->id; |
|
71
|
|
|
}, |
|
72
|
|
|
$searchResult->searchHits |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
sort($ids); |
|
76
|
|
|
|
|
77
|
|
|
return $ids; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
protected function getContentTypeHandler() |
|
81
|
|
|
{ |
|
82
|
|
|
if (!isset($this->contentTypeHandler)) { |
|
83
|
|
|
$this->contentTypeHandler = new ContentTypeHandler( |
|
84
|
|
|
new ContentTypeGateway( |
|
85
|
|
|
$this->getDatabaseHandler(), |
|
86
|
|
|
$this->getDatabaseConnection(), |
|
87
|
|
|
$this->getLanguageMaskGenerator() |
|
88
|
|
|
), |
|
89
|
|
|
new ContentTypeMapper($this->getConverterRegistry(), $this->getLanguageMaskGenerator()), |
|
90
|
|
|
$this->createMock(ContentTypeUpdateHandler::class) |
|
91
|
|
|
); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return $this->contentTypeHandler; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
protected function getConverterRegistry() |
|
98
|
|
|
{ |
|
99
|
|
|
if (!isset($this->converterRegistry)) { |
|
100
|
|
|
$this->converterRegistry = new ConverterRegistry( |
|
101
|
|
|
array( |
|
102
|
|
|
'ezdatetime' => new Converter\DateAndTimeConverter(), |
|
103
|
|
|
'ezinteger' => new Converter\IntegerConverter(), |
|
104
|
|
|
'ezstring' => new Converter\TextLineConverter(), |
|
105
|
|
|
'ezprice' => new Converter\IntegerConverter(), |
|
106
|
|
|
'ezurl' => new Converter\UrlConverter(), |
|
107
|
|
|
'ezrichtext' => new Converter\RichTextConverter(), |
|
108
|
|
|
'ezboolean' => new Converter\CheckboxConverter(), |
|
109
|
|
|
'ezkeyword' => new Converter\KeywordConverter(), |
|
110
|
|
|
'ezauthor' => new Converter\AuthorConverter(), |
|
111
|
|
|
'ezimage' => new Converter\NullConverter(), |
|
112
|
|
|
'ezsrrating' => new Converter\NullConverter(), |
|
113
|
|
|
'ezmultioption' => new Converter\NullConverter(), |
|
114
|
|
|
) |
|
115
|
|
|
); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
return $this->converterRegistry; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|