5 * Contains \Drupal\security_review\Tests\ChecklistTest.
8 namespace Drupal\security_review\Tests;
10 use Drupal\security_review\Checklist;
11 use Drupal\simpletest\KernelTestBase;
14 * Contains test for Checklist.
16 * @group security_review
18 class ChecklistTest extends KernelTestBase {
25 public static $modules = ['security_review', 'security_review_test'];
28 * The security_review.checklist service.
30 * @var \Drupal\security_review\Checklist
35 * The security checks defined by Security Review and Security Review Test.
37 * @var \Drupal\security_review\Check[]
42 * The security checks defined by Security Review.
44 * @var \Drupal\security_review\Check[]
46 protected $realChecks;
49 * The security checks defined by Security Review Test.
51 * @var \Drupal\security_review\Check[]
53 protected $testChecks;
56 * Array of the IDs of $checks.
63 * Sets up the environment, populates the $checks variable.
65 protected function setUp() {
68 $this->checklist = \Drupal::getContainer()
69 ->get('security_review.checklist');
70 $this->realChecks = security_review_security_review_checks();
71 $this->testChecks = security_review_test_security_review_checks();
72 $this->checks = array_merge($this->realChecks, $this->testChecks);
74 Checklist::clearCache();
76 foreach ($this->checks as $check) {
77 $this->checkIDs[] = $check->id();
82 * Tests Checklist::getChecks().
84 * Tests whether getChecks() contains all the checks that
85 * security_review_security_review_checks() and
86 * security_review_test_security_review_checks() returns.
88 public function testChecksProvided() {
89 foreach ($this->checklist->getChecks() as $check) {
90 $this->assertTrue(in_array($check->id(), $this->checkIDs), $check->getTitle() . ' found.');
95 * Tests whether checks returned by getEnabledChecks() are all enabled.
97 public function testEnabledChecks() {
98 foreach ($this->checklist->getEnabledChecks() as $check) {
99 $this->assertFalse($check->isSkipped(), $check->getTitle() . ' is enabled.');
104 Checklist::clearCache();
105 $this->assertEqual(count($this->checklist->getEnabledChecks()), 0, 'Disabled all checks.');
109 * Tests Checklist's Check search functions.
111 * Tests the search functions of Checklist:
115 public function testCheckSearch() {
116 foreach ($this->checklist->getChecks() as $check) {
118 $found = $this->checklist->getCheck($check->getMachineNamespace(), $check->getMachineTitle());
119 $this->assertNotNull($found, 'Found a check.');
120 $this->assertEqual($check->id(), $found->id(), 'Found ' . $check->getTitle() . '.');
123 $found = $this->checklist->getCheckById($check->id());
124 $this->assertNotNull($found, 'Found a check.');
125 $this->assertEqual($check->id(), $found->id(), 'Found ' . $check->getTitle() . '.');