1414namespace Sulu \Bundle \HeadlessBundle \Tests \Functional \Controller ;
1515
1616use Sulu \Bundle \HeadlessBundle \Tests \Functional \BaseTestCase ;
17+ use Sulu \Bundle \HeadlessBundle \Tests \Traits \CreateCategoryTrait ;
1718use Sulu \Bundle \HeadlessBundle \Tests \Traits \CreatePageTrait ;
1819use Symfony \Bundle \FrameworkBundle \KernelBrowser ;
1920use Symfony \Component \HttpFoundation \Response ;
2021
2122class 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 /**
0 commit comments