BlockFieldSelectionTest.php in Block field 8
File
tests/src/Kernel/BlockFieldSelectionTest.php
View source
<?php
namespace Drupal\Tests\block_field\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Core\StringTranslation\TranslationInterface;
class BlockFieldSelectionTest extends KernelTestBase {
public static $modules = [
'block',
'system',
'block_field',
'locale',
];
protected function setUpSelectionInstance($plugin_id = 'blocks', array $settings = []) {
return $this->container
->get('plugin.manager.block_field_selection')
->createInstance($plugin_id, $settings);
}
public function testIsSerializable() {
$plugin = $this
->setUpSelectionInstance('categories', [
'categories' => [
'core',
],
]);
$translation = $this
->prophesize(TranslationInterface::class);
$translation
->willImplement(\Serializable::class);
$translation
->serialize()
->willThrow(\Exception::class);
$translation_service = $translation
->reveal();
$translation_service->_serviceId = 'string_translation';
$plugin
->setStringTranslation($translation_service);
$string = serialize($plugin);
$object = unserialize($string);
$this
->assertEquals('categories', $object
->getPluginId());
$plugin = $this
->setUpSelectionInstance('blocks', [
'plugin_ids' => [
'system_powered_by_block',
'page_title_block',
],
]);
$plugin
->setStringTranslation($translation_service);
$string = serialize($plugin);
$object = unserialize($string);
$this
->assertEquals('blocks', $object
->getPluginId());
}
}