Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Prokyonn committed Apr 19, 2021
1 parent 9f9391f commit fe8faa8
Showing 1 changed file with 72 additions and 96 deletions.
168 changes: 72 additions & 96 deletions Tests/Functional/Document/Index/ArticleIndexerTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
Expand All @@ -17,6 +15,7 @@
use Ramsey\Uuid\Uuid;
use Sulu\Bundle\ArticleBundle\Document\ArticleViewDocument;
use Sulu\Bundle\ArticleBundle\Document\Index\ArticleIndexer;
use Sulu\Bundle\MediaBundle\Content\Types\ImageMapContentType;
use Sulu\Bundle\PageBundle\Document\PageDocument;
use Sulu\Bundle\RouteBundle\Entity\RouteRepositoryInterface;
use Sulu\Bundle\TestBundle\Testing\SuluTestCase;
Expand Down Expand Up @@ -83,11 +82,11 @@ public function testIndexDefaultWithRoute()
$this->indexer->index($document);

$viewDocument = $this->findViewDocument($article['id']);
$this->assertSame($document->getUuid(), $viewDocument->getUuid());
$this->assertSame('/articles/test-article', $viewDocument->getRoutePath());
$this->assertEquals($document->getUuid(), $viewDocument->getUuid());
$this->assertEquals('/articles/test-article', $viewDocument->getRoutePath());
$this->assertInstanceOf('\DateTime', $viewDocument->getPublished());
$this->assertTrue($viewDocument->getPublishedState());
$this->assertSame('localized', $viewDocument->getLocalizationState()->state);
$this->assertEquals('localized', $viewDocument->getLocalizationState()->state);
$this->assertNull($viewDocument->getLocalizationState()->locale);
}

Expand Down Expand Up @@ -130,17 +129,17 @@ public function testIndexShadow()

$viewDocument = $this->findViewDocument($article['id'], $secondLocale);

$this->assertSame($article['id'], $viewDocument->getUuid());
$this->assertSame('/articles/test-artikel-deutsch', $viewDocument->getRoutePath());
$this->assertEquals($article['id'], $viewDocument->getUuid());
$this->assertEquals('/articles/test-artikel-deutsch', $viewDocument->getRoutePath());
$this->assertInstanceOf('\DateTime', $viewDocument->getPublished());
$this->assertTrue($viewDocument->getPublishedState());
$this->assertSame('shadow', $viewDocument->getLocalizationState()->state);
$this->assertSame($this->locale, $viewDocument->getLocalizationState()->locale);
$this->assertSame($secondLocale, $viewDocument->getLocale());
$this->assertSame('Test Article', $viewDocument->getTitle());
$this->assertEquals('shadow', $viewDocument->getLocalizationState()->state);
$this->assertEquals($this->locale, $viewDocument->getLocalizationState()->locale);
$this->assertEquals($secondLocale, $viewDocument->getLocale());
$this->assertEquals('Test Article', $viewDocument->getTitle());

$contentData = json_decode($viewDocument->getContentData(), true);
$this->assertSame($contentData['article'], 'Test content');
$this->assertEquals($contentData['article'], 'Test content');

// now update the source locale
// the shadow should be update also
Expand All @@ -156,10 +155,10 @@ public function testIndexShadow()
);

$viewDocument = $this->findViewDocument($article['id'], $secondLocale);
$this->assertSame('Test Article - CHANGED!', $viewDocument->getTitle());
$this->assertEquals('Test Article - CHANGED!', $viewDocument->getTitle());

$contentData = json_decode($viewDocument->getContentData(), true);
$this->assertSame($contentData['article'], 'Test content - CHANGED!');
$this->assertEquals($contentData['article'], 'Test content - CHANGED!');
}

public function testIndexPageTreeRoute()
Expand All @@ -180,7 +179,7 @@ public function testIndexPageTreeRoute()
$this->indexer->index($document);

$viewDocument = $this->findViewDocument($article['id']);
$this->assertSame($page->getUuid(), $viewDocument->getParentPageUuid());
$this->assertEquals($page->getUuid(), $viewDocument->getParentPageUuid());
}

public function testSetUnpublished()
Expand All @@ -199,92 +198,26 @@ public function testIndexTaggedProperties()
'pageTitle' => 'Test Page Title',
'article' => '<p>Test Article</p>',
'article_2' => '<p>should not be indexed</p>',
'blocks' => [
];

if (class_exists(ImageMapContentType::class)) {
$data['blocks'] = [
[
'type' => 'title-with-article',
'settings' => [],
'title' => 'Test Title in Block',
'article' => '<p>Test Article in Block</p>',
],
],
];

$article = $this->createArticle($data, $data['title'], 'default_with_search_tags');
$this->documentManager->clear();

$document = $this->documentManager->find($article['id'], $this->locale);
$this->indexer->index($document);
$this->indexer->flush();

$viewDocument = $this->findViewDocument($article['id']);
$contentFields = $viewDocument->getContentFields();

$this->assertSame($article['id'], $viewDocument->getUuid());
$this->assertSame($data, json_decode($viewDocument->getContentData(), true));

