Skip to content

Commit

Permalink
Add reproducer test to avoid sideffects to other documents
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Jun 7, 2024
1 parent 91b7287 commit 7321386
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Document/Index/ArticleIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public function replaceWithGhostData(ArticleDocument $document, string $locale):
$search = $repository->createSearch();
$search->addQuery(new TermQuery('localization_state.state', 'ghost'), BoolQuery::MUST);
$search->addQuery(new TermQuery('localization_state.locale', $locale), BoolQuery::MUST);
$search->addQuery(new TermQuery('locale', $locale), BoolQuery::MUST_NOT);
// $search->addQuery(new TermQuery('locale', $locale), BoolQuery::MUST_NOT);
$search->addQuery(new TermQuery('uuid', $document->getUuid()), BoolQuery::MUST);

/** @var array<array{locale: string}> $searchResult */
Expand Down
73 changes: 69 additions & 4 deletions Tests/Functional/Document/Index/ArticleIndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,32 @@ public function testReplaceWithGhostData()
'default_with_route'
);

$otherArticle = $this->createArticle(
[
'article' => 'Other content',
],
'Other Article',
'default_with_route'
);

$articleDocumentUuid = $article['id'];

$documentDE = $this->findViewDocument($articleDocumentUuid, 'de');
$documentEN = $this->findViewDocument($articleDocumentUuid, 'en');
$documentFR = $this->findViewDocument($articleDocumentUuid, 'fr');

$this->assertSame('Test Article', $documentEN->getTitle());
$this->assertSame('localized', $documentEN->getLocalizationState()->state);
$this->assertNull($documentEN->getLocalizationState()->locale);

$this->assertSame('Test Article', $documentDE->getTitle());
$this->assertSame('ghost', $documentDE->getLocalizationState()->state);
$this->assertSame('en', $documentDE->getLocalizationState()->locale);

$this->assertSame('Test Article', $documentFR->getTitle());
$this->assertSame('ghost', $documentFR->getLocalizationState()->state);
$this->assertSame('en', $documentFR->getLocalizationState()->locale);

$secondLocale = 'de';

// now add second locale
Expand All @@ -134,20 +160,59 @@ public function testReplaceWithGhostData()
'Test Artikel Deutsch',
'default_with_route'
);
$this->updateArticle(
$otherArticle['id'],
$secondLocale,
[
'id' => $otherArticle['id'],
'article' => 'Anderer Inhalt',
],
'Anderer Artikel Deutsch',
'default_with_route'
);

/** @var ArticleDocument $articleDocument */
$articleDocument = $this->documentManager->find($article['id']);
$this->indexer->replaceWithGhostData($articleDocument, 'de');
$this->indexer->flush();
$otherDocument = $this->documentManager->find($otherArticle['id']);

// instead of calling replaceWithGhostData directly we go through the document manager to reproduce: https://github.com/sulu/SuluArticleBundle/pull/677 correctly
$this->documentManager->removeLocale($articleDocument, 'de');
$this->documentManager->removeLocale($otherDocument, 'en');

$this->documentManager->flush();

$documentDE = $this->findViewDocument($articleDocument->getUuid(), 'de');
$documentEN = $this->findViewDocument($articleDocument->getUuid(), 'en');
$documentDE = $this->findViewDocument($articleDocument->getUuid(), 'de');
$documentFR = $this->findViewDocument($articleDocument->getUuid(), 'fr');

$this->assertSame('Test Article', $documentEN->getTitle());
$this->assertSame('localized', $documentEN->getLocalizationState()->state);
$this->assertNull($documentEN->getLocalizationState()->locale);

$this->assertSame('Test Article', $documentDE->getTitle());
$this->assertSame('ghost', $documentDE->getLocalizationState()->state);
$this->assertSame('en', $documentDE->getLocalizationState()->locale);

$this->assertSame('Test Article', $documentEN->getTitle());
$this->assertSame('Test Article', $documentFR->getTitle());
$this->assertSame('ghost', $documentFR->getLocalizationState()->state);
$this->assertSame('en', $documentFR->getLocalizationState()->locale);

/** @var ArticleDocument $otherDocument */
$otherDocumentEN = $this->findViewDocument($otherDocument->getUuid(), 'en');
$otherDocumentDE = $this->findViewDocument($otherDocument->getUuid(), 'de');
$otherDocumentFR = $this->findViewDocument($otherDocument->getUuid(), 'fr');

$this->assertSame('Anderer Artikel Deutsch', $otherDocumentDE->getTitle());
$this->assertSame('localized', $otherDocumentDE->getLocalizationState()->state);
$this->assertNull($otherDocumentDE->getLocalizationState()->locale);

$this->assertSame('Anderer Artikel Deutsch', $otherDocumentEN->getTitle());
$this->assertSame('ghost', $otherDocumentEN->getLocalizationState()->state);
$this->assertSame('de', $otherDocumentEN->getLocalizationState()->locale);

$this->assertSame('Anderer Artikel Deutsch', $otherDocumentFR->getTitle());
$this->assertSame('ghost', $otherDocumentFR->getLocalizationState()->state);
$this->assertSame('de', $otherDocumentFR->getLocalizationState()->locale);
}

public function testReplaceWithGhostDataUpdateExistingGhosts()
Expand Down

0 comments on commit 7321386

Please sign in to comment.