diff --git a/sources/content/src/Tests/ContentEntitySourceUiTest.php b/sources/content/src/Tests/ContentEntitySourceUiTest.php index 81b23cf..d6562eb 100644 --- a/sources/content/src/Tests/ContentEntitySourceUiTest.php +++ b/sources/content/src/Tests/ContentEntitySourceUiTest.php @@ -28,7 +28,7 @@ class ContentEntitySourceUiTest extends EntityTestBase { * * @var array */ - public static $modules = array('tmgmt_content', 'comment', 'ckeditor'); + public static $modules = array('tmgmt_content', 'comment', 'ckeditor', 'tmgmt_local'); /** * {@inheritdoc} @@ -84,8 +84,12 @@ class ContentEntitySourceUiTest extends EntityTestBase { $this->assertText(t('One job needs to be checked out.')); $this->assertText($node->getTitle()); + $edit = [ + 'translator' => 'test_translator', + ]; + // Submit. - $this->drupalPostForm(NULL, array(), t('Submit to provider')); + $this->drupalPostForm(NULL, $edit, t('Submit to provider')); // Make sure that we're back on the translate tab. $this->assertEqual($node->url('canonical', array('absolute' => TRUE)) . '/translations', $this->getUrl()); @@ -139,7 +143,10 @@ class ContentEntitySourceUiTest extends EntityTestBase { // Verify that we are on the checkout page. $this->assertText(t('One job needs to be checked out.')); $this->assertText($node->getTitle()); - $this->drupalPostForm(NULL, array(), t('Submit to provider')); + $edit = array( + 'translator' => 'test_translator', + ); + $this->drupalPostForm(NULL, $edit, t('Submit to provider')); // Make sure that we're back on the originally defined destination URL. $this->assertEqual($node->url('canonical', array('absolute' => TRUE)), $this->getUrl()); @@ -187,7 +194,10 @@ class ContentEntitySourceUiTest extends EntityTestBase { 'languages[de]' => TRUE, ); $this->drupalPostForm(NULL, $edit, t('Request translation')); - $this->drupalPostForm(NULL, array(), t('Submit to provider')); + $edit = array( + 'translator' => 'test_translator', + ); + $this->drupalPostForm(NULL, $edit, t('Submit to provider')); $this->clickLink(t('Needs review')); // Delete the node and assert that the job can not be accepted. @@ -231,9 +241,12 @@ class ContentEntitySourceUiTest extends EntityTestBase { // Submit all jobs. $this->assertText($node->getTitle()); - $this->drupalPostForm(NULL, array(), t('Submit to provider and continue')); + $edit = [ + 'translator' => $default_translator->id(), + ]; + $this->drupalPostForm(NULL, $edit, t('Submit to provider and continue')); $this->assertText($node->getTitle()); - $this->drupalPostForm(NULL, array(), t('Submit to provider')); + $this->drupalPostForm(NULL, $edit, t('Submit to provider')); // Make sure that we're back on the translate tab. $this->assertEqual($node->url('canonical', array('absolute' => TRUE)) . '/translations', $this->getUrl()); @@ -327,11 +340,15 @@ class ContentEntitySourceUiTest extends EntityTestBase { // Verify that we are on the translate tab. $this->assertText(t('2 jobs need to be checked out.')); + $edit = [ + 'translator' => $default_translator->id(), + ]; + // Submit all jobs. $this->assertText($comment->getSubject()); - $this->drupalPostForm(NULL, array(), t('Submit to provider and continue')); + $this->drupalPostForm(NULL, $edit, t('Submit to provider and continue')); $this->assertText($comment->getSubject()); - $this->drupalPostForm(NULL, array(), t('Submit to provider')); + $this->drupalPostForm(NULL, $edit, t('Submit to provider')); // Make sure that we're back on the translate tab. $this->assertUrl($comment->url('canonical', array('absolute' => TRUE)) . '/translations'); @@ -715,4 +732,61 @@ class ContentEntitySourceUiTest extends EntityTestBase { $this->assertEqual(count($continuous_job->getItems()), 3, 'There are no new job items for selected nodes.'); } + /** + * Test local translator with content entity sources. + */ + public function testLocalTranslatorWithContentEntitySource() { + $user = $this->loginAsAdmin([ + 'administer translation tasks', + 'provide translation services', + 'view the administration theme', + 'administer themes', + 'translate any entity', + 'create content translations', + 'view own unpublished content', + ]); + + $edit = array( + 'tmgmt_translation_skills[0][language_from]' => 'en', + 'tmgmt_translation_skills[0][language_to]' => 'de', + ); + $this->drupalPostForm('user/' . $user->id() . '/edit', $edit, t('Save')); + + // Create an english source node. + $node = $this->createTranslatableNode('page', 'en'); + $node->setPublished(FALSE); + $node->save(); + + // Go to the translate tab. + $this->drupalGet('node/' . $node->id()); + $this->clickLink('Translate'); + + // Request a translation for german. + $edit = array( + 'languages[de]' => TRUE, + ); + $this->drupalPostForm(NULL, $edit, t('Request translation')); + $this->assertText($node->getTitle()); + + // Submit job. + $edit = [ + 'settings[translator]' => $user->id(), + ]; + $this->drupalPostForm(NULL, $edit, t('Submit to provider')); + + $this->drupalLogin($user); + + // Go to local task item form. + $this->drupalGet('translate'); + $this->clickLink(t('View')); + $this->clickLink(t('Translate')); + + // Assert source link + $this->assertLink($node->getTitle()); + + // Test that local translator can access an unpublished node. + $this->clickLink($node->getTitle()); + $this->assertText($node->getTitle()); + } + }