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