View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\lingotek\Lingotek;
class LingotekContentTypeBulkCancelTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
];
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
ConfigurableLanguage::createFromLangcode('es')
->save();
$this
->saveLingotekConfigTranslationSettings([
'node_type' => 'automatic',
]);
}
public function testContentTypeCancel() {
\Drupal::state()
->set('lingotek.uploaded_content_type', 'content_type');
$this
->drupalLogin($this->rootUser);
$this
->createAndTranslateContentTypeWithLinks();
$edit = [
'table[article]' => 'article',
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCancel('node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$config_translation_service = \Drupal::service('lingotek.config_translation');
\Drupal::entityTypeManager()
->getStorage('node_type')
->resetCache();
$cancelled_docs = \Drupal::state()
->get('lingotek.cancelled_docs', []);
$this
->assertEqual(1, count($cancelled_docs), 'The document has been cancelled remotely.');
$deleted_docs = \Drupal::state()
->get('lingotek.deleted_docs', []);
$this
->assertEqual(0, count($deleted_docs), 'No document has been deleted remotely.');
\Drupal::entityTypeManager()
->getStorage('node_type')
->resetCache();
$entity = \Drupal::entityTypeManager()
->getStorage('node_type')
->load('article');
$this
->assertNull($config_translation_service
->getDocumentId($entity));
$this
->assertSourceStatus('EN', Lingotek::STATUS_CANCELLED);
$this
->assertTargetStatus('ES', Lingotek::STATUS_CANCELLED);
$this
->assertIdentical(Lingotek::STATUS_CANCELLED, $config_translation_service
->getSourceStatus($entity));
$this
->assertIdentical(Lingotek::STATUS_CANCELLED, $config_translation_service
->getTargetStatus($entity, 'es'));
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertNoLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/es_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->createAndTranslateContentTypeWithLinks();
}
public function testContentTypeCancelTarget() {
\Drupal::state()
->set('lingotek.uploaded_content_type', 'content_type');
$this
->drupalLogin($this->rootUser);
$this
->createAndTranslateContentTypeWithLinks();
$edit = [
'table[article]' => 'article',
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCancelTarget('es', 'node_type'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$config_translation_service = \Drupal::service('lingotek.config_translation');
\Drupal::entityTypeManager()
->getStorage('node_type')
->resetCache();
$cancelled_locales = \Drupal::state()
->get('lingotek.cancelled_locales', []);
$this
->assertTrue(isset($cancelled_locales['dummy-document-hash-id']) && in_array('es_ES', $cancelled_locales['dummy-document-hash-id']), 'The document target has been cancelled remotely.');
\Drupal::entityTypeManager()
->getStorage('node_type')
->resetCache();
$entity = \Drupal::entityTypeManager()
->getStorage('node_type')
->load('article');
$this
->assertEquals('dummy-document-hash-id', $config_translation_service
->getDocumentId($entity));
$this
->assertSourceStatus('EN', Lingotek::STATUS_CURRENT);
$this
->assertTargetStatus('ES', Lingotek::STATUS_CANCELLED);
$this
->assertIdentical(Lingotek::STATUS_CURRENT, $config_translation_service
->getSourceStatus($entity));
$this
->assertIdentical(Lingotek::STATUS_CANCELLED, $config_translation_service
->getTargetStatus($entity, 'es'));
$basepath = \Drupal::request()
->getBasePath();
$this
->assertNoLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/es_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
}
protected function createAndTranslateContentTypeWithLinks() {
$this
->goToConfigBulkManagementForm('node_type');
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('EN');
$this
->assertText(t('Article uploaded successfully'));
$this
->clickLink('EN');
$this
->assertText('Article status checked successfully');
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/es_ES?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->clickLink('ES');
$this
->assertText("Translation to es_ES requested successfully");
$this
->clickLink('ES');
$this
->assertText("Translation to es_ES status checked successfully");
$this
->clickLink('ES');
$this
->assertText('Translation to es_ES downloaded successfully');
}
}