Version 1
[yaffs-website] / web / modules / contrib / video_embed_field / tests / src / Functional / InstallationTest.php
1 <?php
2
3 namespace Drupal\Tests\video_embed_field\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Test the modules install and uninstall cleanly.
9  *
10  * @group video_embed_field
11  */
12 class InstallationTest extends BrowserTestBase {
13
14   use AdminUserTrait;
15
16   /**
17    * {@inheritdoc}
18    */
19   protected function setUp() {
20     parent::setUp();
21     $this->drupalLogin($this->createAdminUser());
22   }
23
24   /**
25    * Test the installation and uninstallation of the the modules.
26    */
27   public function testInstallation() {
28     $this->assertInstallationStatus(FALSE);
29     $this->installModules();
30     $this->assertInstallationStatus(TRUE);
31     $this->uninstallModules();
32     $this->assertInstallationStatus(FALSE);
33     $this->installModules();
34     $this->assertInstallationStatus(TRUE);
35   }
36
37   /**
38    * Assert the installation status of the modules.
39    *
40    * @param bool $installed
41    *   If the modules should be installed or not.
42    */
43   protected function assertInstallationStatus($installed) {
44     $this->drupalGet('admin/modules');
45     // @todo, add video_embed_media once infrastructure places version
46     // information in module info files.
47     foreach (['video_embed_field', 'video_embed_wysiwyg'] as $module) {
48       $this->assertSession()->{$installed ? 'checkboxChecked' : 'checkboxNotChecked'}('modules[' . $module . '][enable]');
49     }
50   }
51
52   /**
53    * Uninstall the module using the UI.
54    */
55   protected function uninstallModules() {
56     $this->drupalPostForm('admin/modules/uninstall', [
57       'uninstall[video_embed_wysiwyg]' => TRUE,
58     ], 'Uninstall');
59     $this->getSession()->getPage()->pressButton('Uninstall');
60     $this->drupalPostForm('admin/modules/uninstall', [
61       'uninstall[video_embed_field]' => TRUE,
62     ], 'Uninstall');
63     $this->getSession()->getPage()->pressButton('Uninstall');
64   }
65
66   /**
67    * Install the modules using the UI.
68    */
69   protected function installModules() {
70     $this->drupalPostForm('admin/modules', [
71       'modules[video_embed_field][enable]' => TRUE,
72       'modules[video_embed_wysiwyg][enable]' => TRUE,
73     ], 'Install');
74     // Continue is only required to confirm dependencies being enabled on the
75     // first call of this function.
76     if ($button = $this->getSession()->getPage()->findButton('Continue')) {
77       $button->press();
78     }
79   }
80
81 }