8a2dd2953f3b20c1a858d5a7f30975da94e7c69e
[yaffs-website] / web / core / modules / views_ui / tests / src / Functional / ViewsUITourTest.php
1 <?php
2
3 namespace Drupal\Tests\views_ui\Functional;
4
5 use Drupal\Tests\tour\Functional\TourTestBase;
6 use Drupal\language\Entity\ConfigurableLanguage;
7
8 /**
9  * Tests the Views UI tour.
10  *
11  * @group views_ui
12  */
13 class ViewsUITourTest extends TourTestBase {
14
15   /**
16    * An admin user with administrative permissions for views.
17    *
18    * @var \Drupal\user\UserInterface
19    */
20   protected $adminUser;
21
22   /**
23    * String translation storage object.
24    *
25    * @var \Drupal\locale\StringStorageInterface
26    */
27   protected $localeStorage;
28
29   /**
30    * Modules to enable.
31    *
32    * @var array
33    */
34   public static $modules = ['views_ui', 'tour', 'language', 'locale'];
35
36   protected function setUp() {
37     parent::setUp();
38     $this->adminUser = $this->drupalCreateUser(['administer views', 'access tour']);
39     $this->drupalLogin($this->adminUser);
40   }
41
42   /**
43    * Tests views_ui tour tip availability.
44    */
45   public function testViewsUiTourTips() {
46     // Create a basic view that shows all content, with a page and a block
47     // display.
48     $view['label'] = $this->randomMachineName(16);
49     $view['id'] = strtolower($this->randomMachineName(16));
50     $view['page[create]'] = 1;
51     $view['page[path]'] = $this->randomMachineName(16);
52     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
53     $this->assertTourTips();
54   }
55
56   /**
57    * Tests views_ui tour tip availability in a different language.
58    */
59   public function testViewsUiTourTipsTranslated() {
60     $langcode = 'nl';
61
62     // Add a default locale storage for this test.
63     $this->localeStorage = $this->container->get('locale.storage');
64
65     // Add Dutch language programmatically.
66     ConfigurableLanguage::createFromLangcode($langcode)->save();
67
68     // Handler titles that need translations.
69     $handler_titles = [
70       'Format',
71       'Fields',
72       'Sort criteria',
73       'Filter criteria',
74     ];
75
76     foreach ($handler_titles as $handler_title) {
77       // Create source string.
78       $source = $this->localeStorage->createString([
79         'source' => $handler_title,
80       ]);
81       $source->save();
82       $this->createTranslation($source, $langcode);
83     }
84
85     // Create a basic view that shows all content, with a page and a block
86     // display.
87     $view['label'] = $this->randomMachineName(16);
88     $view['id'] = strtolower($this->randomMachineName(16));
89     $view['page[create]'] = 1;
90     $view['page[path]'] = $this->randomMachineName(16);
91     // Load the page in dutch.
92     $this->drupalPostForm(
93       $langcode . '/admin/structure/views/add',
94       $view,
95       t('Save and edit')
96     );
97     $this->assertTourTips();
98   }
99
100   /**
101    * Creates single translation for source string.
102    */
103   public function createTranslation($source, $langcode) {
104     return $this->localeStorage->createTranslation([
105         'lid' => $source->lid,
106         'language' => $langcode,
107         'translation' => $this->randomMachineName(100),
108       ])->save();
109   }
110
111 }