public function LingotekContentTranslationDocumentUploadHookTest::testNodeTranslation in Lingotek Translation 3.2.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/LingotekContentTranslationDocumentUploadHookTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTranslationDocumentUploadHookTest::testNodeTranslation()
- 4.0.x tests/src/Functional/LingotekContentTranslationDocumentUploadHookTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTranslationDocumentUploadHookTest::testNodeTranslation()
- 3.0.x tests/src/Functional/LingotekContentTranslationDocumentUploadHookTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTranslationDocumentUploadHookTest::testNodeTranslation()
- 3.1.x tests/src/Functional/LingotekContentTranslationDocumentUploadHookTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTranslationDocumentUploadHookTest::testNodeTranslation()
- 3.3.x tests/src/Functional/LingotekContentTranslationDocumentUploadHookTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTranslationDocumentUploadHookTest::testNodeTranslation()
- 3.4.x tests/src/Functional/LingotekContentTranslationDocumentUploadHookTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTranslationDocumentUploadHookTest::testNodeTranslation()
- 3.5.x tests/src/Functional/LingotekContentTranslationDocumentUploadHookTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTranslationDocumentUploadHookTest::testNodeTranslation()
- 3.6.x tests/src/Functional/LingotekContentTranslationDocumentUploadHookTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTranslationDocumentUploadHookTest::testNodeTranslation()
- 3.7.x tests/src/Functional/LingotekContentTranslationDocumentUploadHookTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTranslationDocumentUploadHookTest::testNodeTranslation()
- 3.8.x tests/src/Functional/LingotekContentTranslationDocumentUploadHookTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTranslationDocumentUploadHookTest::testNodeTranslation()
Tests that a node can be translated.
File
- tests/
src/ Functional/ LingotekContentTranslationDocumentUploadHookTest.php, line 78
Class
- LingotekContentTranslationDocumentUploadHookTest
- Tests the hooks a node.
Namespace
Drupal\Tests\lingotek\FunctionalCode
public function testNodeTranslation() {
// Login as admin.
$this
->drupalLogin($this->rootUser);
$test_image = current($this
->getTestFiles('image'));
// Create a node.
$edit = [];
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['files[field_image_0]'] = \Drupal::service('file_system')
->realpath($test_image->uri);
$this
->drupalPostForm('node/add/animal', $edit, t('Preview'));
unset($edit['files[field_image_0]']);
$edit['field_image[0][alt]'] = 'Llamas are cool';
$this
->saveAndPublishNodeForm($edit, NULL);
$this->node = Node::load(1);
// Check that the configured fields have been uploaded, but also the one
// added via the hook.
$data = json_decode(\Drupal::state()
->get('lingotek.uploaded_content', '[]'), TRUE);
$this
->assertUploadedDataFieldCount($data, 4);
$this
->assertTrue(isset($data['title'][0]['value']));
$this
->assertEqual(1, count($data['body'][0]));
$this
->assertTrue(isset($data['body'][0]['value']));
$this
->assertEqual(1, count($data['field_image'][0]));
$this
->assertTrue(isset($data['field_image'][0]['alt']));
$this
->assertTrue(isset($data['animal_date']));
$this
->assertEqual('2016-05-01', $data['animal_date']);
// Assert the locale used was correct.
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
// Check that the profile used was the right one.
$used_profile = \Drupal::state()
->get('lingotek.used_profile');
$this
->assertIdentical('automatic', $used_profile, 'The automatic profile was used.');
// Check that the url used was the right one.
$uploaded_url = \Drupal::state()
->get('lingotek.uploaded_url');
$this
->assertIdentical(\Drupal::request()
->getBasePath() . '/animal/2016/llamas-are-cool', $uploaded_url, 'The altered url was used.');
}