66 */
77namespace Ibexa \Tests \Core \Repository \Service \Mock ;
88
9+ use Ibexa \Contracts \Core \Event \ResolveUrlAliasSchemaEvent ;
910use Ibexa \Contracts \Core \Repository \Values \Content \Field ;
1011use Ibexa \Core \FieldType \TextLine \Value as TextLineValue ;
1112use Ibexa \Core \Repository \Helper \NameSchemaService ;
@@ -22,52 +23,46 @@ class NameSchemaTest extends BaseServiceMockTest
2223{
2324 public function testResolveUrlAliasSchema ()
2425 {
25- $ serviceMock = $ this ->getPartlyMockedNameSchemaService (['resolve ' ]);
26-
2726 $ content = $ this ->buildTestContentObject ();
2827 $ contentType = $ this ->buildTestContentType ();
2928
30- $ serviceMock ->expects (
31- $ this ->once ()
32- )->method (
33- 'resolve '
34- )->with (
35- '<urlalias_schema> ' ,
36- $ this ->equalTo ($ contentType ),
37- $ this ->equalTo ($ content ->fields ),
38- $ this ->equalTo ($ content ->versionInfo ->languageCodes )
39- )->will (
40- $ this ->returnValue (42 )
41- );
29+ $ serviceMock = $ this ->getMockBuilder (NameSchemaService::class)
30+ ->setConstructorArgs (
31+ [
32+ $ this ->getPersistenceMock ()->contentTypeHandler (),
33+ $ this ->getContentTypeDomainMapperMock (),
34+ $ this ->getFieldTypeRegistryMock (),
35+ $ this ->getSchemaIdentifierExtractorMock (),
36+ $ this ->getEventDispatcherMock (['field ' => '<urlalias_schema> ' ], $ content , ['<urlalias_schema> ' => 42 ]),
37+ ]
38+ )
39+ ->getMock ();
4240
4341 $ result = $ serviceMock ->resolveUrlAliasSchema ($ content , $ contentType );
4442
45- self ::assertEquals (42 , $ result );
43+ self ::assertEquals ([] , $ result );
4644 }
4745
4846 public function testResolveUrlAliasSchemaFallbackToNameSchema ()
4947 {
50- $ serviceMock = $ this ->getPartlyMockedNameSchemaService (['resolve ' ]);
51-
5248 $ content = $ this ->buildTestContentObject ();
5349 $ contentType = $ this ->buildTestContentType ('<name_schema> ' , '' );
5450
55- $ serviceMock ->expects (
56- $ this ->once ()
57- )->method (
58- 'resolve '
59- )->with (
60- '<name_schema> ' ,
61- $ this ->equalTo ($ contentType ),
62- $ this ->equalTo ($ content ->fields ),
63- $ this ->equalTo ($ content ->versionInfo ->languageCodes )
64- )->will (
65- $ this ->returnValue (42 )
66- );
51+ $ serviceMock = $ this ->getMockBuilder (NameSchemaService::class)
52+ ->setConstructorArgs (
53+ [
54+ $ this ->getPersistenceMock ()->contentTypeHandler (),
55+ $ this ->getContentTypeDomainMapperMock (),
56+ $ this ->getFieldTypeRegistryMock (),
57+ $ this ->getSchemaIdentifierExtractorMock (),
58+ $ this ->getEventDispatcherMock (['field ' => '<name_schema> ' ], $ content , ['<name_schema> ' => null ]),
59+ ]
60+ )
61+ ->getMock ();
6762
6863 $ result = $ serviceMock ->resolveUrlAliasSchema ($ content , $ contentType );
6964
70- self ::assertEquals (42 , $ result );
65+ self ::assertEquals ([] , $ result );
7166 }
7267
7368 public function testResolveNameSchema ()
@@ -176,9 +171,9 @@ public function testResolve(
176171 }
177172
178173 /**
179- * Data provider for the @see testResolve method .
174+ * Data provider for the @return array .
180175 *
181- * @return array
176+ * @see testResolve method.
182177 */
183178 public function resolveDataProvider ()
184179 {
@@ -371,6 +366,18 @@ protected function getPartlyMockedNameSchemaService(array $methods = null, array
371366 )
372367 ->getMock ();
373368 }
369+
370+ protected function getEventDispatcherMock (array $ schemaIdentifiers , Content $ content , array $ tokenValues )
371+ {
372+ $ event = new ResolveUrlAliasSchemaEvent ($ schemaIdentifiers , $ content );
373+ $ event ->setTokenValues ($ tokenValues );
374+
375+ $ eventDispatcherMock = parent ::getEventDispatcher ();
376+ $ eventDispatcherMock ->method ('dispatch ' )
377+ ->willReturn ($ event );
378+
379+ return $ eventDispatcherMock ;
380+ }
374381}
375382
376383class_alias (NameSchemaTest::class, 'eZ\Publish\Core\Repository\Tests\Service\Mock\NameSchemaTest ' );
0 commit comments