ViewsUITourTest.php 2.87 KB
Newer Older
1 2
<?php

3
namespace Drupal\Tests\views_ui\Functional;
4

5
use Drupal\Tests\tour\Functional\TourTestBase;
6
use Drupal\language\Entity\ConfigurableLanguage;
7 8

/**
9 10 11
 * Tests the Views UI tour.
 *
 * @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 24 25 26 27 28
  /**
   * String translation storage object.
   *
   * @var \Drupal\locale\StringStorageInterface
   */
  protected $localeStorage;

29
  /**
30
   * Modules to enable.
31 32 33
   *
   * @var array
   */
34
  public static $modules = ['views_ui', 'tour', 'language', 'locale'];
35 36 37

  protected function setUp() {
    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 46 47
  public function testViewsUiTourTips() {
    // Create a basic view that shows all content, with a page and a block
    // display.
48 49
    $view['label'] = $this->randomMachineName(16);
    $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 58 59 60 61 62 63 64 65 66 67 68
  /**
   * Tests views_ui tour tip availability in a different language.
   */
  public function testViewsUiTourTipsTranslated() {
    $langcode = 'nl';

    // Add a default locale storage for this test.
    $this->localeStorage = $this->container->get('locale.storage');

    // Add Dutch language programmatically.
    ConfigurableLanguage::createFromLangcode($langcode)->save();

    // Handler titles that need translations.
69
    $handler_titles = [
70 71 72 73
      'Format',
      'Fields',
      'Sort criteria',
      'Filter criteria',
74
    ];
75 76 77

    foreach ($handler_titles as $handler_title) {
      // Create source string.
78
      $source = $this->localeStorage->createString([
79
        'source' => $handler_title
80
      ]);
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
      $source->save();
      $this->createTranslation($source, $langcode);
    }

    // Create a basic view that shows all content, with a page and a block
    // display.
    $view['label'] = $this->randomMachineName(16);
    $view['id'] = strtolower($this->randomMachineName(16));
    $view['page[create]'] = 1;
    $view['page[path]'] = $this->randomMachineName(16);
    // Load the page in dutch.
    $this->drupalPostForm(
      $langcode . '/admin/structure/views/add',
      $view,
      t('Save and edit')
    );
    $this->assertTourTips();
  }

  /**
   * Creates single translation for source string.
   */
  public function createTranslation($source, $langcode) {
104
    return $this->localeStorage->createTranslation([
105 106 107
        'lid' => $source->lid,
        'language' => $langcode,
        'translation' => $this->randomMachineName(100),
108
      ])->save();
109 110
  }

111
}