d62cc48a3ea3220f371c7855d3058c071369f2c9
[yaffs-website] / web / core / modules / simpletest / src / Tests / MissingCheckedRequirementsTest.php
1 <?php
2
3 namespace Drupal\simpletest\Tests;
4
5 use Drupal\simpletest\WebTestBase;
6
7 /**
8  * Tests a test case with missing requirements.
9  *
10  * @group simpletest
11  */
12 class MissingCheckedRequirementsTest extends WebTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['simpletest'];
20
21   protected function setUp() {
22     parent::setUp();
23     $admin_user = $this->drupalCreateUser(['administer unit tests']);
24     $this->drupalLogin($admin_user);
25   }
26
27   /**
28    * Overrides checkRequirements().
29    */
30   protected function checkRequirements() {
31     if ($this->isInChildSite()) {
32       return [
33         'Test is not allowed to run.'
34       ];
35     }
36     return parent::checkRequirements();
37   }
38
39   /**
40    * Ensures test will not run when requirements are missing.
41    */
42   public function testCheckRequirements() {
43     // If this is the main request, run the web test script and then assert
44     // that the child tests did not run.
45     if (!$this->isInChildSite()) {
46       // Run this test from web interface.
47       $edit['tests[Drupal\simpletest\Tests\MissingCheckedRequirementsTest]'] = TRUE;
48       $this->drupalPostForm('admin/config/development/testing', $edit, t('Run tests'));
49       $this->assertRaw('Test is not allowed to run.', 'Test check for requirements came up.');
50       $this->assertNoText('Test ran when it failed requirements check.', 'Test requirements stopped test from running.');
51     }
52     else {
53       $this->fail('Test ran when it failed requirements check.');
54     }
55   }
56
57 }