diff --git a/core/modules/field/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php b/core/modules/field/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php index c3c696a..4213e4b 100644 --- a/core/modules/field/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php +++ b/core/modules/field/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php @@ -43,7 +43,7 @@ class TextTranslationTest extends WebTestBase { 'bypass node access', filter_permission_name($full_html_format), )); - $this->translator = $this->drupalCreateUser(array('create article content', 'edit own article content', 'translate content')); + $this->translator = $this->drupalCreateUser(array('create article content', 'edit own article content', 'translate all content')); // Enable an additional language. $this->drupalLogin($this->admin); diff --git a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php index 09518ab..f9aa0de 100644 --- a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php +++ b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php @@ -31,7 +31,7 @@ class PathLanguageTest extends PathTestBase { parent::setUp(); // Create and login user. - $this->web_user = $this->drupalCreateUser(array('edit any page content', 'create page content', 'administer url aliases', 'create url aliases', 'administer languages', 'translate content', 'access administration pages')); + $this->web_user = $this->drupalCreateUser(array('edit any page content', 'create page content', 'administer url aliases', 'create url aliases', 'administer languages', 'translate all content', 'access administration pages')); $this->drupalLogin($this->web_user); // Enable French language. diff --git a/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php b/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php index 819b5f7..84cf03f 100644 --- a/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php +++ b/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php @@ -34,7 +34,7 @@ class PollTranslateTest extends PollTestBase { * the vote count values are set to 0. */ function testPollTranslate() { - $admin_user = $this->drupalCreateUser(array('administer content types', 'administer languages', 'edit any poll content', 'create poll content', 'administer nodes', 'translate content')); + $admin_user = $this->drupalCreateUser(array('administer content types', 'administer languages', 'edit any poll content', 'create poll content', 'administer nodes', 'translate all content')); // Set up a poll with two choices. $title = $this->randomName(); diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php index f9f76a7..7a30cb0 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php @@ -159,4 +159,24 @@ class LanguageUpgradePathTest extends UpgradePathTestBase { // whether index 'plural' has been removed. $this->assertFalse(db_index_exists('locales_target', 'plural'), t('Translations without plurals upgraded.')); } + + /** + * Tests upgrading translations permissions. + */ + public function testLanguagePermissionsUpgrade() { + db_insert('role_permission')->fields(array( + 'rid' => 2, + 'permission' => 'translate content', + 'module' => 'translation', + ))->execute(); + + $this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.')); + + // Check that translate content role doesn't exist on database. + $old_permission_exists = db_query('SELECT * FROM {role_permission} WHERE permission LIKE ?', array('translate content'))->fetchObject(); + $this->assertFalse($old_permission_exists, t('No translate content role left on database.')); + // Check that translate content has been renamed to translate all content. + $new_permission_exists = db_query('SELECT * FROM {role_permission} WHERE permission LIKE ?', array('translate all content'))->fetchObject(); + $this->assertTrue($new_permission_exists, t('Rename role translate content to translate all content was completed successfully.')); + } } diff --git a/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php b/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php index a409150..b4f2b6c 100644 --- a/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php +++ b/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php @@ -38,8 +38,9 @@ class TranslationTest extends WebTestBase { parent::setUp(); // Setup users. - $this->admin_user = $this->drupalCreateUser(array('bypass node access', 'administer nodes', 'administer languages', 'administer content types', 'administer blocks', 'access administration pages', 'translate content')); - $this->translator = $this->drupalCreateUser(array('create page content', 'edit own page content', 'translate content')); + $this->admin_user = $this->drupalCreateUser(array('bypass node access', 'administer nodes', 'administer languages', 'administer content types', 'administer blocks', 'access administration pages', 'translate all content')); + $this->translator = $this->drupalCreateUser(array('create page content', 'edit own page content', 'translate all content')); + $this->limited_translator = $this->drupalCreateUser(array('create page content', 'edit own page content', 'translate own content')); $this->drupalLogin($this->admin_user); @@ -250,6 +251,35 @@ class TranslationTest extends WebTestBase { } /** + * Checks that users with "translate own content" role only can translate own content. + */ + function testTranslateOwnContentRole() { + // Create a Basic page in English and its translation in Spanish with user + // that has "translate own content" role. + $this->drupalLogin($this->limited_translator); + $node = $this->createPage($this->randomName(), $this->randomName(), 'en'); + $this->assertLinkByHref('node/' . $node->nid . '/translate', 0, t('User with "translate own content" role can see translate link')); + $this->drupalGet('node/' . $node->nid . '/translate'); + $this->assertResponse(200, t('User with "translate own content" role can get translate page')); + $translation_es = $this->createTranslation($node, $this->randomName(), $this->randomName(), 'es'); + + // Create a page as translator user. + $this->drupalLogin($this->translator); + $node = $this->createPage($this->randomName(), $this->randomName(), 'en'); + // Change to limited_translator and check that translate links aren't shown. + $this->drupalLogin($this->limited_translator); + $this->assertNoLinkByHref('node/' . $node->nid . '/translate', t('User with "translate own content" role can\'t see translate link')); + // Check if user with "translate own content" role can see translate page + // from other user's node. + $this->drupalGet('node/' . $node->nid . '/translate'); + $this->assertResponse(403, t('User with "translate own content" role can\'t get translate page')); + + // Try to change to translate with "brute force". + $this->drupalGet('node/add/page', array('query' => array('translation' => $node->nid, 'target' => 'es'))); + $this->assertResponse(403, t('User with "translate own content" role can\'t get create translate page')); + } + + /** * Resets static caches to make the test code match the client-side behavior. */ function resetCaches() { diff --git a/core/modules/translation/translation.module b/core/modules/translation/translation.module index 909117f..66f1e2d 100644 --- a/core/modules/translation/translation.module +++ b/core/modules/translation/translation.module @@ -37,7 +37,7 @@ function translation_help($path, $arg) { $output .= '