TextDataTypeTest.php in Typed Data API enhancements 8
File
tests/src/Kernel/TextDataTypeTest.php
View source
<?php
namespace Drupal\Tests\typed_data\Kernel;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\TypedData\Type\StringInterface;
use Drupal\Core\TypedData\TypedDataInterface;
use Drupal\KernelTests\KernelTestBase;
class TextDataTypeTest extends KernelTestBase {
protected static $modules = [
'system',
'typed_data',
];
public function testTextDatatype() {
$value = $this
->randomString() . "\r\n" . $this
->randomString();
$definition = DataDefinition::create('text');
$typed_data = $this->container
->get('typed_data_manager')
->create($definition, $value, 'some_text_name');
$this
->assertInstanceOf(TypedDataInterface::class, $typed_data, 'Typed Data object is an instance of the typed data interface.');
$this
->assertInstanceOf(StringInterface::class, $typed_data, 'Typed Data object is an instance of StringInterface).');
$this
->assertSame($value, $typed_data
->getValue(), 'Text value was fetched.');
$this
->assertEquals(0, $typed_data
->validate()
->count());
$new_value = $this
->randomString() . "\r\n" . $this
->randomString();
$typed_data
->setValue($new_value);
$this
->assertSame($new_value, $typed_data
->getValue(), 'Text value was changed.');
$this
->assertEquals(0, $typed_data
->validate()
->count());
}
}