-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
347 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
tests/lib/Mapper/SearchHitToContentSuggestionMapperTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\Search\Mapper; | ||
|
||
use Ibexa\Contracts\Core\Persistence\Content\ContentInfo; | ||
use Ibexa\Contracts\Core\Persistence\Content\Location; | ||
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit; | ||
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; | ||
use Ibexa\Core\Repository\Values\Content\Content; | ||
use Ibexa\Core\Repository\Values\ContentType\ContentType; | ||
use Ibexa\Search\Mapper\SearchHitToContentSuggestionMapper; | ||
use Ibexa\Search\Model\Suggestion\ContentSuggestion; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class SearchHitToContentSuggestionMapperTest extends TestCase | ||
{ | ||
public function testMap(): void | ||
{ | ||
$this->markTestIncomplete('This test has not been implemented yet.'); | ||
|
||
$mapper = new SearchHitToContentSuggestionMapper( | ||
$this->getConfigResolverMock() | ||
); | ||
|
||
$result = $mapper->map( | ||
new SearchHit([ | ||
'valueObject' => new Content([ | ||
'id' => 1, | ||
'contentInfo' => new ContentInfo([ | ||
'name' => 'name', | ||
'mainLanguageCode' => 'eng-GB', | ||
'mainLocation' => new Location([ | ||
'pathString' => [1, 2, 3], | ||
]), | ||
'contentTypeId' => 1, | ||
]), | ||
'versionInfo' => new VersionInfo([ | ||
'contentInfo' => new ContentInfo([ | ||
'name' => 'name', | ||
'mainLanguageCode' => 'eng-GB', | ||
'contentTypeId' => 1, | ||
]), | ||
]), | ||
'contentType' => new ContentType([ | ||
'identifier' => 'content_type_identifier', | ||
]), | ||
]), | ||
]) | ||
); | ||
$this->assertInstanceOf(ContentSuggestion::class, $result); | ||
} | ||
|
||
private function getConfigResolverMock(): ConfigResolverInterface | ||
{ | ||
$configResolverMock = $this->createMock(ConfigResolverInterface::class); | ||
$configResolverMock->method('getParameter')->willReturn(5); | ||
|
||
return $configResolverMock; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\Search\Model\Suggestion; | ||
|
||
use Ibexa\Search\Model\Suggestion\ContentSuggestion; | ||
use Ibexa\Search\Model\Suggestion\Suggestion; | ||
use Ibexa\Tests\Core\Search\TestCase; | ||
|
||
final class ContentSuggestionTest extends TestCase | ||
{ | ||
public function testCreate(): void | ||
{ | ||
$implementation = new ContentSuggestion( | ||
1, | ||
'content_type_identifier', | ||
'name', | ||
'text', | ||
[0 => 'text'] | ||
); | ||
|
||
$this->assertInstanceOf(Suggestion::class, $implementation); | ||
$this->assertSame(1, $implementation->getContentId()); | ||
$this->assertSame('content_type_identifier', $implementation->getContentTypeIdentifier()); | ||
$this->assertSame('content', $implementation->getType()); | ||
$this->assertSame([0 => 'text'], $implementation->getParentsLocation()); | ||
|
||
$implementation->addPath(1, 'text2'); | ||
$this->assertSame([0 => 'text', 1 => 'text2'], $implementation->getParentsLocation()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\Search\Model\Suggestion; | ||
|
||
use Ibexa\Contracts\Core\Collection\MutableArrayList; | ||
use Ibexa\Search\Model\Suggestion\ContentSuggestion; | ||
use Ibexa\Search\Model\Suggestion\SuggestionCollection; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class SuggestionCollectionTest extends TestCase | ||
{ | ||
public function testCollection(): void | ||
{ | ||
$collection = new SuggestionCollection(); | ||
$this->assertInstanceOf(MutableArrayList::class, $collection); | ||
$this->assertInstanceOf(SuggestionCollection::class, $collection); | ||
|
||
$collection->append(new ContentSuggestion(1, 'article', 'test')); | ||
$collection->append(new ContentSuggestion(2, 'article', 'test2')); | ||
|
||
$this->assertCount(2, $collection); | ||
|
||
foreach ($collection as $item) { | ||
$this->assertInstanceOf(ContentSuggestion::class, $item); | ||
} | ||
|
||
$this->expectException(\TypeError::class); | ||
$collection->append(new \stdClass()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\Search\Model\Suggestion; | ||
|
||
use Ibexa\Search\Model\Suggestion\Suggestion as SuggestionAlias; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class SuggestionTest extends TestCase | ||
{ | ||
public function testSuggestionCreate(): void | ||
{ | ||
$implementation = new class('name', 'text', [0 => 'text']) extends SuggestionAlias { | ||
public function getType(): string | ||
{ | ||
return 'test_implementation'; | ||
} | ||
}; | ||
|
||
$this->assertInstanceOf(SuggestionAlias::class, $implementation); | ||
$this->assertSame('name', $implementation->getName()); | ||
$this->assertSame('text', $implementation->getPathString()); | ||
$this->assertSame([0 => 'text'], $implementation->getParentsLocation()); | ||
$this->assertSame('test_implementation', $implementation->getType()); | ||
|
||
$implementation->addPath(1, 'text2'); | ||
$this->assertSame([0 => 'text', 1 => 'text2'], $implementation->getParentsLocation()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\Search\Service\Event; | ||
|
||
use Ibexa\Contracts\Search\Event\AfterSuggestionEvent; | ||
use Ibexa\Contracts\Search\Event\BeforeSuggestionEvent; | ||
use Ibexa\Contracts\Search\Service\SuggestionServiceInterface; | ||
use Ibexa\Search\Model\Suggestion\SuggestionCollection; | ||
use Ibexa\Search\Model\SuggestionQuery; | ||
use Ibexa\Search\Service\Event\SuggestionService; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; | ||
|
||
final class SuggestionServiceTest extends TestCase | ||
{ | ||
public function testSuggestion(): void | ||
{ | ||
$eventDispatcherMock = $this->getEventDispatcherMock(); | ||
$eventDispatcherMock | ||
->method('dispatch') | ||
->withConsecutive( | ||
[ | ||
$this->isInstanceOf(BeforeSuggestionEvent::class), | ||
], | ||
[ | ||
$this->isInstanceOf(AfterSuggestionEvent::class), | ||
] | ||
) | ||
->willReturnCallback( | ||
static function ($event) { | ||
return $event; | ||
} | ||
); | ||
|
||
$innerServiceMock = $this->getSuggestionServiceMock(); | ||
$innerServiceMock | ||
->method('suggest') | ||
->willReturn(new SuggestionCollection()); | ||
|
||
$service = new SuggestionService($innerServiceMock, $eventDispatcherMock); | ||
|
||
$result = $service->suggest(new SuggestionQuery('query', 10, 'eng-GB')); | ||
self::assertInstanceOf(SuggestionCollection::class, $result); | ||
} | ||
|
||
public function testSuggestionStopPropagation(): void | ||
{ | ||
$eventDispatcherMock = $this->getEventDispatcherMock(); | ||
$eventDispatcherMock | ||
->expects(self::once()) | ||
->method('dispatch') | ||
->withConsecutive( | ||
[ | ||
$this->isInstanceOf(BeforeSuggestionEvent::class), | ||
] | ||
) | ||
->willReturnCallback( | ||
static function (BeforeSuggestionEvent $event) { | ||
$event->stopPropagation(); | ||
|
||
return $event; | ||
} | ||
); | ||
|
||
$innerServiceMock = $this->getSuggestionServiceMock(); | ||
$innerServiceMock | ||
->method('suggest') | ||
->willReturn(new SuggestionCollection()); | ||
|
||
$service = new SuggestionService($innerServiceMock, $eventDispatcherMock); | ||
|
||
$result = $service->suggest(new SuggestionQuery('query', 10, 'eng-GB')); | ||
self::assertInstanceOf(SuggestionCollection::class, $result); | ||
} | ||
|
||
private function getSuggestionServiceMock(): SuggestionServiceInterface | ||
{ | ||
$suggestionServiceMock = $this->getMockBuilder(SuggestionServiceInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
return $suggestionServiceMock; | ||
} | ||
|
||
private function getEventDispatcherMock(): EventDispatcherInterface | ||
{ | ||
$eventDispatcherMock = $this->getMockBuilder(EventDispatcherInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
return $eventDispatcherMock; | ||
} | ||
} |
Oops, something went wrong.