Completed
Push — EZP-31460 ( fb49b1...efa331 )
by
unknown
19:23 queued 11s
created

DeleteTranslationTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
dl 0
loc 66
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 10 2
A findContent() 0 15 1
A testDeleteContentTranslation() 0 25 1
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\Query;
14
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
15
use eZ\Publish\API\Repository\Values\Content\Search\SearchResult;
16
17
/**
18
 * Test case for delete content translation with the SearchService.
19
 *
20
 * @see \eZ\Publish\API\Repository\SearchService
21
 * @group integration
22
 * @group search
23
 */
24
final class DeleteTranslationTest extends BaseTest
25
{
26
    /**
27
     * @throws \ErrorException
28
     */
29
    public function setUp(): void
30
    {
31
        $setupFactory = $this->getSetupFactory();
32
33
        if ($setupFactory instanceof LegacyElasticsearch) {
34
            $this->markTestIncomplete('Not implemented for Elasticsearch Search Engine');
35
        }
36
37
        parent::setUp();
38
    }
39
40
    /**
41
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
42
     */
43
    protected function findContent(string $text, string $languageCode): SearchResult
44
    {
45
        $repository = $this->getRepository();
46
        $searchService = $repository->getSearchService();
47
        $query = new Query();
48
        $query->query = new Criterion\FullText($text);
49
        $query->limit = 0;
50
        $languageFilter = [
51
            'languages' => [$languageCode],
52
            'useAlwaysAvailable' => true,
53
            'excludeTranslationsFromAlwaysAvailable' => false,
54
        ];
55
56
        return $searchService->findContent($query, $languageFilter);
57
    }
58
59
    /**
60
     * @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException
61
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
62
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
63
     */
64
    public function testDeleteContentTranslation(): void
65
    {
66
        $repository = $this->getRepository();
67
        $contentService = $repository->getContentService();
68
69
        $testContent = $this->createFolder(['eng-GB' => 'Contact', 'ger-DE' => 'Kontakt'], 2);
70
        $this->createFolder(['eng-GB' => 'OtherEngContent', 'ger-DE' => 'OtherGerContent'], 2);
71
        $this->refreshSearch($repository);
72
73
        $searchResult = $this->findContent('Kontakt', 'ger-DE');
74
        $this->assertEquals(1, $searchResult->totalCount);
75
76
        $contentService->deleteTranslation($testContent->contentInfo, 'ger-DE');
77
        $this->refreshSearch($repository);
78
        $searchResult = $this->findContent('Kontakt', 'ger-DE');
79
        $this->assertEquals(
80
            0,
81
            $searchResult->totalCount,
82
            'Found reference to the deleted Content translation'
83
        );
84
85
        // check if unrelated items were not affected
86
        $searchResult = $this->findContent('OtherGerContent', 'ger-DE');
87
        $this->assertEquals(1, $searchResult->totalCount, 'Unrelated translation was deleted');
88
    }
89
}
90