Commit 78e14d73 authored by catch's avatar catch
Browse files

Issue #3128905 by jungle, longwave, Kristen Pol, mondrake: Replace assert*...

Issue #3128905 by jungle, longwave, Kristen Pol, mondrake: Replace assert* involving an instanceof operator with assertInstanceOf()/assertNotInstanceOf()

(cherry picked from commit 4fe0b034)
parent a6e1bd14
...@@ -61,7 +61,7 @@ public function testActions() { ...@@ -61,7 +61,7 @@ public function testActions() {
protected function assertEntity($id, $label, $type, $configuration) { protected function assertEntity($id, $label, $type, $configuration) {
$action = Action::load($id); $action = Action::load($id);
$this->assertTrue($action instanceof Action); $this->assertInstanceOf(Action::class, $action);
/** @var \Drupal\system\Entity\Action $action */ /** @var \Drupal\system\Entity\Action $action */
$this->assertIdentical($id, $action->id()); $this->assertIdentical($id, $action->id());
$this->assertIdentical($label, $action->label()); $this->assertIdentical($label, $action->label());
......
...@@ -61,7 +61,7 @@ public function testActions() { ...@@ -61,7 +61,7 @@ public function testActions() {
protected function assertEntity($id, $label, $type, $configuration) { protected function assertEntity($id, $label, $type, $configuration) {
$action = Action::load($id); $action = Action::load($id);
$this->assertTrue($action instanceof Action); $this->assertInstanceOf(Action::class, $action);
/** @var \Drupal\system\Entity\Action $action */ /** @var \Drupal\system\Entity\Action $action */
$this->assertIdentical($id, $action->id()); $this->assertIdentical($id, $action->id());
$this->assertIdentical($label, $action->label()); $this->assertIdentical($label, $action->label());
......
...@@ -42,7 +42,7 @@ protected function setUp(): void { ...@@ -42,7 +42,7 @@ protected function setUp(): void {
* Tests CRUD operations. * Tests CRUD operations.
*/ */
public function testBlockCRUD() { public function testBlockCRUD() {
$this->assertTrue($this->controller instanceof ConfigEntityStorage, 'The block storage is loaded.'); $this->assertInstanceOf(ConfigEntityStorage::class, $this->controller, 'The block storage is loaded.');
// Run each test method in the same installation. // Run each test method in the same installation.
$this->createTests(); $this->createTests();
...@@ -73,7 +73,7 @@ protected function createTests() { ...@@ -73,7 +73,7 @@ protected function createTests() {
]); ]);
$entity->save(); $entity->save();
$this->assertTrue($entity instanceof Block, 'The newly created entity is a Block.'); $this->assertInstanceOf(Block::class, $entity, 'The newly created entity is a Block.');
// Verify all of the block properties. // Verify all of the block properties.
$actual_properties = $this->config('block.block.test_block')->get(); $actual_properties = $this->config('block.block.test_block')->get();
...@@ -102,7 +102,7 @@ protected function createTests() { ...@@ -102,7 +102,7 @@ protected function createTests() {
$this->assertIdentical($actual_properties, $expected_properties); $this->assertIdentical($actual_properties, $expected_properties);
$this->assertTrue($entity->getPlugin() instanceof TestHtmlBlock, 'The entity has an instance of the correct block plugin.'); $this->assertInstanceOf(TestHtmlBlock::class, $entity->getPlugin(), 'The entity has an instance of the correct block plugin.');
} }
/** /**
...@@ -111,7 +111,7 @@ protected function createTests() { ...@@ -111,7 +111,7 @@ protected function createTests() {
protected function loadTests() { protected function loadTests() {
$entity = $this->controller->load('test_block'); $entity = $this->controller->load('test_block');
$this->assertTrue($entity instanceof Block, 'The loaded entity is a Block.'); $this->assertInstanceOf(Block::class, $entity, 'The loaded entity is a Block.');
// Verify several properties of the block. // Verify several properties of the block.
$this->assertSame('content', $entity->getRegion()); $this->assertSame('content', $entity->getRegion());
......
...@@ -78,7 +78,7 @@ protected function setUp(): void { ...@@ -78,7 +78,7 @@ protected function setUp(): void {
*/ */
public function assertEntity($id, $visibility, $region, $theme, $weight, array $settings = NULL, $status = TRUE) { public function assertEntity($id, $visibility, $region, $theme, $weight, array $settings = NULL, $status = TRUE) {
$block = Block::load($id); $block = Block::load($id);
$this->assertTrue($block instanceof Block); $this->assertInstanceOf(Block::class, $block);
$this->assertSame($visibility, $block->getVisibility()); $this->assertSame($visibility, $block->getVisibility());
$this->assertSame($region, $block->getRegion()); $this->assertSame($region, $block->getRegion());
$this->assertSame($theme, $block->getTheme()); $this->assertSame($theme, $block->getTheme());
...@@ -303,7 +303,7 @@ public function testBlockMigration() { ...@@ -303,7 +303,7 @@ public function testBlockMigration() {
// Custom block with php code is not migrated. // Custom block with php code is not migrated.
$block = Block::load('block_3'); $block = Block::load('block_3');
$this->assertFalse($block instanceof Block); $this->assertNotInstanceOf(Block::class, $block);
} }
} }
...@@ -84,7 +84,7 @@ protected function setUp(): void { ...@@ -84,7 +84,7 @@ protected function setUp(): void {
*/ */
public function assertEntity($id, $plugin_id, array $roles, $pages, $region, $theme, $weight, $label, $label_display, $status = TRUE) { public function assertEntity($id, $plugin_id, array $roles, $pages, $region, $theme, $weight, $label, $label_display, $status = TRUE) {
$block = Block::load($id); $block = Block::load($id);
$this->assertTrue($block instanceof Block); $this->assertInstanceOf(Block::class, $block);
/** @var \Drupal\block\BlockInterface $block */ /** @var \Drupal\block\BlockInterface $block */
$this->assertSame($plugin_id, $block->getPluginId()); $this->assertSame($plugin_id, $block->getPluginId());
......
...@@ -80,7 +80,7 @@ public function testRevisions() { ...@@ -80,7 +80,7 @@ public function testRevisions() {
'@revision' => $loaded->getRevisionId(), '@revision' => $loaded->getRevisionId(),
])); ]));
if ($delta > 0) { if ($delta > 0) {
$this->assertTrue($loaded->getRevisionUser() instanceof UserInterface, 'Revision User found.'); $this->assertInstanceOf(UserInterface::class, $loaded->getRevisionUser(), 'Revision User found.');
$this->assertTrue(is_numeric($loaded->getRevisionUserId()), 'Revision User ID found.'); $this->assertTrue(is_numeric($loaded->getRevisionUserId()), 'Revision User ID found.');
$this->assertTrue(is_numeric($loaded->getRevisionCreationTime()), 'Revision time found.'); $this->assertTrue(is_numeric($loaded->getRevisionCreationTime()), 'Revision time found.');
} }
......
...@@ -36,14 +36,14 @@ protected function setUp(): void { ...@@ -36,14 +36,14 @@ protected function setUp(): void {
public function testBlockContentBodyFieldMigration() { public function testBlockContentBodyFieldMigration() {
/** @var \Drupal\field\FieldStorageConfigInterface $storage */ /** @var \Drupal\field\FieldStorageConfigInterface $storage */
$storage = FieldStorageConfig::load('block_content.body'); $storage = FieldStorageConfig::load('block_content.body');
$this->assertTrue($storage instanceof FieldStorageConfigInterface); $this->assertInstanceOf(FieldStorageConfigInterface::class, $storage);
$this->assertIdentical('block_content', $storage->getTargetEntityTypeId()); $this->assertIdentical('block_content', $storage->getTargetEntityTypeId());
$this->assertIdentical(['basic'], array_values($storage->getBundles())); $this->assertIdentical(['basic'], array_values($storage->getBundles()));
$this->assertIdentical('body', $storage->getName()); $this->assertIdentical('body', $storage->getName());
/** @var \Drupal\field\FieldConfigInterface $field */ /** @var \Drupal\field\FieldConfigInterface $field */
$field = FieldConfig::load('block_content.basic.body'); $field = FieldConfig::load('block_content.basic.body');
$this->assertTrue($field instanceof FieldConfigInterface); $this->assertInstanceOf(FieldConfigInterface::class, $field);
$this->assertIdentical('block_content', $field->getTargetEntityTypeId()); $this->assertIdentical('block_content', $field->getTargetEntityTypeId());
$this->assertIdentical('basic', $field->getTargetBundle()); $this->assertIdentical('basic', $field->getTargetBundle());
$this->assertIdentical('body', $field->getName()); $this->assertIdentical('body', $field->getName());
......
...@@ -31,7 +31,7 @@ protected function setUp(): void { ...@@ -31,7 +31,7 @@ protected function setUp(): void {
public function testBlockContentTypeMigration() { public function testBlockContentTypeMigration() {
/** @var \Drupal\block_content\BlockContentTypeInterface $entity */ /** @var \Drupal\block_content\BlockContentTypeInterface $entity */
$entity = BlockContentType::load('basic'); $entity = BlockContentType::load('basic');
$this->assertTrue($entity instanceof BlockContentTypeInterface); $this->assertInstanceOf(BlockContentTypeInterface::class, $entity);
$this->assertIdentical('Basic', $entity->label()); $this->assertIdentical('Basic', $entity->label());
} }
......
...@@ -40,7 +40,7 @@ protected function setUp(): void { ...@@ -40,7 +40,7 @@ protected function setUp(): void {
*/ */
public function testCustomBlockMigration() { public function testCustomBlockMigration() {
$block = BlockContent::load(1); $block = BlockContent::load(1);
$this->assertTrue($block instanceof BlockContentInterface); $this->assertInstanceOf(BlockContentInterface::class, $block);
/** @var \Drupal\block_content\BlockContentInterface $block */ /** @var \Drupal\block_content\BlockContentInterface $block */
$this->assertIdentical('Limerick', $block->label()); $this->assertIdentical('Limerick', $block->label());
......
...@@ -64,7 +64,7 @@ public function testSetAccessDependency($use_set_first) { ...@@ -64,7 +64,7 @@ public function testSetAccessDependency($use_set_first) {
// Calling setAccessDependency() replaces the existing dependency. // Calling setAccessDependency() replaces the existing dependency.
$testRefinable->setAccessDependency($this->neutral); $testRefinable->setAccessDependency($this->neutral);
$dependency = $testRefinable->getAccessDependency(); $dependency = $testRefinable->getAccessDependency();
$this->assertFalse($dependency instanceof AccessGroupAnd); $this->assertNotInstanceOf(AccessGroupAnd::class, $dependency);
$accessResult = $dependency->access('view', $this->account, TRUE); $accessResult = $dependency->access('view', $this->account, TRUE);
$this->assertTrue($accessResult->isNeutral()); $this->assertTrue($accessResult->isNeutral());
$this->assertEquals('I have no opinion', $accessResult->getReason()); $this->assertEquals('I have no opinion', $accessResult->getReason());
...@@ -92,7 +92,7 @@ public function testMergeNonGroup($use_set_first) { ...@@ -92,7 +92,7 @@ public function testMergeNonGroup($use_set_first) {
/** @var \Drupal\block_content\Access\AccessGroupAnd $dependency */ /** @var \Drupal\block_content\Access\AccessGroupAnd $dependency */
$dependency = $testRefinable->getAccessDependency(); $dependency = $testRefinable->getAccessDependency();
// Ensure the new dependency create a new AND group when merged. // Ensure the new dependency create a new AND group when merged.
$this->assertTrue($dependency instanceof AccessGroupAnd); $this->assertInstanceOf(AccessGroupAnd::class, $dependency);
$dependencies = $dependency->getDependencies(); $dependencies = $dependency->getDependencies();
$accessResultForbidden = $dependencies[0]->access('view', $this->account, TRUE); $accessResultForbidden = $dependencies[0]->access('view', $this->account, TRUE);
$this->assertTrue($accessResultForbidden->isForbidden()); $this->assertTrue($accessResultForbidden->isForbidden());
...@@ -123,7 +123,7 @@ public function testMergeGroup($use_set_first) { ...@@ -123,7 +123,7 @@ public function testMergeGroup($use_set_first) {
$dependency = $testRefinable->getAccessDependency(); $dependency = $testRefinable->getAccessDependency();
// Ensure the new dependency is merged with the existing group. // Ensure the new dependency is merged with the existing group.
$this->assertTrue($dependency instanceof AccessGroupAnd); $this->assertInstanceOf(AccessGroupAnd::class, $dependency);
$dependencies = $dependency->getDependencies(); $dependencies = $dependency->getDependencies();
$accessResultForbidden = $dependencies[0]->access('view', $this->account, TRUE); $accessResultForbidden = $dependencies[0]->access('view', $this->account, TRUE);
$this->assertTrue($accessResultForbidden->isForbidden()); $this->assertTrue($accessResultForbidden->isForbidden());
......
...@@ -150,7 +150,7 @@ public function testExistingFormat() { ...@@ -150,7 +150,7 @@ public function testExistingFormat() {
$expected_settings = $expected_default_settings; $expected_settings = $expected_default_settings;
$expected_settings['plugins']['stylescombo']['styles'] = ''; $expected_settings['plugins']['stylescombo']['styles'] = '';
$editor = Editor::load('filtered_html'); $editor = Editor::load('filtered_html');
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists now.'); $this->assertInstanceOf(Editor::class, $editor, 'An Editor config entity exists now.');
$this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.'); $this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
// Configure the Styles plugin, and ensure the updated settings are saved. // Configure the Styles plugin, and ensure the updated settings are saved.
...@@ -161,7 +161,7 @@ public function testExistingFormat() { ...@@ -161,7 +161,7 @@ public function testExistingFormat() {
$this->drupalPostForm(NULL, $edit, t('Save configuration')); $this->drupalPostForm(NULL, $edit, t('Save configuration'));
$expected_settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.callout|Callout\n\n"; $expected_settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.callout|Callout\n\n";
$editor = Editor::load('filtered_html'); $editor = Editor::load('filtered_html');
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.'); $this->assertInstanceOf(Editor::class, $editor, 'An Editor config entity exists.');
$this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.'); $this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
// Change the buttons that appear on the toolbar (in JavaScript, this is // Change the buttons that appear on the toolbar (in JavaScript, this is
...@@ -177,7 +177,7 @@ public function testExistingFormat() { ...@@ -177,7 +177,7 @@ public function testExistingFormat() {
]; ];
$this->drupalPostForm(NULL, $edit, t('Save configuration')); $this->drupalPostForm(NULL, $edit, t('Save configuration'));
$editor = Editor::load('filtered_html'); $editor = Editor::load('filtered_html');
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.'); $this->assertInstanceOf(Editor::class, $editor, 'An Editor config entity exists.');
$this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.'); $this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
// Check that the markup we're setting for the toolbar buttons (actually in // Check that the markup we're setting for the toolbar buttons (actually in
...@@ -205,7 +205,7 @@ public function testExistingFormat() { ...@@ -205,7 +205,7 @@ public function testExistingFormat() {
$ultra_llama_mode_checkbox = $this->xpath('//input[@type="checkbox" and @name="editor[settings][plugins][llama_contextual_and_button][ultra_llama_mode]" and not(@checked)]'); $ultra_llama_mode_checkbox = $this->xpath('//input[@type="checkbox" and @name="editor[settings][plugins][llama_contextual_and_button][ultra_llama_mode]" and not(@checked)]');
$this->assertCount(1, $ultra_llama_mode_checkbox, 'The "Ultra llama mode" checkbox exists and is not checked.'); $this->assertCount(1, $ultra_llama_mode_checkbox, 'The "Ultra llama mode" checkbox exists and is not checked.');
$editor = Editor::load('filtered_html'); $editor = Editor::load('filtered_html');
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.'); $this->assertInstanceOf(Editor::class, $editor, 'An Editor config entity exists.');
$this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.'); $this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
// Finally, check the "Ultra llama mode" checkbox. // Finally, check the "Ultra llama mode" checkbox.
...@@ -219,7 +219,7 @@ public function testExistingFormat() { ...@@ -219,7 +219,7 @@ public function testExistingFormat() {
$this->assertCount(1, $ultra_llama_mode_checkbox, 'The "Ultra llama mode" checkbox exists and is checked.'); $this->assertCount(1, $ultra_llama_mode_checkbox, 'The "Ultra llama mode" checkbox exists and is checked.');
$expected_settings['plugins']['llama_contextual_and_button']['ultra_llama_mode'] = TRUE; $expected_settings['plugins']['llama_contextual_and_button']['ultra_llama_mode'] = TRUE;
$editor = Editor::load('filtered_html'); $editor = Editor::load('filtered_html');
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.'); $this->assertInstanceOf(Editor::class, $editor, 'An Editor config entity exists.');
$this->assertEqual($expected_settings, $editor->getSettings()); $this->assertEqual($expected_settings, $editor->getSettings());
$this->drupalGet('admin/config/content/formats/add'); $this->drupalGet('admin/config/content/formats/add');
...@@ -293,13 +293,13 @@ public function testNewFormat() { ...@@ -293,13 +293,13 @@ public function testNewFormat() {
// Ensure a FilterFormat object exists now. // Ensure a FilterFormat object exists now.
$filter_format = FilterFormat::load('amazing_format'); $filter_format = FilterFormat::load('amazing_format');
$this->assertTrue($filter_format instanceof FilterFormatInterface, 'A FilterFormat config entity exists now.'); $this->assertInstanceOf(FilterFormatInterface::class, $filter_format, 'A FilterFormat config entity exists now.');
// Ensure an Editor object exists now, with the proper settings. // Ensure an Editor object exists now, with the proper settings.
$expected_settings = $default_settings; $expected_settings = $default_settings;
$expected_settings['plugins']['stylescombo']['styles'] = ''; $expected_settings['plugins']['stylescombo']['styles'] = '';
$editor = Editor::load('amazing_format'); $editor = Editor::load('amazing_format');
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists now.'); $this->assertInstanceOf(Editor::class, $editor, 'An Editor config entity exists now.');
$this->assertEqual($this->castSafeStrings($expected_settings), $this->castSafeStrings($editor->getSettings()), 'The Editor config entity has the correct settings.'); $this->assertEqual($this->castSafeStrings($expected_settings), $this->castSafeStrings($editor->getSettings()), 'The Editor config entity has the correct settings.');
} }
......
...@@ -54,7 +54,7 @@ public function testCommentPreview() { ...@@ -54,7 +54,7 @@ public function testCommentPreview() {
\Drupal::state()->set('user_hooks_test_user_format_name_alter_safe', TRUE); \Drupal::state()->set('user_hooks_test_user_format_name_alter_safe', TRUE);
$this->drupalPostForm('node/' . $this->node->id(), $edit, t('Preview')); $this->drupalPostForm('node/' . $this->node->id(), $edit, t('Preview'));
$this->assertTrue($this->webUser->getDisplayName() instanceof MarkupInterface, 'Username is marked safe'); $this->assertInstanceOf(MarkupInterface::class, $this->webUser->getDisplayName(), 'Username is marked safe');
$this->assertNoEscaped('<em>' . $this->webUser->id() . '</em>'); $this->assertNoEscaped('<em>' . $this->webUser->id() . '</em>');
$this->assertRaw('<em>' . $this->webUser->id() . '</em>'); $this->assertRaw('<em>' . $this->webUser->id() . '</em>');
......
...@@ -48,8 +48,8 @@ public function testCommentItem() { ...@@ -48,8 +48,8 @@ public function testCommentItem() {
$storage = $this->container->get('entity_type.manager')->getStorage('entity_test'); $storage = $this->container->get('entity_type.manager')->getStorage('entity_test');
$storage->resetCache([$id]); $storage->resetCache([$id]);
$entity = $storage->load($id); $entity = $storage->load($id);
$this->assertTrue($entity->comment instanceof FieldItemListInterface, 'Field implements interface.'); $this->assertInstanceOf(FieldItemListInterface::class, $entity->comment, 'Field implements interface.');
$this->assertTrue($entity->comment[0] instanceof CommentItemInterface, 'Field item implements interface.'); $this->assertInstanceOf(CommentItemInterface::class, $entity->comment[0], 'Field item implements interface.');
// Test sample item generation. // Test sample item generation.
/** @var \Drupal\entity_test\Entity\EntityTest $entity */ /** @var \Drupal\entity_test\Entity\EntityTest $entity */
......
...@@ -1156,7 +1156,7 @@ protected function assertDisabledTextarea($id) { ...@@ -1156,7 +1156,7 @@ protected function assertDisabledTextarea($id) {
':id' => $id, ':id' => $id,
]); ]);
$textarea = reset($textarea); $textarea = reset($textarea);
$this->assertTrue($textarea instanceof NodeElement, new FormattableMarkup('Disabled field @id exists.', [ $this->assertInstanceOf(NodeElement::class, $textarea, new FormattableMarkup('Disabled field @id exists.', [
'@id' => $id, '@id' => $id,
])); ]));
$expected = 'This field has been disabled because you do not have sufficient permissions to edit it.'; $expected = 'This field has been disabled because you do not have sufficient permissions to edit it.';
......
...@@ -45,7 +45,7 @@ protected function setUp(): void { ...@@ -45,7 +45,7 @@ protected function setUp(): void {
protected function assertEntity($id, $expected_label, array $expected_recipients, $expected_reply, $expected_weight) { protected function assertEntity($id, $expected_label, array $expected_recipients, $expected_reply, $expected_weight) {
/** @var \Drupal\contact\ContactFormInterface $entity */ /** @var \Drupal\contact\ContactFormInterface $entity */
$entity = ContactForm::load($id); $entity = ContactForm::load($id);
$this->assertTrue($entity instanceof ContactFormInterface); $this->assertInstanceOf(ContactFormInterface::class, $entity);
$this->assertIdentical($expected_label, $entity->label()); $this->assertIdentical($expected_label, $entity->label());
$this->assertIdentical($expected_recipients, $entity->getRecipients()); $this->assertIdentical($expected_recipients, $entity->getRecipients());
$this->assertIdentical($expected_reply, $entity->getReply()); $this->assertIdentical($expected_reply, $entity->getReply());
......
...@@ -78,8 +78,8 @@ public function testDateTime() { ...@@ -78,8 +78,8 @@ public function testDateTime() {
// Verify entity has been created properly. // Verify entity has been created properly.
$id = $entity->id(); $id = $entity->id();
$entity = EntityTest::load($id); $entity = EntityTest::load($id);
$this->assertTrue($entity->field_datetime instanceof FieldItemListInterface, 'Field implements interface.'); $this->assertInstanceOf(FieldItemListInterface::class, $entity->field_datetime, 'Field implements interface.');
$this->assertTrue($entity->field_datetime[0] instanceof FieldItemInterface, 'Field item implements interface.'); $this->assertInstanceOf(FieldItemInterface::class, $entity->field_datetime[0], 'Field item implements interface.');
$this->assertEqual($entity->field_datetime->value, $value); $this->assertEqual($entity->field_datetime->value, $value);
$this->assertEqual($entity->field_datetime[0]->value, $value); $this->assertEqual($entity->field_datetime[0]->value, $value);
$this->assertEqual(DateTimeItemInterface::STORAGE_TIMEZONE, $entity->field_datetime[0]->getProperties()['value']->getDateTime()->getTimeZone()->getName()); $this->assertEqual(DateTimeItemInterface::STORAGE_TIMEZONE, $entity->field_datetime[0]->getProperties()['value']->getDateTime()->getTimeZone()->getName());
...@@ -122,8 +122,8 @@ public function testDateOnly() { ...@@ -122,8 +122,8 @@ public function testDateOnly() {
// Verify entity has been created properly. // Verify entity has been created properly.
$id = $entity->id(); $id = $entity->id();
$entity = EntityTest::load($id); $entity = EntityTest::load($id);
$this->assertTrue($entity->field_datetime instanceof FieldItemListInterface, 'Field implements interface.'); $this->assertInstanceOf(FieldItemListInterface::class, $entity->field_datetime, 'Field implements interface.');
$this->assertTrue($entity->field_datetime[0] instanceof FieldItemInterface, 'Field item implements interface.'); $this->assertInstanceOf(FieldItemInterface::class, $entity->field_datetime[0], 'Field item implements interface.');
$this->assertEqual($entity->field_datetime->value, $value); $this->assertEqual($entity->field_datetime->value, $value);
$this->assertEqual($entity->field_datetime[0]->value, $value); $this->assertEqual($entity->field_datetime[0]->value, $value);
$this->assertEquals(DateTimeItemInterface::STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); $this->assertEquals(DateTimeItemInterface::STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName());
......
...@@ -57,8 +57,8 @@ public function testBooleanItem() { ...@@ -57,8 +57,8 @@ public function testBooleanItem() {
// Verify entity has been created properly. // Verify entity has been created properly.
$id = $entity->id(); $id = $entity->id();
$entity = EntityTest::load($id); $entity = EntityTest::load($id);
$this->assertTrue($entity->field_boolean instanceof FieldItemListInterface, 'Field implements interface.'); $this->assertInstanceOf(FieldItemListInterface::class, $entity->field_boolean, 'Field implements interface.');
$this->assertTrue($entity->field_boolean[0] instanceof FieldItemInterface, 'Field item implements interface.'); $this->assertInstanceOf(FieldItemInterface::class, $entity->field_boolean[0], 'Field item implements interface.');
$this->assertEqual($entity->field_boolean->value, $value); $this->assertEqual($entity->field_boolean->value, $value);
$this->assertEqual($entity->field_boolean[0]->value, $value); $this->assertEqual($entity->field_boolean[0]->value, $value);
......
...@@ -45,7 +45,7 @@ protected function setUp(): void { ...@@ -45,7 +45,7 @@ protected function setUp(): void {
public function testBundleFieldDefinition() { public function testBundleFieldDefinition() {
$definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->entityType, $this->bundle); $definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->entityType, $this->bundle);
$this->assertTrue(isset($definitions[$this->fieldTestData->field->getName()])); $this->assertTrue(isset($definitions[$this->fieldTestData->field->getName()]));
$this->assertTrue($definitions[$this->fieldTestData->field->getName()] instanceof FieldDefinitionInterface); $this->assertInstanceOf(FieldDefinitionInterface::class, $definitions[$this->fieldTestData->field->getName()]);
// Make sure fields on other entity types are not exposed. // Make sure fields on other entity types are not exposed.
$this->assertFalse(isset($definitions[$this->fieldTestData->field_rev->getName()])); $this->assertFalse(isset($definitions[$this->fieldTestData->field_rev->getName()]));
} }
...@@ -56,7 +56,7 @@ public function testBundleFieldDefinition() { ...@@ -56,7 +56,7 @@ public function testBundleFieldDefinition() {
public function testFieldStorageDefinition() { public function testFieldStorageDefinition() {
$field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($this->entityType); $field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($this->entityType);
$this->assertTrue(isset($field_storage_definitions[$this->fieldTestData->field->getName()])); $this->assertTrue(isset($field_storage_definitions[$this->fieldTestData->field->getName()]));
$this->assertTrue($field_storage_definitions[$this->fieldTestData->field->getName()] instanceof FieldStorageDefinitionInterface); $this->assertInstanceOf(FieldStorageDefinitionInterface::class, $field_storage_definitions[$this->fieldTestData->field->getName()]);
// Make sure storages on other entity types are not exposed. // Make sure storages on other entity types are not exposed.
$this->assertFalse(isset($field_storage_definitions[$this->fieldTestData->field_rev->getName()])); $this->assertFalse(isset($field_storage_definitions[$this->fieldTestData->field_rev->getName()]));
} }
......
...@@ -54,8 +54,8 @@ public function testEmailItem() { ...@@ -54,8 +54,8 @@ public function testEmailItem() {
// Verify entity has been created properly. // Verify entity has been created properly.
$id = $entity->id(); $id = $entity->id();
$entity = EntityTest::load($id); $entity = EntityTest::load($id);
$this->assertTrue($entity->field_email instanceof FieldItemListInterface, 'Field implements interface.'); $this->assertInstanceOf(FieldItemListInterface::class, $entity->field_email, 'Field implements interface.');
$this->assertTrue($entity->field_email[0] instanceof FieldItemInterface, 'Field item implements interface.'); $this->assertInstanceOf(FieldItemInterface::class, $entity->field_email[0], 'Field item implements interface.');
$this->assertEqual($entity->field_email->value, $value); $this->assertEqual($entity->field_email->value, $value);
$this->assertEqual($entity->field_email[0]->value, $value); $this->assertEqual($entity->field_email[0]->value, $value);
......
...@@ -128,15 +128,15 @@ public function testContentEntityReferenceItem() { ...@@ -128,15 +128,15 @@ public function testContentEntityReferenceItem() {
$entity->save(); $entity->save();
$entity = EntityTest::load($entity->id()); $entity = EntityTest::load($entity->id());
$this->assertTrue($entity->field_test_taxonomy_term instanceof FieldItemListInterface, 'Field implements interface.'); $this->assertInstanceOf(FieldItemListInterface::class, $entity->field_test_taxonomy_term, 'Field implements interface.');
$this->assertTrue($entity->field_test_taxonomy_term[0] instanceof FieldItemInterface, 'Field item implements interface.'); $this->assertInstanceOf(FieldItemInterface::class, $entity->field_test_taxonomy_term[0], 'Field item implements interface.');
$this->assertEqual($entity->field_test_taxonomy_term->target_id, $tid); $this->assertEqual($entity->field_test_taxonomy_term->target_id, $tid);
$this->assertEqual($entity->field_test_taxonomy_term->entity->getName(), $this->term->getName()); $this->assertEqual($entity->field_test_taxonomy_term->entity->getName(), $this->term->getName());
$this->assertEqual($entity->field_test_taxonomy_term->entity->id(), $tid); $this->assertEqual($entity->field_test_taxonomy_term->entity->id(), $tid);
$this->assertEqual($entity->field_test_taxonomy_term->entity->uuid(), $this->term->uuid()); $this->assertEqual($entity->field_test_taxonomy_term->entity->uuid(), $this->term->uuid());
// Verify that the label for the target ID property definition is correct. // Verify that the label for the target ID property definition is correct.
$label = $entity->field_test_taxonomy_term->getFieldDefinition()->getFieldStorageDefinition()->getPropertyDefinition('target_id')->getLabel(); $label = $entity->field_test_taxonomy_term->getFieldDefinition()->getFieldStorageDefinition()->getPropertyDefinition('target_id')->getLabel();
$this->assertTrue($label instanceof TranslatableMarkup); $this->assertInstanceOf(TranslatableMarkup::class, $label);
$this->assertEqual($label->render(), 'Taxonomy term ID'); $this->assertEqual($label->render(), 'Taxonomy term ID');
// Change the name of the term via the reference. // Change the name of the term via the reference.
...@@ -247,7 +247,7 @@ public function testContentEntityReferenceItemWithStringId() { ...@@ -247,7 +247,7 @@ public function testContentEntityReferenceItemWithStringId() {
$this->assertEqual($this->entityStringId->id(), $storage->load($entity->id())->field_test_entity_test_string_id->target_id); $this->assertEqual($this->entityStringId->id(), $storage->load($entity->id())->field_test_entity_test_string_id->target_id);
// Verify that the label for the target ID property definition is correct. // Verify that the label for the target ID property definition is correct.
$label = $entity->field_test_taxonomy_term->getFieldDefinition()->getFieldStorageDefinition()->getPropertyDefinition('target_id')->getLabel(); $label = $entity->field_test_taxonomy_term->getFieldDefinition()->getFieldStorageDefinition()->getPropertyDefinition('target_id')->getLabel();
$this->assertTrue($label instanceof TranslatableMarkup); $this->assertInstanceOf(TranslatableMarkup::class, $label);
$this->assertEqual($label->render(), 'Taxonomy term ID'); $this->assertEqual($label->render(), 'Taxonomy term ID');
} }
...@@ -264,8 +264,8 @@ public function testConfigEntityReferenceItem() { ...@@ -264,8 +264,8 @@ public function testConfigEntityReferenceItem() {
$entity->save(); $entity->save();
$entity = EntityTest::load($entity->id());