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
|
|
|
/** @var \eZ\Publish\SPI\Persistence\Content\Type\Handler */ |
34
|
|
|
private $contentTypeHandler; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Only set up once for these read only tests on a large fixture. |
38
|
|
|
* |
39
|
|
|
* Skipping the reset-up, since setting up for these tests takes quite some |
40
|
|
|
* time, which is not required to spent, since we are only reading from the |
41
|
|
|
* database anyways. |
42
|
|
|
*/ |
43
|
|
|
public function setUp() |
44
|
|
|
{ |
45
|
|
|
if (!self::$setup) { |
46
|
|
|
parent::setUp(); |
47
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/../_fixtures/full_dump.php'); |
48
|
|
|
self::$setup = $this->handler; |
49
|
|
|
} else { |
50
|
|
|
$this->handler = self::$setup; |
51
|
|
|
$this->connection = $this->handler->getConnection(); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Assert that the elements are. |
57
|
|
|
*/ |
58
|
|
|
protected function assertSearchResults($expectedIds, $searchResult) |
59
|
|
|
{ |
60
|
|
|
$ids = $this->getIds($searchResult); |
61
|
|
|
$this->assertEquals($expectedIds, $ids); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
protected function getIds($searchResult) |
65
|
|
|
{ |
66
|
|
|
$ids = array_map( |
67
|
|
|
function ($hit) { |
68
|
|
|
return $hit->valueObject->id; |
69
|
|
|
}, |
70
|
|
|
$searchResult->searchHits |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
sort($ids); |
74
|
|
|
|
75
|
|
|
return $ids; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
protected function getContentTypeHandler() |
79
|
|
|
{ |
80
|
|
|
if (!isset($this->contentTypeHandler)) { |
81
|
|
|
$this->contentTypeHandler = new ContentTypeHandler( |
82
|
|
|
new ContentTypeGateway( |
83
|
|
|
$this->getDatabaseHandler(), |
84
|
|
|
$this->getDatabaseConnection(), |
85
|
|
|
$this->getLanguageMaskGenerator() |
86
|
|
|
), |
87
|
|
|
new ContentTypeMapper($this->getConverterRegistry(), $this->getLanguageMaskGenerator()), |
88
|
|
|
$this->createMock(ContentTypeUpdateHandler::class) |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return $this->contentTypeHandler; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
View Code Duplication |
protected function getConverterRegistry() |
96
|
|
|
{ |
97
|
|
|
if (!isset($this->converterRegistry)) { |
98
|
|
|
$this->converterRegistry = new ConverterRegistry( |
99
|
|
|
[ |
100
|
|
|
'ezdatetime' => new Converter\DateAndTimeConverter(), |
101
|
|
|
'ezinteger' => new Converter\IntegerConverter(), |
102
|
|
|
'ezstring' => new Converter\TextLineConverter(), |
103
|
|
|
'ezprice' => new Converter\IntegerConverter(), |
104
|
|
|
'ezurl' => new Converter\UrlConverter(), |
105
|
|
|
'ezrichtext' => new Converter\RichTextConverter(), |
106
|
|
|
'ezboolean' => new Converter\CheckboxConverter(), |
107
|
|
|
'ezkeyword' => new Converter\KeywordConverter(), |
108
|
|
|
'ezauthor' => new Converter\AuthorConverter(), |
109
|
|
|
'ezimage' => new Converter\NullConverter(), |
110
|
|
|
'ezsrrating' => new Converter\NullConverter(), |
111
|
|
|
'ezmultioption' => new Converter\NullConverter(), |
112
|
|
|
] |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return $this->converterRegistry; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|