You are here

public function LingotekProfileFormTest::testDeletingProfileBeingUsedInContent in Lingotek Translation 8

Test deleting profile being used in content is not deleted.

File

src/Tests/Form/LingotekProfileFormTest.php, line 158

Class

LingotekProfileFormTest
Tests the Lingotek profile form.

Namespace

Drupal\lingotek\Tests\Form

Code

public function testDeletingProfileBeingUsedInContent() {

  /** @var LingotekProfileInterface $profile */
  $profile = LingotekProfile::create([
    'id' => strtolower($this
      ->randomMachineName()),
    'label' => $this
      ->randomString(),
  ]);
  $profile
    ->save();
  $profile_id = $profile
    ->id();

  // Create Article node types.
  $this
    ->drupalCreateContentType([
    'type' => 'article',
    'name' => 'Article',
  ]);

  // Enable translation for the current entity type and ensure the change is
  // picked up.
  ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
    ->setLanguageAlterable(TRUE)
    ->save();
  \Drupal::service('content_translation.manager')
    ->setEnabled('node', 'article', TRUE);
  $edit = [
    'node[article][enabled]' => 1,
    'node[article][profiles]' => 'automatic',
    'node[article][fields][title]' => 1,
    'node[article][fields][body]' => 1,
  ];
  $this
    ->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-content-form');

  // Create a node.
  $edit = array();
  $edit['title[0][value]'] = 'Llamas are cool';
  $edit['body[0][value]'] = 'Llamas are very cool';
  $edit['langcode[0][value]'] = 'en';
  $edit['lingotek_translation_profile'] = $profile_id;
  $this
    ->drupalPostForm('node/add/article', $edit, t('Save and publish'));
  $this
    ->assertUrl('/node/1', [], 'Node has been created.');
  $this
    ->drupalGet("/admin/lingotek/settings/profile/{$profile_id}/delete");

  // Confirm the form.
  $this
    ->assertText(t('This action cannot be undone.'));
  $this
    ->drupalPostForm(NULL, [], t('Delete'));
  $this
    ->assertNoRaw(t('The lingotek profile %profile has been deleted.', [
    '%profile' => $profile
      ->label(),
  ]));
  $this
    ->assertRaw(t('The Lingotek profile %profile is being used so cannot be deleted.', [
    '%profile' => $profile
      ->label(),
  ]));

  /** @var LingotekProfileInterface $profile */
  $profile = LingotekProfile::load($profile_id);
  $this
    ->assertNotNull($profile);
}