Skip to content

Commit 0910dd3

Browse files
authored
Add additional search tests (#154)
1 parent 7cab9cf commit 0910dd3

6 files changed

Lines changed: 274 additions & 6 deletions

File tree

Tests/Functional/Controller/SearchControllerTest.php

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,27 @@
1414
namespace Sulu\Bundle\HeadlessBundle\Tests\Functional\Controller;
1515

1616
use Sulu\Bundle\HeadlessBundle\Tests\Functional\BaseTestCase;
17+
use Sulu\Bundle\HeadlessBundle\Tests\Traits\CreateCategoryTrait;
1718
use Sulu\Bundle\HeadlessBundle\Tests\Traits\CreatePageTrait;
1819
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
1920
use Symfony\Component\HttpFoundation\Response;
2021

2122
class SearchControllerTest extends BaseTestCase
2223
{
24+
use CreateCategoryTrait;
2325
use CreatePageTrait;
2426

2527
/**
2628
* @var KernelBrowser
2729
*/
2830
private $websiteClient;
2931

32+
private static ?int $category1Id = null;
33+
private static ?int $category2Id = null;
34+
3035
public static function setUpBeforeClass(): void
3136
{
37+
self::purgeDatabase();
3238
self::initPhpcr();
3339

3440
$searchManager = self::getContainer()->get('massive_search.search_manager');
@@ -37,12 +43,34 @@ public static function setUpBeforeClass(): void
3743
}
3844
$searchManager->flush();
3945

46+
$entityManager = self::getEntityManager();
47+
$connection = $entityManager->getConnection();
48+
$connection->executeStatement('ALTER TABLE ca_categories AUTO_INCREMENT = 1');
49+
$connection->executeStatement('ALTER TABLE ta_tags AUTO_INCREMENT = 1');
50+
$entityManager->clear();
51+
52+
$category1 = self::createCategory(['name' => 'Technology', 'key' => 'technology']);
53+
$category2 = self::createCategory(['name' => 'Development', 'key' => 'development']);
54+
$entityManager = self::getEntityManager();
55+
$entityManager->flush();
56+
self::$category1Id = $category1->getId();
57+
self::$category2Id = $category2->getId();
58+
59+
$tagRepository = self::getContainer()->get('sulu.repository.tag');
60+
$tag1 = $tagRepository->createNew();
61+
$tag1->setName('cms');
62+
$entityManager->persist($tag1);
63+
$tag2 = $tagRepository->createNew();
64+
$tag2->setName('php');
65+
$entityManager->persist($tag2);
66+
$entityManager->flush();
67+
4068
self::createPage(
4169
[
4270
'title' => 'Sulu is awesome',
4371
'url' => '/awesome-sulu',
4472
]
45-
)->getUuid();
73+
);
4674

4775
self::createPage(
4876
[
@@ -51,6 +79,37 @@ public static function setUpBeforeClass(): void
5179
]
5280
);
5381

82+
self::createPage([
83+
'title' => 'Content Management Systems',
84+
'url' => '/content-management',
85+
'excerpt' => [
86+
'title' => 'CMS Guide',
87+
'description' => 'Guide about content management',
88+
'categories' => [self::$category1Id, self::$category2Id],
89+
],
90+
]);
91+
92+
self::createPage([
93+
'title' => 'Web Development Guide',
94+
'url' => '/web-development',
95+
'excerpt' => [
96+
'title' => 'Development Resources',
97+
'description' => 'Resources for developers',
98+
'tags' => [$tag1->getName(), $tag2->getName()],
99+
],
100+
]);
101+
102+
self::createPage([
103+
'title' => 'PHP CMS Tutorial',
104+
'url' => '/php-cms-tutorial',
105+
'excerpt' => [
106+
'title' => 'Complete Tutorial',
107+
'description' => 'Learn to build a CMS',
108+
'categories' => [self::$category1Id],
109+
'tags' => [$tag1->getName()],
110+
],
111+
]);
112+
54113
static::ensureKernelShutdown();
55114
}
56115

@@ -75,6 +134,24 @@ public static function provideAttributes(): \Generator
75134
['page_sulu_io_published'],
76135
'search__get_awesome.json',
77136
];
137+
138+
yield 'page with categories' => [
139+
'Content Management',
140+
['page_sulu_io_published'],
141+
'search__get_content_management.json',
142+
];
143+
144+
yield 'page with tags' => [
145+
'Web Development',
146+
['page_sulu_io_published'],
147+
'search__get_web_development.json',
148+
];
149+
150+
yield 'page with categories and tags' => [
151+
'PHP CMS',
152+
['page_sulu_io_published'],
153+
'search__get_php_cms.json',
154+
];
78155
}
79156

