Commit 5ef1f99f authored by catch's avatar catch
Browse files

task: #3594057 Remove/replace any tests using telephone

By: smustgrave
By: dcam
By: quietone
(cherry picked from commit 7a5bc5b2)
(cherry picked from commit 514bb19b)
parent 106d0215
Loading
Loading
Loading
Loading
Loading
+20 −20
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ class FieldImportDeleteUninstallUiTest extends FieldTestBase {
   */
  protected static $modules = [
    'entity_test',
    'telephone',
    'field_test',
    'config',
    'filter',
    'datetime',
@@ -50,11 +50,11 @@ protected function setUp(): void {
   * Tests deleting field storages and fields as part of config import.
   */
  public function testImportDeleteUninstall(): void {
    // Create a telephone field.
    // Create a test_field field.
    $field_storage = FieldStorageConfig::create([
      'field_name' => 'field_tel',
      'field_name' => 'field_test_field',
      'entity_type' => 'entity_test',
      'type' => 'telephone',
      'type' => 'test_field',
    ]);
    $field_storage->save();
    FieldConfig::create([
@@ -74,15 +74,15 @@ public function testImportDeleteUninstall(): void {
      'bundle' => 'entity_test',
    ])->save();

    // Create an entity which has values for the telephone and text field.
    // Create an entity which has values for the test_field and date field.
    $entity = EntityTest::create();
    $value = '+0123456789';
    $entity->field_tel = $value;
    $value = '99';
    $entity->field_test_field = $value;
    $entity->field_date = time();
    $entity->name->value = $this->randomMachineName();
    $entity->save();

    // Delete the text field before exporting configuration so that we can test
    // Delete the date field before exporting configuration so that we can test
    // that deleted fields that are provided by modules that will be uninstalled
    // are also purged and that the UI message includes such fields.
    $date_field_storage->delete();
@@ -90,26 +90,26 @@ public function testImportDeleteUninstall(): void {
    // Verify entity has been created properly.
    $id = $entity->id();
    $entity = EntityTest::load($id);
    $this->assertEquals($value, $entity->field_tel->value);
    $this->assertEquals($value, $entity->field_tel[0]->value);
    $this->assertEquals($value, $entity->field_test_field->value);
    $this->assertEquals($value, $entity->field_test_field[0]->value);

    $active = $this->container->get('config.storage');
    $sync = $this->container->get('config.storage.sync');
    $this->copyConfig($active, $sync);

    // Stage uninstall of the Telephone module.
    // Stage uninstall of the field_test module.
    $core_extension = $this->config('core.extension')->get();
    unset($core_extension['module']['telephone']);
    unset($core_extension['module']['field_test']);
    $sync->write('core.extension', $core_extension);

    // Stage the field deletion including its dependencies.
    $sync->delete('field.storage.entity_test.field_tel');
    $sync->delete('field.field.entity_test.entity_test.field_tel');
    $sync->delete('field.storage.entity_test.field_test_field');
    $sync->delete('field.field.entity_test.entity_test.field_test_field');
    $sync->delete('core.entity_form_display.entity_test.entity_test.default');
    $this->drupalGet('admin/config/development/configuration');
    // Test that the message for one field being purged during a configuration
    // synchronization is correct.
    $this->assertSession()->pageTextContains('This synchronization will delete data from the field entity_test.field_tel.');
    $this->assertSession()->pageTextContains('This synchronization will delete data from the field entity_test.field_test_field.');

    // Stage an uninstall of the datetime module to test the message for
    // multiple fields.
@@ -117,17 +117,17 @@ public function testImportDeleteUninstall(): void {
    $sync->write('core.extension', $core_extension);

    $this->drupalGet('admin/config/development/configuration');
    $this->assertSession()->pageTextContains('This synchronization will delete data from the fields: entity_test.field_tel, entity_test.field_date.');
    $this->assertSession()->pageTextContains('This synchronization will delete data from the fields: entity_test.field_test_field, entity_test.field_date.');

    // This will purge all the data, delete the field and uninstall the
    // Telephone and Text modules.
    // field_test and Datetime modules.
    $this->submitForm([], 'Import all');
    $this->assertSession()->pageTextNotContains('Field data will be deleted by this synchronization.');
    $this->rebuildContainer();
    $this->assertFalse(\Drupal::moduleHandler()->moduleExists('telephone'));
    $this->assertNull(\Drupal::service('entity.repository')->loadEntityByUuid('field_storage_config', $field_storage->uuid()), 'The telephone field has been deleted by the configuration synchronization');
    $this->assertFalse(\Drupal::moduleHandler()->moduleExists('field_test'));
    $this->assertNull(\Drupal::service('entity.repository')->loadEntityByUuid('field_storage_config', $field_storage->uuid()), 'The field_test_field field has been deleted by the configuration synchronization');
    $deleted_storage_definitions = \Drupal::service('entity_field.deleted_fields_repository')->getFieldStorageDefinitions();
    $this->assertFalse(isset($deleted_storage_definitions[$field_storage->uuid()]), 'Telephone field has been completed removed from the system.');
    $this->assertFalse(isset($deleted_storage_definitions[$field_storage->uuid()]), 'field_test field has been completed removed from the system.');
    $this->assertFalse(isset($deleted_storage_definitions[$field_storage->uuid()]), 'Text field has been completed removed from the system.');
  }

+22 −25
Original line number Diff line number Diff line
@@ -26,9 +26,9 @@ class ReEnableModuleFieldTest extends BrowserTestBase {
  protected static $modules = [
    'field',
    'node',
    // We use telephone module instead of test_field because test_field is
    // We use link module instead of test_field because test_field is
    // hidden and does not display on the admin/modules page.
    'telephone',
    'link',
  ];

  /**
@@ -55,49 +55,46 @@ protected function setUp(): void {
   * @see field_system_info_alter()
   */
  public function testReEnabledField(): void {
    // Add a telephone field to the article content type.
    // Add a link field to the article content type.
    $field_storage = FieldStorageConfig::create([
      'field_name' => 'field_telephone',
      'field_name' => 'field_link',
      'entity_type' => 'node',
      'type' => 'telephone',
      'type' => 'link',
    ]);
    $field_storage->save();
    FieldConfig::create([
      'field_storage' => $field_storage,
      'bundle' => 'article',
      'label' => 'Telephone Number',
      'label' => 'Link',
    ])->save();

    /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
    $display_repository = \Drupal::service('entity_display.repository');
    $display_repository->getFormDisplay('node', 'article')
      ->setComponent('field_telephone', [
        'type' => 'telephone_default',
        'settings' => [
          'placeholder' => '123-456-7890',
        ],
      ->setComponent('field_link', [
        'type' => 'link_default',
      ])
      ->save();

    $display_repository->getViewDisplay('node', 'article')
      ->setComponent('field_telephone', [
        'type' => 'telephone_link',
      ->setComponent('field_link', [
        'type' => 'link',
        'weight' => 1,
      ])
      ->save();

    // Display the article node form and verify the telephone widget is present.
    // Display the article node form and verify the link widget is present.
    $this->drupalGet('node/add/article');
    $this->assertSession()->fieldValueEquals("field_telephone[0][value]", '');
    $this->assertSession()->fieldValueEquals("field_link[0][uri]", '');

    // Submit an article node with a telephone field so data exist for the
    // Submit an article node with a link field so data exist for the
    // field.
    $edit = [
      'title[0][value]' => $this->randomMachineName(),
      'field_telephone[0][value]' => "123456789",
      'field_link[0][uri]' => "https://www.example.com",
    ];
    $this->submitForm($edit, 'Save');
    $this->assertSession()->responseContains('<a href="tel:123456789">');
    $this->assertSession()->responseContains('<a href="https://www.example.com">');

    // Test that the module can't be uninstalled from the UI while there is data
    // for its fields.
@@ -107,25 +104,25 @@ public function testReEnabledField(): void {
    ]);
    $this->drupalLogin($admin_user);
    $this->drupalGet('admin/modules/uninstall');
    $this->assertSession()->pageTextContains("The Telephone number field type is used in the following field: node.field_telephone");
    $this->assertSession()->pageTextContains("The Link field type is used in the following field: node.field_link");

    // Add another telephone field to a different entity type in order to test
    // Add another link field to a different entity type in order to test
    // the message for the case when multiple fields are blocking the
    // uninstallation of a module.
    $field_storage2 = FieldStorageConfig::create([
      'field_name' => 'field_telephone_2',
      'field_name' => 'field_link_2',
      'entity_type' => 'user',
      'type' => 'telephone',
      'type' => 'link',
    ]);
    $field_storage2->save();
    FieldConfig::create([
      'field_storage' => $field_storage2,
      'bundle' => 'user',
      'label' => 'User Telephone Number',
      'label' => 'User Link',
    ])->save();

    $this->drupalGet('admin/modules/uninstall');
    $this->assertSession()->pageTextContains("The Telephone number field type is used in the following fields: node.field_telephone, user.field_telephone_2");
    $this->assertSession()->pageTextContains("The Link field type is used in the following fields: node.field_link, user.field_link_2");

    // Delete both fields.
    $field_storage->delete();
@@ -137,7 +134,7 @@ public function testReEnabledField(): void {
    $this->cronRun();
    $this->drupalGet('admin/modules/uninstall');
    $this->assertSession()->pageTextContains('Uninstall');
    $this->assertSession()->pageTextNotContains("The Telephone number field type is used in the following field: node.field_telephone");
    $this->assertSession()->pageTextNotContains("The Link field type is used in the following field: node.field_link");
    $this->assertSession()->pageTextNotContains('Fields pending deletion');
  }

+15 −15
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ class FieldImportDeleteUninstallTest extends FieldKernelTestBase {
  /**
   * {@inheritdoc}
   */
  protected static $modules = ['telephone'];
  protected static $modules = ['field_test'];

  /**
   * {@inheritdoc}
@@ -54,11 +54,11 @@ public function testImportDeleteUninstall(): void {
      'bundle' => 'entity_test',
    ])->save();

    // Create a telephone field for validation.
    // Create a test_field field for validation.
    $field_storage = FieldStorageConfig::create([
      'field_name' => 'field_test',
      'entity_type' => 'entity_test',
      'type' => 'telephone',
      'type' => 'test_field',
    ]);
    $field_storage->save();
    FieldConfig::create([
@@ -67,7 +67,7 @@ public function testImportDeleteUninstall(): void {
    ])->save();

    $entity = EntityTest::create();
    $value = '+0123456789';
    $value = '1234';
    $entity->field_test = $value;
    $entity->field_int = '99';
    $entity->name->value = $this->randomMachineName();
@@ -88,9 +88,9 @@ public function testImportDeleteUninstall(): void {
    $sync = $this->container->get('config.storage.sync');
    $this->copyConfig($active, $sync);

    // Stage uninstall of the Telephone module.
    // Stage uninstall of the field_test module.
    $core_extension = $this->config('core.extension')->get();
    unset($core_extension['module']['telephone']);
    unset($core_extension['module']['field_test']);
    $sync->write('core.extension', $core_extension);

    // Stage the field deletion.
@@ -101,13 +101,13 @@ public function testImportDeleteUninstall(): void {
    $this->assertSame(['\\Drupal\\field\\ConfigImporterFieldPurger', 'process'], $steps[0], 'The additional process configuration synchronization step has been added.');

    // This will purge all the data, delete the field and uninstall the
    // Telephone module.
    // field_test module.
    $this->configImporter()->import();

    $this->assertFalse(\Drupal::moduleHandler()->moduleExists('telephone'));
    $this->assertFalse(\Drupal::moduleHandler()->moduleExists('field_test'));
    $this->assertNull(\Drupal::service('entity.repository')->loadEntityByUuid('field_storage_config', $field_storage->uuid()), 'The test field has been deleted by the configuration synchronization');
    $deleted_storage_definitions = \Drupal::service('entity_field.deleted_fields_repository')->getFieldStorageDefinitions();
    $this->assertFalse(isset($deleted_storage_definitions[$field_storage->uuid()]), 'Telephone field has been completed removed from the system.');
    $this->assertFalse(isset($deleted_storage_definitions[$field_storage->uuid()]), 'test_field field has been completed removed from the system.');
    $this->assertTrue(isset($deleted_storage_definitions[$unrelated_field_storage->uuid()]), 'Unrelated field not purged by configuration synchronization.');
  }

@@ -115,11 +115,11 @@ public function testImportDeleteUninstall(): void {
   * Tests purging previously deleted fields and storages in config import.
   */
  public function testImportAlreadyDeletedUninstall(): void {
    // Create a telephone field for validation.
    // Create a test_field field for validation.
    $field_storage = FieldStorageConfig::create([
      'field_name' => 'field_test',
      'entity_type' => 'entity_test',
      'type' => 'telephone',
      'type' => 'test_field',
    ]);
    $field_storage->save();
    $field_storage_uuid = $field_storage->uuid();
@@ -131,7 +131,7 @@ public function testImportAlreadyDeletedUninstall(): void {
    // Create 12 entities to ensure that the purging works as expected.
    for ($i = 0; $i < 12; $i++) {
      $entity = EntityTest::create();
      $value = '+0123456789';
      $value = '1234';
      $entity->field_test = $value;
      $entity->name->value = $this->randomMachineName();
      $entity->save();
@@ -149,9 +149,9 @@ public function testImportAlreadyDeletedUninstall(): void {
    $sync = $this->container->get('config.storage.sync');
    $this->copyConfig($active, $sync);

    // Stage uninstall of the Telephone module.
    // Stage uninstall of the field_test module.
    $core_extension = $this->config('core.extension')->get();
    unset($core_extension['module']['telephone']);
    unset($core_extension['module']['field_test']);
    $sync->write('core.extension', $core_extension);

    $deleted_storage_definitions = \Drupal::service('entity_field.deleted_fields_repository')->getFieldStorageDefinitions();
@@ -161,7 +161,7 @@ public function testImportAlreadyDeletedUninstall(): void {
    $this->assertSame(['\\Drupal\\field\\ConfigImporterFieldPurger', 'process'], $steps[0], 'The additional process configuration synchronization step has been added.');

    // This will purge all the data, delete the field and uninstall the
    // Telephone module.
    // field_test module.
    $this->configImporter()->import();

    $deleted_storage_definitions = \Drupal::service('entity_field.deleted_fields_repository')->getFieldStorageDefinitions();
+0 −2
Original line number Diff line number Diff line
@@ -233,7 +233,6 @@ public function testUpdatedSite(): void {
    $assert_session->elementContains('css', '#field-test-4', 'Email');
    $assert_session->elementContains('css', '#field-test-5', 'Link');
    $assert_session->elementContains('css', '#field-test-6', 'Float');
    $assert_session->elementContains('css', '#field-test-7', 'Telephone number');
    $assert_session->elementContains('css', '#field-test-8', 'Entity reference');
    $assert_session->elementContains('css', '#field-test-9', 'File');
    $assert_session->elementContains('css', '#field-test-10', 'Image');
@@ -368,7 +367,6 @@ public function testUpdatedSite(): void {
      'syslog',
      'system',
      'taxonomy',
      'telephone',
      'text',
      'toolbar',
      'update',
+3 −3
Original line number Diff line number Diff line
@@ -83,10 +83,10 @@ protected function setUp(): void {
   */
  public function testGetGroupedDefinitions(): void {
    $this->discovery->getDefinitions()->willReturn([
      'telephone' => [
      'field_test' => [
        'category' => 'general',
        'label' => 'Telephone',
        'id' => 'telephone',
        'label' => 'field_test',
        'id' => 'field_test',
      ],
      'string' => [
        'category' => 'text',