You are here

public function LingotekNodeBulkFormTest::testDisabledLanguage in Lingotek Translation 8

Tests that the node bulk form doesn't show a language if it's disabled.

File

src/Tests/Form/LingotekNodeBulkFormTest.php, line 439

Class

LingotekNodeBulkFormTest
Tests the bulk management form.

Namespace

Drupal\lingotek\Tests\Form

Code

public function testDisabledLanguage() {

  // Create an article.
  $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'] = 'manual';
  $this
    ->drupalPostForm('node/add/article', $edit, t('Save and publish'));

  // Go and upload this node.
  $this
    ->goToContentBulkManagementForm();
  $basepath = \Drupal::request()
    ->getBasePath();

  // Clicking English must init the upload of content.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/node/1?destination=' . $basepath . '/admin/lingotek/manage/node');

  // And we cannot request yet a translation.
  $this
    ->assertNoLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/node');
  $this
    ->clickLink('EN');

  // There is a link for checking status.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/check_upload/dummy-document-hash-id?destination=' . $basepath . '/admin/lingotek/manage/node');

  // And we can already request a translation for Spanish.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/node');

  // Then we disable the Spanish language.
  $request = $this
    ->curlExec(array(
    CURLOPT_URL => \Drupal::url('lingotek.dashboard_endpoint', array(), array(
      'absolute' => TRUE,
    )),
    CURLOPT_HTTPGET => FALSE,
    CURLOPT_CUSTOMREQUEST => 'DELETE',
    CURLOPT_POSTFIELDS => $this
      ->serializePostValues([
      'code' => 'es_MX',
    ]),
    CURLOPT_HTTPHEADER => array(
      'Accept: application/json',
      'Content-Type: application/x-www-form-urlencoded',
    ),
  ));
  $response = json_decode($request, TRUE);
  $this
    ->verbose(var_export($response, TRUE));

  // And we check that Spanish is not there anymore.
  $this
    ->goToContentBulkManagementForm();
  $this
    ->assertNoLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/node');

  // We re-enable Spanish.

  /** @var LingotekConfigurationServiceInterface $lingotekConfig */
  $lingotekConfig = \Drupal::service('lingotek.configuration');
  $language = ConfigurableLanguage::load('es');
  $lingotekConfig
    ->enableLanguage($language);

  // And Spanish should be back in the management form.
  $this
    ->goToContentBulkManagementForm();
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/node');
}