-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZP-31512: Fixed extracting Search Fields from RichText (#128)
* Added test coverage for generating RichText SearchField * Fixed extracting search index data from RichText DocBook XML * [Travis] Added job for unit tests on PHP 7.3 * [Travis] Removed empty statement from after_failure section
- Loading branch information
Showing
3 changed files
with
112 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\Tests\EzPlatformRichText\eZ\FieldType\RichText; | ||
|
||
use EzSystems\EzPlatformRichText\eZ\FieldType\RichText\SearchField; | ||
use eZ\Publish\SPI\Persistence\Content\Field; | ||
use eZ\Publish\SPI\Persistence\Content\FieldValue; | ||
use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition; | ||
use eZ\Publish\SPI\Search; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class SearchFieldTest extends TestCase | ||
{ | ||
/** @var \EzSystems\EzPlatformRichText\eZ\FieldType\RichText\SearchField */ | ||
private $searchField; | ||
|
||
public function getDataForTestGetIndexData(): array | ||
{ | ||
return [ | ||
'simple stub' => [ | ||
$this->getSimpleDocBookXml(), | ||
[ | ||
new Search\Field( | ||
'value', | ||
'Welcome to eZ Platform', | ||
new Search\FieldType\StringField() | ||
), | ||
new Search\Field( | ||
'fulltext', | ||
"\n Welcome to eZ Platform \n eZ Platform is the new generation DXP from eZ Systems. \n ", | ||
new Search\FieldType\FullTextField() | ||
), | ||
], | ||
], | ||
'empty xml' => [ | ||
$this->getEmptyXml(), | ||
[ | ||
new Search\Field( | ||
'value', | ||
'', | ||
new Search\FieldType\StringField() | ||
), | ||
new Search\Field( | ||
'fulltext', | ||
'', | ||
new Search\FieldType\FullTextField() | ||
), | ||
], | ||
], | ||
]; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->searchField = new SearchField(); | ||
} | ||
|
||
/** | ||
* @covers \EzSystems\EzPlatformRichText\eZ\FieldType\RichText\SearchField::getIndexData | ||
* | ||
* @dataProvider getDataForTestGetIndexData | ||
* | ||
* @param array $expectedSearchFields | ||
*/ | ||
public function testGetIndexData(string $docBookXml, array $expectedSearchFields): void | ||
{ | ||
$field = new Field( | ||
[ | ||
'id' => 1, | ||
'type' => 'ezrichtext', | ||
'value' => new FieldValue(['data' => $docBookXml]), | ||
] | ||
); | ||
$fieldDefinition = new FieldDefinition(); | ||
|
||
self::assertEquals( | ||
$expectedSearchFields, | ||
$this->searchField->getIndexData($field, $fieldDefinition) | ||
); | ||
} | ||
|
||
private function getSimpleDocBookXml(): string | ||
{ | ||
return <<<XML | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<section xmlns="http://docbook.org/ns/docbook" | ||
xmlns:xlink="http://www.w3.org/1999/xlink" | ||
xmlns:ezxhtml="https://ezplatform.com/xmlns/docbook/xhtml"> | ||
<title ezxhtml:level="2">Welcome to eZ Platform</title> | ||
<para><link xlink:href="ezurl://1" xlink:show="none">eZ Platform</link> is the new generation DXP from eZ Systems.</para> | ||
</section> | ||
XML; | ||
} | ||
|
||
private function getEmptyXml(): string | ||
{ | ||
return '<?xml version="1.0" encoding="UTF-8"?><section></section>'; | ||
} | ||
} |