init
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\MultiLocaleTranslation\Test\Unit\Model;
|
||||
|
||||
use Esun\MultiLocaleTranslation\Model\Html\TranslatableTextExtractor;
|
||||
use Esun\MultiLocaleTranslation\Model\TranslationLogger;
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
use Magento\Framework\DB\Adapter\AdapterInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TranslationLoggerTest extends TestCase
|
||||
{
|
||||
public function testHtmlLogContainsOnlyVisibleText(): void
|
||||
{
|
||||
$connection = $this->createMock(AdapterInterface::class);
|
||||
$connection->expects(self::once())
|
||||
->method('insertMultiple')
|
||||
->with(
|
||||
'esun_localetranslation_log',
|
||||
self::callback(static function (array $rows): bool {
|
||||
return $rows[0]['source_text'] === "Hello\nworld"
|
||||
&& $rows[0]['translated_text'] === "Bonjour\nmonde"
|
||||
&& $rows[0]['character_count'] === 11
|
||||
&& !str_contains($rows[0]['source_text'], 'display:none');
|
||||
})
|
||||
);
|
||||
|
||||
$resourceConnection = $this->createMock(ResourceConnection::class);
|
||||
$resourceConnection->method('getConnection')->willReturn($connection);
|
||||
$resourceConnection->method('getTableName')->willReturn('esun_localetranslation_log');
|
||||
|
||||
$logger = new TranslationLogger($resourceConnection, new TranslatableTextExtractor());
|
||||
$logger->logSuccess(
|
||||
'deepl',
|
||||
'cms_page',
|
||||
5,
|
||||
0,
|
||||
2,
|
||||
'EN',
|
||||
'FR',
|
||||
[
|
||||
'content' => [
|
||||
'value' => '<style>.hidden{display:none}</style><p>Hello <strong>world</strong></p>',
|
||||
'is_html' => true,
|
||||
],
|
||||
],
|
||||
[
|
||||
'content' => '<style>.hidden{display:none}</style><p>Bonjour <strong>monde</strong></p>',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user