Update
This commit is contained in:
80
tests/Feature/BlockEditEncodingTest.php
Normal file
80
tests/Feature/BlockEditEncodingTest.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Klevze\ControlPanel\Facades\ActiveLanguage;
|
||||
use cPad\Plugins\Blocks\Controllers\BlockController;
|
||||
|
||||
it('renders decoded html in the block editor form', function () {
|
||||
View::addNamespace('plugin.block', base_path('packages/klevze/Plugins/Blocks/Resources/views'));
|
||||
|
||||
$decodeHtml = function ($value) {
|
||||
$decoded = (string) $value;
|
||||
|
||||
while (true) {
|
||||
$next = html_entity_decode($decoded, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||
|
||||
if ($next === $decoded) {
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
$decoded = $next;
|
||||
}
|
||||
};
|
||||
|
||||
$defaultLanguageContent = $decodeHtml('&lt;a href=&quot;#&quot;&gt;Link&lt;/a&gt;');
|
||||
|
||||
$html = view('plugin.block::form.translation', [
|
||||
'languages' => [(object) ['iso' => 'en']],
|
||||
'attributes' => (object) [
|
||||
'en' => (object) [
|
||||
'content' => '&lt;a href=&quot;#&quot;&gt;Link&lt;/a&gt;',
|
||||
'html_code' => null,
|
||||
],
|
||||
],
|
||||
'decodeHtml' => $decodeHtml,
|
||||
'defaultLanguageContent' => $defaultLanguageContent,
|
||||
])->render();
|
||||
|
||||
expect($html)->toContain('"#"');
|
||||
expect($html)->not->toContain('&quot;#&quot;');
|
||||
});
|
||||
|
||||
it('normalizes encoded html before persisting a block', function () {
|
||||
$controller = app(BlockController::class);
|
||||
|
||||
$reflection = new ReflectionMethod($controller, 'normalizePrevodPayload');
|
||||
$reflection->setAccessible(true);
|
||||
|
||||
$normalized = $reflection->invoke($controller, [
|
||||
'en' => [
|
||||
'content' => '&lt;a href=&quot;#&quot;&gt;Link&lt;/a&gt;',
|
||||
],
|
||||
]);
|
||||
|
||||
expect($normalized['en']['content'])->toBe('<a href="#">Link</a>');
|
||||
});
|
||||
|
||||
it('renders frontend language tabs in the block editor', function () {
|
||||
View::addNamespace('plugin.block', base_path('packages/klevze/Plugins/Blocks/Resources/views'));
|
||||
|
||||
ActiveLanguage::shouldReceive('getList')
|
||||
->once()
|
||||
->with('fp')
|
||||
->andReturn(collect([
|
||||
(object) ['iso' => 'en', 'name' => 'English'],
|
||||
(object) ['iso' => 'sl', 'name' => 'Slovenian'],
|
||||
]));
|
||||
|
||||
$html = view('plugin.block::form.translation', [
|
||||
'languages' => [(object) ['iso' => 'en']],
|
||||
'attributes' => (object) [
|
||||
'en' => (object) ['content' => '', 'html_code' => null],
|
||||
],
|
||||
'decodeHtml' => fn ($value) => (string) $value,
|
||||
'defaultLanguageContent' => '',
|
||||
])->render();
|
||||
|
||||
expect($html)->toContain('nav nav-tabs');
|
||||
expect($html)->toContain('English');
|
||||
expect($html)->toContain('Slovenian');
|
||||
});
|
||||
Reference in New Issue
Block a user