Skip to content

Commit

Permalink
Testing that richtext conversion logs warnings correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
vidarl committed Jun 21, 2018
1 parent 2c5efc1 commit faca7a5
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 3 deletions.
48 changes: 45 additions & 3 deletions tests/lib/FieldType/Converter/RichTextTest.php
Expand Up @@ -17,6 +17,7 @@
use eZ\Publish\API\Repository\LocationService;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\API\Repository\Values\Content\Location;
use Psr\Log\NullLogger;

class RichTextTest extends TestCase
{
Expand Down Expand Up @@ -54,8 +55,12 @@ public function providerForTestConvert()
foreach (glob(__DIR__ . '/_fixtures/richtext/input/*.xml') as $inputFilePath) {
$basename = basename($inputFilePath, '.xml');
$outputFilePath = __DIR__ . "/_fixtures/richtext/output/{$basename}.xml";
$logFilePath = __DIR__ . "/_fixtures/richtext/log/{$basename}.log";
if (!file_exists($logFilePath)) {
$logFilePath = null;
}

$map[] = [$inputFilePath, $outputFilePath];
$map[] = [$inputFilePath, $outputFilePath, $logFilePath];
}

return $map;
Expand Down Expand Up @@ -123,18 +128,55 @@ private function createApiRepositoryStub()
return $apiRepositoryStub;
}

private function createLoggerStub($logFilePath)
{
$loggerStub = $this->createMock(NullLogger::class);

if ($logFilePath !== null) {
$log = file_get_contents($logFilePath);
$logLines = explode("\n", $log);
$logNo = 0;
foreach ($logLines as $expectedLogLine) {
if ($expectedLogLine === '') {
continue;
}
if (strpos($expectedLogLine, '*') !== false) {
$loggerStub->expects($this->at($logNo++))
->method('warning')
->with($this->callback(function ($logMessage) use ($expectedLogLine) {
$expectedLogMessage = substr($expectedLogLine, 0, strpos($expectedLogLine, '*'));

$this->assertEquals($expectedLogMessage, substr($logMessage, 0, strlen($expectedLogMessage)), 'Actual log message do not match the expected one');

return true;
}));
} else {
$loggerStub->expects($this->at($logNo++))
->method('warning')
->with($expectedLogLine);
}
}
} else {
$loggerStub->expects($this->never())
->method('warning');
}

return $loggerStub;
}

/**
* @param string $inputFilePath
* @param string $outputFilePath
*
* @dataProvider providerForTestConvert
*/
public function testConvert($inputFilePath, $outputFilePath)
public function testConvert($inputFilePath, $outputFilePath, $logFilePath)
{
$apiRepositoryStub = $this->createApiRepositoryStub();
$loggerStub = $this->createLoggerStub($logFilePath);

$inputDocument = $this->createDocument($inputFilePath);
$richText = new RichText($apiRepositoryStub);
$richText = new RichText($apiRepositoryStub, $loggerStub);
$richText->setImageContentTypes([27]);

$result = $richText->convert($inputDocument, true, true);
Expand Down
@@ -0,0 +1,2 @@
Duplicated id in original ezxmltext for contentobject_attribute.id=[unknown], automatically generated new id : inv5 --> duplicated_id_inv5_*
Duplicated id in original ezxmltext for contentobject_attribute.id=[unknown], automatically generated new id : inv5 --> duplicated_id_inv5_*
@@ -0,0 +1 @@
Duplicated id in original ezxmltext for contentobject_attribute.id=[unknown], automatically generated new id : myembed_id --> duplicated_id_myembed_id_idm*
@@ -0,0 +1 @@
Duplicated id in original ezxmltext for contentobject_attribute.id=[unknown], automatically generated new id : anchor --> duplicated_id_anchor_idm*
@@ -0,0 +1,6 @@
Replaced non-validating id value in richtext for contentobject_attribute.id=[unknown], changed from : 1name --> rewrite_1name
Replaced non-validating id value in richtext for contentobject_attribute.id=[unknown], changed from : -1name --> rewrite_-1name
Replaced non-validating id value in richtext for contentobject_attribute.id=[unknown], changed from : #aname --> rewrite__aname
Replaced non-validating id value in richtext for contentobject_attribute.id=[unknown], changed from : a@name --> rewrite_a_name
Replaced non-validating id value in richtext for contentobject_attribute.id=[unknown], changed from : an£ame --> rewrite_an__ame
Replaced non-validating id value in richtext for contentobject_attribute.id=[unknown], changed from : aname[ --> rewrite_aname_
@@ -0,0 +1 @@
Warning: ezxmltext for contentobject_attribute.id=contains embed or embed-inline tag(s) without node_id or object_id
@@ -0,0 +1 @@
Warning: ezxmltext for contentobject_attribute.id=contains embed or embed-inline tag(s) without node_id or object_id

0 comments on commit faca7a5

Please sign in to comment.