3 namespace Drupal\security_review\Tests;
5 use Drupal\security_review\Checklist;
6 use Drupal\simpletest\WebTestBase;
9 * Contains tests related to the SecurityReview class.
11 * @group security_review
13 class ChecklistWebTest extends WebTestBase {
20 public static $modules = ['security_review'];
25 * @var \Drupal\user\Entity\User
30 * The security checks defined by Security Review.
32 * @var \Drupal\security_review\Check[]
37 * The security_review.checklist service.
39 * @var \Drupal\security_review\Checklist
44 * Sets up the testing environment.
46 protected function setUp() {
49 $this->checklist = \Drupal::getContainer()
50 ->get('security_review.checklist');
53 $this->user = $this->drupalCreateUser(
55 'run security checks',
56 'access security review list',
57 'access administration pages',
58 'administer site configuration',
61 $this->drupalLogin($this->user);
64 $this->checks = security_review_security_review_checks();
67 Checklist::clearCache();
71 * Tests a full checklist run.
73 * Tests whether the checks hasn't been run yet, then runs them and checks
74 * that their lastRun value is not 0.
76 public function testRun() {
77 foreach ($this->checks as $check) {
78 $this->assertEqual(0, $check->lastRun(), $check->getTitle() . ' has not been run yet.');
80 $this->checklist->runChecklist();
81 foreach ($this->checks as $check) {
82 $this->assertNotEqual(0, $check->lastRun(), $check->getTitle() . ' has been run.');
87 * Skips all checks then runs the checklist. No checks should be ran.
89 public function testSkippedRun() {
90 foreach ($this->checks as $check) {
93 $this->checklist->runChecklist();
94 foreach ($this->checks as $check) {
95 $this->assertEqual(0, $check->lastRun(), $check->getTitle() . ' has not been run.');