3 namespace Drupal\Tests\security_review\Kernel;
5 use Drupal\KernelTests\KernelTestBase;
6 use Drupal\security_review\Checklist;
9 * Contains test for Checklist.
11 * @group security_review
13 class ChecklistTest extends KernelTestBase {
20 public static $modules = ['security_review', 'security_review_test'];
23 * The security_review.checklist service.
25 * @var \Drupal\security_review\Checklist
30 * The security checks defined by Security Review and Security Review Test.
32 * @var \Drupal\security_review\Check[]
37 * The security checks defined by Security Review.
39 * @var \Drupal\security_review\Check[]
41 protected $realChecks;
44 * The security checks defined by Security Review Test.
46 * @var \Drupal\security_review\Check[]
48 protected $testChecks;
51 * Array of the IDs of $checks.
58 * Sets up the environment, populates the $checks variable.
60 protected function setUp() {
63 $this->checklist = \Drupal::getContainer()
64 ->get('security_review.checklist');
65 $this->realChecks = security_review_security_review_checks();
66 $this->testChecks = security_review_test_security_review_checks();
67 $this->checks = array_merge($this->realChecks, $this->testChecks);
69 Checklist::clearCache();
71 foreach ($this->checks as $check) {
72 $this->checkIDs[] = $check->id();
77 * Tests Checklist::getChecks().
79 * Tests whether getChecks() contains all the checks that
80 * security_review_security_review_checks() and
81 * security_review_test_security_review_checks() returns.
83 public function testChecksProvided() {
84 foreach ($this->checklist->getChecks() as $check) {
85 $this->assertTrue(in_array($check->id(), $this->checkIDs), $check->getTitle() . ' found.');
90 * Tests whether checks returned by getEnabledChecks() are all enabled.
92 public function testEnabledChecks() {
93 foreach ($this->checklist->getEnabledChecks() as $check) {
94 $this->assertFalse($check->isSkipped(), $check->getTitle() . ' is enabled.');
99 Checklist::clearCache();
100 $this->assertEquals(0, count($this->checklist->getEnabledChecks()), 'Disabled all checks.');
104 * Tests Checklist's Check search functions.
106 * Tests the search functions of Checklist:
110 public function testCheckSearch() {
111 foreach ($this->checklist->getChecks() as $check) {
113 $found = $this->checklist->getCheck($check->getMachineNamespace(), $check->getMachineTitle());
114 $this->assertEquals($check->id(), $found->id(), 'Found ' . $check->getTitle() . '.');
117 $found = $this->checklist->getCheckById($check->id());
118 $this->assertEquals($check->id(), $found->id(), 'Found ' . $check->getTitle() . '.');