Including security review as a submodule - with patched for Yaffs.
[yaffs-website] / web / modules / contrib / security_review / src / Tests / ChecklistWebTest.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\security_review\Tests\ChecklistWebTest.
6  */
7
8 namespace Drupal\security_review\Tests;
9
10 use Drupal\security_review\Checklist;
11 use Drupal\simpletest\WebTestBase;
12
13 /**
14  * Contains tests related to the SecurityReview class.
15  *
16  * @group security_review
17  */
18 class ChecklistWebTest extends WebTestBase {
19
20   /**
21    * Modules to enable.
22    *
23    * @var array
24    */
25   public static $modules = ['security_review'];
26
27   /**
28    * The test user.
29    *
30    * @var \Drupal\user\Entity\User
31    */
32   protected $user;
33
34   /**
35    * The security checks defined by Security Review.
36    *
37    * @var \Drupal\security_review\Check[]
38    */
39   protected $checks;
40
41   /**
42    * The security_review.checklist service.
43    *
44    * @var \Drupal\security_review\Checklist
45    */
46   protected $checklist;
47
48   /**
49    * Sets up the testing environment.
50    */
51   protected function setUp() {
52     parent::setUp();
53
54     $this->checklist = \Drupal::getContainer()
55       ->get('security_review.checklist');
56
57     // Login.
58     $this->user = $this->drupalCreateUser(
59       [
60         'run security checks',
61         'access security review list',
62         'access administration pages',
63         'administer site configuration',
64       ]
65     );
66     $this->drupalLogin($this->user);
67
68     // Populate $checks.
69     $this->checks = security_review_security_review_checks();
70
71     // Clear cache.
72     Checklist::clearCache();
73   }
74
75   /**
76    * Tests a full checklist run.
77    *
78    * Tests whether the checks hasn't been run yet, then runs them and checks
79    * that their lastRun value is not 0.
80    */
81   public function testRun() {
82     foreach ($this->checks as $check) {
83       $this->assertEqual(0, $check->lastRun(), $check->getTitle() . ' has not been run yet.');
84     }
85     $this->checklist->runChecklist();
86     foreach ($this->checks as $check) {
87       $this->assertNotEqual(0, $check->lastRun(), $check->getTitle() . ' has been run.');
88     }
89   }
90
91   /**
92    * Skips all checks then runs the checklist. No checks should be ran.
93    */
94   public function testSkippedRun() {
95     foreach ($this->checks as $check) {
96       $check->skip();
97     }
98     $this->checklist->runChecklist();
99     foreach ($this->checks as $check) {
100       $this->assertEqual(0, $check->lastRun(), $check->getTitle() . ' has not been run.');
101     }
102   }
103
104 }