Backup of db before drupal security update
[yaffs-website] / web / core / modules / content_translation / src / Tests / Views / TranslationLinkTest.php
1 <?php
2
3 namespace Drupal\content_translation\Tests\Views;
4
5 use Drupal\content_translation\Tests\ContentTranslationTestBase;
6 use Drupal\views\Tests\ViewTestData;
7 use Drupal\Core\Language\Language;
8 use Drupal\user\Entity\User;
9
10 /**
11  * Tests the content translation overview link field handler.
12  *
13  * @group content_translation
14  * @see \Drupal\content_translation\Plugin\views\field\TranslationLink
15  */
16 class TranslationLinkTest extends ContentTranslationTestBase {
17
18   /**
19    * Views used by this test.
20    *
21    * @var array
22    */
23   public static $testViews = ['test_entity_translations_link'];
24
25   /**
26    * Modules to enable.
27    *
28    * @var array
29    */
30   public static $modules = ['content_translation_test_views'];
31
32   protected function setUp() {
33     // @todo Use entity_type once it is has multilingual Views integration.
34     $this->entityTypeId = 'user';
35
36     parent::setUp();
37
38     // Assign user 1  a language code so that the entity can be translated.
39     $user = User::load(1);
40     $user->langcode = 'en';
41     $user->save();
42
43     // Assign user 2 LANGCODE_NOT_SPECIFIED code so entity can't be translated.
44     $user = User::load(2);
45     $user->langcode = Language::LANGCODE_NOT_SPECIFIED;
46     $user->save();
47
48     ViewTestData::createTestViews(get_class($this), ['content_translation_test_views']);
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   protected function getTranslatorPermissions() {
55     $permissions = parent::getTranslatorPermissions();
56     $permissions[] = 'access user profiles';
57     return $permissions;
58   }
59
60   /**
61    * Tests the content translation overview link field handler.
62    */
63   public function testTranslationLink() {
64     $this->drupalGet('test-entity-translations-link');
65     $this->assertLinkByHref('user/1/translations');
66     $this->assertNoLinkByHref('user/2/translations', 'The translations link is not present when content_translation_translate_access() is FALSE.');
67   }
68
69 }