$this->assertCount(5, $contentFields);
$this->assertContains('Test Article Title', $contentFields);
$this->assertContains('Test Page Title', $contentFields);
$this->assertContains('Test Article', $contentFields);
$this->assertContains('Test Title in Block', $contentFields);
$this->assertContains('Test Article in Block', $contentFields);
}

public function testIndexContentData()
{
$data = [
'title' => 'Test Article',
'routePath' => '/test-article',
'pageTitle' => 'Test Page Title',
'article' => 'Test Article',
];

$article = $this->createArticle($data, $data['title'], 'default_pages');
$this->documentManager->clear();

$this->createArticlePage($article);
$this->documentManager->clear();

$document = $this->documentManager->find($article['id'], $this->locale);
$this->indexer->index($document);
$this->indexer->flush();

$viewDocument = $this->findViewDocument($article['id']);
$this->assertSame($article['id'], $viewDocument->getUuid());
$this->assertSame($data, json_decode($viewDocument->getContentData(), true));

$this->assertProxies($data, $viewDocument->getContent(), $viewDocument->getView());

$this->assertCount(1, $viewDocument->getPages());
foreach ($viewDocument->getPages() as $page) {
$this->assertProxies(
[
'title' => 'Test Article',
'routePath' => '/test-article/page-2',
'pageTitle' => 'Test-Page',
'article' => '',
],
$page->content,
$page->view
);
}
}

public function testIndexTaggedProperties(): void
{
$data = [
'title' => 'Test Article Title',
'pageTitle' => 'Test Page Title',
'article' => '<p>Test Article</p>',
'article_2' => '<p>should not be indexed</p>',
'blocks' => [
];
} else {
$data['blocks'] = [
[
'type' => 'title-with-article',
'settings' => [],
'title' => 'Test Title in Block',
'article' => '<p>Test Article in Block</p>',
],
],
];
];
}

$article = $this->createArticle($data, $data['title'], 'default_with_search_tags');
$this->documentManager->clear();
Expand All @@ -297,6 +230,7 @@ public function testIndexTaggedProperties(): void
$contentFields = $viewDocument->getContentFields();

$this->assertSame($article['id'], $viewDocument->getUuid());
$this->assertSame($data, json_decode($viewDocument->getContentData(), true));

$this->assertCount(5, $contentFields);
$this->assertContains('Test Article Title', $contentFields);
Expand Down Expand Up @@ -380,7 +314,7 @@ public function testIndexTaggedPropertiesBlocksInBlocks(): void
$viewDocument = $this->findViewDocument($article['id']);
$contentFields = $viewDocument->getContentFields();

$this->assertSame($article['id'], $viewDocument->getUuid());
$this->assertEquals($article['id'], $viewDocument->getUuid());

$this->assertCount(9, $contentFields);
$this->assertContains('Test Article', $contentFields);
Expand All @@ -394,6 +328,46 @@ public function testIndexTaggedPropertiesBlocksInBlocks(): void
$this->assertContains('Level 4 Article_2', $contentFields);
}

public function testIndexContentData()
{
$data = [
'title' => 'Test Article',
'routePath' => '/test-article',
'pageTitle' => 'Test Page Title',
'article' => 'Test Article',
];

$article = $this->createArticle($data, $data['title'], 'default_pages');
$this->documentManager->clear();

$this->createArticlePage($article);
$this->documentManager->clear();

$document = $this->documentManager->find($article['id'], $this->locale);
$this->indexer->index($document);
$this->indexer->flush();

$viewDocument = $this->findViewDocument($article['id']);
$this->assertEquals($article['id'], $viewDocument->getUuid());
$this->assertEquals($data, json_decode($viewDocument->getContentData(), true));

$this->assertProxies($data, $viewDocument->getContent(), $viewDocument->getView());

$this->assertCount(1, $viewDocument->getPages());
foreach ($viewDocument->getPages() as $page) {
$this->assertProxies(
[
'title' => 'Test Article',
'routePath' => '/test-article/page-2',
'pageTitle' => 'Test-Page',
'article' => '',
],
$page->content,
$page->view
);
}
}

private function assertProxies(array $data, $contentProxy, $viewProxy)
{
$this->assertInstanceOf(\ArrayObject::class, $contentProxy);
Expand All @@ -402,7 +376,7 @@ private function assertProxies(array $data, $contentProxy, $viewProxy)
$content = iterator_to_array($contentProxy);
$view = iterator_to_array($viewProxy);

$this->assertSame($data, $content);
$this->assertEquals($data, $content);
foreach ($data as $key => $value) {
$this->assertArrayHasKey($key, $view);
}
Expand Down Expand Up @@ -443,7 +417,8 @@ private function updateArticle(
array $data = [],
$title = 'Test Article',
$template = 'default'
) {
)
{
$requestData = $data;

if ($title) {
Expand All @@ -460,7 +435,7 @@ private function updateArticle(
$requestData
);

$this->assertSame(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());

return json_decode($this->client->getResponse()->getContent(), true);
}
Expand All @@ -478,7 +453,8 @@ private function createArticlePage(
array $data = [],
$pageTitle = 'Test-Page',
$template = 'default_pages'
) {
)
{
$this->client->jsonRequest(
'POST',
'/api/articles/' . $article['id'] . '/pages?locale=' . $this->locale . '&action=publish',
Expand Down

0 comments on commit fe8faa8

Please sign in to comment.