80157
/**
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"_embedded": {
3+
"hits": [
4+
{
5+
"document": {
6+
"id": "@uuid@",
7+
"title": "Content Management Systems",
8+
"description": "",
9+
"url": "/content-management",
10+
"imageUrl": "",
11+
"locale": "de",
12+
"index": "page_sulu_io_published",
13+
"created": null,
14+
"creatorName": null,
15+
"creatorId": null,
16+
"changed": null,
17+
"changerName": null,
18+
"changerId": null,
19+
"properties": {
20+
"excerptTitle": "CMS Guide",
21+
"excerptMore": "",
22+
"excerptDescription": "Guide about content management",
23+
"excerptCategories": "|1|2|",
24+
"excerptCategories#0#key": "technology",
25+
"excerptCategories#0#translation": "Technology",
26+
"excerptCategories#0#keywords": "[]",
27+
"excerptCategories#0#created": "@string@.isDateTime()",
28+
"excerptCategories#0#changed": "@string@.isDateTime()",
29+
"excerptCategories#0#creator": "",
30+
"excerptCategories#0#creator_id": "",
31+
"excerptCategories#0#changer": "",
32+
"excerptCategories#0#changer_id": "",
33+
"excerptCategories#1#key": "development",
34+
"excerptCategories#1#translation": "Development",
35+
"excerptCategories#1#keywords": "[]",
36+
"excerptCategories#1#created": "@string@.isDateTime()",
37+
"excerptCategories#1#changed": "@string@.isDateTime()",
38+
"excerptCategories#1#creator": "",
39+
"excerptCategories#1#creator_id": "",
40+
"excerptCategories#1#changer": "",
41+
"excerptCategories#1#changer_id": "",
42+
"excerptTags": "||",
43+
"excerptIcon": "{\"ids\":[]}",
44+
"excerptImages": "{\"ids\":[]}",
45+
"title": "Content Management Systems",
46+
"webspace_key": "sulu_io",
47+
"state": "published",
48+
"published": "@string@.isDateTime()",
49+
"authored": "@string@.isDateTime()",
50+
"_structure_type": "default"
51+
}
52+
},
53+
"score": "@double@",
54+
"id": "@uuid@"
55+
}
56+
]
57+
}
58+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"_embedded": {
3+
"hits": [
4+
{
5+
"document": {
6+
"id": "@uuid@",
7+
"title": "PHP CMS Tutorial",
8+
"description": "",
9+
"url": "/php-cms-tutorial",
10+
"imageUrl": "",
11+
"locale": "de",
12+
"index": "page_sulu_io_published",
13+
"created": null,
14+
"creatorName": null,
15+
"creatorId": null,
16+
"changed": null,
17+
"changerName": null,
18+
"changerId": null,
19+
"properties": {
20+
"excerptTitle": "Complete Tutorial",
21+
"excerptMore": "",
22+
"excerptDescription": "Learn to build a CMS",
23+
"excerptCategories": "|1|",
24+
"excerptCategories#0#key": "technology",
25+
"excerptCategories#0#translation": "Technology",
26+
"excerptCategories#0#keywords": "[]",
27+
"excerptCategories#0#created": "@string@.isDateTime()",
28+
"excerptCategories#0#changed": "@string@.isDateTime()",
29+
"excerptCategories#0#creator": "",
30+
"excerptCategories#0#creator_id": "",
31+
"excerptCategories#0#changer": "",
32+
"excerptCategories#0#changer_id": "",
33+
"excerptTags": "|1|",
34+
"excerptTags#0#id": "1",
35+
"excerptTags#0#name": "cms",
36+
"excerptIcon": "{\"ids\":[]}",
37+
"excerptImages": "{\"ids\":[]}",
38+
"title": "PHP CMS Tutorial",
39+
"webspace_key": "sulu_io",
40+
"state": "published",
41+
"published": "@string@.isDateTime()",
42+
"authored": "@string@.isDateTime()",
43+
"_structure_type": "default"
44+
}
45+
},
46+
"score": "@double@",
47+
"id": "@uuid@"
48+
},
49+
{
50+
"document": {
51+
"id": "@uuid@",
52+
"title": "Web Development Guide",
53+
"description": "",
54+
"url": "/web-development",
55+
"imageUrl": "",
56+
"locale": "de",
57+
"index": "page_sulu_io_published",
58+
"created": null,
59+
"creatorName": null,
60+
"creatorId": null,
61+
"changed": null,
62+
"changerName": null,
63+
"changerId": null,
64+
"properties": {
65+
"excerptTitle": "Development Resources",
66+
"excerptMore": "",
67+
"excerptDescription": "Resources for developers",
68+
"excerptCategories": "||",
69+
"excerptTags": "|1|2|",
70+
"excerptTags#0#id": "1",
71+
"excerptTags#0#name": "cms",
72+
"excerptTags#1#id": "2",
73+
"excerptTags#1#name": "php",
74+
"excerptIcon": "{\"ids\":[]}",
75+
"excerptImages": "{\"ids\":[]}",
76+
"title": "Web Development Guide",
77+
"webspace_key": "sulu_io",
78+
"state": "published",
79+
"published": "@string@.isDateTime()",
80+
"authored": "@string@.isDateTime()",
81+
"_structure_type": "default"
82+
}
83+
},
84+
"score": "@double@",
85+
"id": "@uuid@"
86+
}
87+
]
88+
}
89+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"_embedded": {
3+
"hits": [
4+
{
5+
"document": {
6+
"id": "@uuid@",
7+
"title": "Web Development Guide",
8+
"description": "",
9+
"url": "/web-development",
10+
"imageUrl": "",
11+
"locale": "de",
12+
"index": "page_sulu_io_published",
13+
"created": null,
14+
"creatorName": null,
15+
"creatorId": null,
16+
"changed": null,
17+
"changerName": null,
18+
"changerId": null,
19+
"properties": {
20+
"excerptTitle": "Development Resources",
21+
"excerptMore": "",
22+
"excerptDescription": "Resources for developers",
23+
"excerptCategories": "||",
24+
"excerptTags": "|1|2|",
25+
"excerptTags#0#id": "1",
26+
"excerptTags#0#name": "cms",
27+
"excerptTags#1#id": "2",
28+
"excerptTags#1#name": "php",
29+
"excerptIcon": "{\"ids\":[]}",
30+
"excerptImages": "{\"ids\":[]}",
31+
"title": "Web Development Guide",
32+
"webspace_key": "sulu_io",
33+
"state": "published",
34+
"published": "@string@.isDateTime()",
35+
"authored": "@string@.isDateTime()",
36+
"_structure_type": "default"
37+
}
38+
},
39+
"score": "@double@",
40+
"id": "@uuid@"
41+
}
42+
]
43+
}
44+
}

Tests/Unit/Content/Serializer/MediaSerializerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function testSerialize(): void
9696
$apiMedia->getVersion()->willReturn(1)->shouldBeCalled();
9797
$apiMedia->getSubVersion()->willReturn(0)->shouldBeCalled();
9898

99-
$apiMediaArgument = Argument::that(function (Media $apiMedia) use ($media, $locale) {
99+
$apiMediaArgument = Argument::that(static function (Media $apiMedia) use ($media, $locale) {
100100
return $apiMedia->getEntity() === $media->reveal() && $locale === $apiMedia->getLocale();
101101
});
102102

@@ -143,7 +143,7 @@ public function testSerializeDocument(): void
143143
$apiMedia->getName()->willReturn('media-1.pdf')->shouldBeCalled();
144144
$apiMedia->getMimeType()->willReturn('application/pdf')->shouldBeCalled();
145145

146-
$apiMediaArgument = Argument::that(function (Media $apiMedia) use ($media, $locale) {
146+
$apiMediaArgument = Argument::that(static function (Media $apiMedia) use ($media, $locale) {
147147
return $apiMedia->getEntity() === $media->reveal() && $locale === $apiMedia->getLocale();
148148
});
149149

@@ -202,7 +202,7 @@ public function testSerializeWithPreviewImage(): void
202202
$previewMedia->getId()->willReturn(1)->shouldBeCalled();
203203
$media->getPreviewImage()->willReturn($previewMedia->reveal())->shouldBeCalled();
204204

205-
$apiMediaArgument = Argument::that(function (Media $apiMedia) use ($media, $locale) {
205+
$apiMediaArgument = Argument::that(static function (Media $apiMedia) use ($media, $locale) {
206206
return $apiMedia->getEntity() === $media->reveal() && $locale === $apiMedia->getLocale();
207207
});
208208

@@ -251,7 +251,7 @@ public function testSerializeWithContext(): void
251251
$apiMedia->getVersion()->willReturn(1)->shouldBeCalled();
252252
$apiMedia->getSubVersion()->willReturn(0)->shouldBeCalled();
253253

254-
$apiMediaArgument = Argument::that(function (Media $apiMedia) use ($media, $locale) {
254+
$apiMediaArgument = Argument::that(static function (Media $apiMedia) use ($media, $locale) {
255255
return $apiMedia->getEntity() === $media->reveal() && $locale === $apiMedia->getLocale();
256256
});
257257

Tests/Unit/Content/StructureResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private function prophesizeExcerpt(): ObjectProphecy
100100
$excerpt->getProperty('title')->willReturn($titleProperty->reveal());
101101

102102
$this->contentResolver->resolve(Argument::any(), $titleProperty->reveal(), Argument::cetera())->will(
103-
function ($arguments) {
103+
static function ($arguments) {
104104
return new ContentView($arguments[0]);
105105
}
106106
);

0 commit comments

Comments
 (0)