beb7b486d5023a8815e156232404472d27500c5b
[yaffs-website] / Wizard / WizardPluginBaseKernelTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Kernel\Wizard;
4
5 use Drupal\Core\Form\FormState;
6 use Drupal\language\Entity\ConfigurableLanguage;
7 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
8 use Drupal\views_ui\ViewUI;
9
10 /**
11  * Tests the wizard base plugin class.
12  *
13  * @group views
14  * @see \Drupal\views\Plugin\views\wizard\WizardPluginBase
15  */
16 class WizardPluginBaseKernelTest extends ViewsKernelTestBase {
17
18   /**
19    * Modules to enable.
20    *
21    * @var array
22    */
23   public static $modules = ['language', 'system', 'user', 'views_ui'];
24
25   /**
26    * Contains thw wizard plugin manager.
27    *
28    * @var \Drupal\views\Plugin\views\wizard\WizardPluginBase
29    */
30   protected $wizard;
31
32   protected function setUp($import_test_views = TRUE) {
33     parent::setUp();
34
35     $this->installConfig(['language']);
36
37     $this->wizard = $this->container->get('plugin.manager.views.wizard')->createInstance('standard:views_test_data', []);
38   }
39
40   /**
41    * Tests the creating of a view.
42    *
43    * @see \Drupal\views\Plugin\views\wizard\WizardPluginBase
44    */
45   public function testCreateView() {
46     $form = [];
47     $form_state = new FormState();
48     $form = $this->wizard->buildForm($form, $form_state);
49     $random_id = strtolower($this->randomMachineName());
50     $random_label = $this->randomMachineName();
51     $random_description = $this->randomMachineName();
52
53     // Add a new language and mark it as default.
54     ConfigurableLanguage::createFromLangcode('it')->save();
55     $this->config('system.site')->set('default_langcode', 'it')->save();
56
57     $form_state->setValues([
58       'id' => $random_id,
59       'label' => $random_label,
60       'description' => $random_description,
61       'base_table' => 'views_test_data',
62     ]);
63
64     $this->wizard->validateView($form, $form_state);
65     $view = $this->wizard->createView($form, $form_state);
66     $this->assertTrue($view instanceof ViewUI, 'The created view is a ViewUI object.');
67     $this->assertEqual($view->get('id'), $random_id);
68     $this->assertEqual($view->get('label'), $random_label);
69     $this->assertEqual($view->get('description'), $random_description);
70     $this->assertEqual($view->get('base_table'), 'views_test_data');
71     $this->assertEqual($view->get('langcode'), 'it');
72   }
73
74 }