1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace eZ\Publish\API\Repository\Tests\SearchService; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Tests\BaseTest; |
12
|
|
|
use eZ\Publish\API\Repository\Tests\SetupFactory\LegacyElasticsearch; |
13
|
|
|
use eZ\Publish\API\Repository\Values\Content\Content; |
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query; |
15
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query\Criterion; |
16
|
|
|
use eZ\Publish\API\Repository\Values\Content\Search\SearchResult; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Test case for delete content translation with the SearchService. |
20
|
|
|
* |
21
|
|
|
* @see \eZ\Publish\API\Repository\SearchService |
22
|
|
|
* @group integration |
23
|
|
|
* @group search |
24
|
|
|
*/ |
25
|
|
|
class DeleteTranslationTest extends BaseTest |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @throws \ErrorException |
29
|
|
|
*/ |
30
|
|
|
public function setUp(): void |
31
|
|
|
{ |
32
|
|
|
$setupFactory = $this->getSetupFactory(); |
33
|
|
|
|
34
|
|
|
if ($setupFactory instanceof LegacyElasticsearch) { |
35
|
|
|
$this->markTestIncomplete('Not implemented for Elasticsearch Search Engine'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
parent::setUp(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param array $languages |
43
|
|
|
* |
44
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException |
45
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
46
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
47
|
|
|
*/ |
48
|
|
|
protected function createTestContentWithLanguages(array $languages): Content |
49
|
|
|
{ |
50
|
|
|
$repository = $this->getRepository(); |
51
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
52
|
|
|
$contentService = $repository->getContentService(); |
53
|
|
|
$locationService = $repository->getLocationService(); |
54
|
|
|
|
55
|
|
|
$contentTypeArticle = $contentTypeService->loadContentTypeByIdentifier('article'); |
56
|
|
|
$contentCreateStructArticle = $contentService->newContentCreateStruct( |
57
|
|
|
$contentTypeArticle, |
58
|
|
|
'eng-GB' |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
foreach ($languages as $langCode => $title) { |
62
|
|
|
$contentCreateStructArticle->setField('title', $title, $langCode); |
63
|
|
|
$contentCreateStructArticle->setField( |
64
|
|
|
'intro', |
65
|
|
|
'<?xml version="1.0" encoding="UTF-8"?> |
66
|
|
|
<section xmlns="http://docbook.org/ns/docbook" version="5.0-variant ezpublish-1.0"> |
67
|
|
|
<para>' . $title . '</para> |
68
|
|
|
</section>', |
69
|
|
|
$langCode |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$locationCreateStructArticle = $locationService->newLocationCreateStruct(2); |
74
|
|
|
$draftArticle = $contentService->createContent( |
75
|
|
|
$contentCreateStructArticle, |
76
|
|
|
[$locationCreateStructArticle] |
77
|
|
|
); |
78
|
|
|
$content = $contentService->publishVersion($draftArticle->getVersionInfo()); |
79
|
|
|
$this->refreshSearch($repository); |
80
|
|
|
|
81
|
|
|
return $content; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
86
|
|
|
*/ |
87
|
|
|
protected function findContent(string $text, string $languageCode): SearchResult |
88
|
|
|
{ |
89
|
|
|
$repository = $this->getRepository(); |
90
|
|
|
$searchService = $repository->getSearchService(); |
91
|
|
|
$query = new Query(); |
92
|
|
|
$query->query = new Criterion\FullText($text); |
93
|
|
|
$query->limit = 0; |
94
|
|
|
$languageFilter = [ |
95
|
|
|
'languages' => [$languageCode], |
96
|
|
|
'useAlwaysAvailable' => true, |
97
|
|
|
'excludeTranslationsFromAlwaysAvailable' => false, |
98
|
|
|
]; |
99
|
|
|
|
100
|
|
|
return $searchService->findContent($query, $languageFilter); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException |
105
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
106
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
107
|
|
|
*/ |
108
|
|
|
public function testDeleteContentTranslation(): void |
109
|
|
|
{ |
110
|
|
|
$repository = $this->getRepository(); |
111
|
|
|
$testContent = $this->createTestContentWithLanguages( |
112
|
|
|
[ |
113
|
|
|
'eng-GB' => 'Contact', |
114
|
|
|
'ger-DE' => 'Kontakt', |
115
|
|
|
] |
116
|
|
|
); |
117
|
|
|
$contentService = $repository->getContentService(); |
118
|
|
|
$searchResult = $this->findContent('Kontakt', 'ger-DE'); |
119
|
|
|
$this->assertEquals(1, $searchResult->totalCount); |
120
|
|
|
|
121
|
|
|
$contentService->deleteTranslation($testContent->contentInfo, 'ger-DE'); |
122
|
|
|
$this->refreshSearch($repository); |
123
|
|
|
$searchResult = $this->findContent('Kontakt', 'ger-DE'); |
124
|
|
|
$this->assertEquals(0, $searchResult->totalCount); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|