public function PhoneInternationalItemTest::testTestItem in International Phone 8.2
Same name and namespace in other branches
- 8 tests/src/Kernel/PhoneInternationalItemTest.php \Drupal\Tests\phone_international\Kernel\PhoneInternationalItemTest::testTestItem()
- 3.x tests/src/Kernel/PhoneInternationalItemTest.php \Drupal\Tests\phone_international\Kernel\PhoneInternationalItemTest::testTestItem()
Tests using entity fields of the phone_international field type.
File
- tests/
src/ Kernel/ PhoneInternationalItemTest.php, line 29
Class
- PhoneInternationalItemTest
- Tests the new entity API for the phone_international field type.
Namespace
Drupal\Tests\phone_international\KernelCode
public function testTestItem() {
// Verify entity creation.
$entity = EntityTest::create();
$value = '+0123456789';
$entity->field_test = $value;
$entity->name->value = $this
->randomMachineName();
$entity
->save();
// Verify entity has been created properly.
$id = $entity
->id();
$entity = EntityTest::load($id);
$this
->assertTrue($entity->field_test instanceof FieldItemListInterface, 'Field implements interface.');
$this
->assertTrue($entity->field_test[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this
->assertEquals($entity->field_test->value, $value);
$this
->assertEquals($entity->field_test[0]->value, $value);
// Verify changing the field value.
$new_value = '+41' . rand(1000000, 9999999);
$entity->field_test->value = $new_value;
$this
->assertEquals($entity->field_test->value, $new_value);
// Read changed entity and assert changed values.
$entity
->save();
$entity = EntityTest::load($id);
$this
->assertEquals($entity->field_test->value, $new_value);
// Test sample item generation.
$entity = EntityTest::create();
$entity->field_test
->generateSampleItems();
$this
->entityValidateAndSave($entity);
}