View source
<?php
namespace Drupal\lingotek\Tests\Form;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\lingotek\Lingotek;
use Drupal\lingotek\LingotekContentTranslationServiceInterface;
use Drupal\lingotek\Tests\LingotekTestBase;
use Drupal\node\Entity\Node;
class LingotekMetadataEditFormTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
];
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block', [
'region' => 'content',
'weight' => -5,
]);
$this
->drupalPlaceBlock('local_tasks_block', [
'region' => 'content',
'weight' => -10,
]);
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX')
->save();
ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'article', TRUE);
drupal_static_reset();
\Drupal::entityManager()
->clearCachedDefinitions();
\Drupal::service('entity.definition_update_manager')
->applyUpdates();
$this
->rebuildContainer();
$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');
}
public function testMetadataLocalTaskNotAvailable() {
$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'] = 'automatic';
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$this
->assertUrl('/node/1', [], 'Node has been created.');
$this
->assertNoLink(t('Lingotek Metadata'));
}
public function testMetadataLocalTaskAvailable() {
$this
->drupalPostForm('admin/lingotek/settings', [], 'Enable debug operations');
$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'] = 'automatic';
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$this
->assertUrl('/node/1', [], 'Node has been created.');
$this
->drupalGet('/node/1');
$this
->assertLink(t('Lingotek Metadata'));
}
public function testMetadataEditForm() {
$this
->drupalPostForm('admin/lingotek/settings', [], 'Enable debug operations');
$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'] = 'automatic';
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$this
->drupalGet('/node/1');
$this
->clickLink(t('Lingotek Metadata'));
$this
->assertUrl('/node/1/metadata', [], 'Metadata local task enables the metadata form.');
$this
->assertFieldById('edit-lingotek-document-id', 'dummy-document-hash-id');
$this
->assertOptionSelected('edit-lingotek-source-status', Lingotek::STATUS_IMPORTING);
$this
->assertOptionSelected('edit-en', Lingotek::STATUS_IMPORTING);
$this
->assertOptionSelected('edit-es', Lingotek::STATUS_REQUEST);
$edit = [
'lingotek_document_id' => 'another-id',
'lingotek_source_status' => Lingotek::STATUS_UNTRACKED,
'en' => Lingotek::STATUS_UNTRACKED,
'es' => Lingotek::STATUS_READY,
];
$this
->drupalPostForm(NULL, $edit, 'Save metadata');
$this
->assertFieldById('edit-lingotek-document-id', 'another-id');
$this
->assertOptionSelected('edit-lingotek-source-status', Lingotek::STATUS_UNTRACKED);
$this
->assertOptionSelected('edit-en', Lingotek::STATUS_UNTRACKED);
$this
->assertOptionSelected('edit-es', Lingotek::STATUS_READY);
$content_translation_service = \Drupal::service('lingotek.content_translation');
$node = Node::load(1);
$this
->assertIdentical('another-id', $content_translation_service
->getDocumentId($node));
$this
->assertIdentical(Lingotek::STATUS_UNTRACKED, $content_translation_service
->getSourceStatus($node));
$this
->assertIdentical(Lingotek::STATUS_UNTRACKED, $content_translation_service
->getTargetStatus($node, 'en'));
$this
->assertIdentical(Lingotek::STATUS_READY, $content_translation_service
->getTargetStatus($node, 'es'));
}
}