ChecklistTest.php in Security Review 8
File
tests/src/Kernel/ChecklistTest.php
View source
<?php
namespace Drupal\Tests\security_review\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\security_review\Checklist;
class ChecklistTest extends KernelTestBase {
public static $modules = [
'security_review',
'security_review_test',
];
protected $checklist;
protected $checks;
protected $realChecks;
protected $testChecks;
protected $checkIDs;
protected function setUp() {
parent::setUp();
$this->checklist = \Drupal::getContainer()
->get('security_review.checklist');
$this->realChecks = security_review_security_review_checks();
$this->testChecks = security_review_test_security_review_checks();
$this->checks = array_merge($this->realChecks, $this->testChecks);
Checklist::clearCache();
$this->checkIDs = [];
foreach ($this->checks as $check) {
$this->checkIDs[] = $check
->id();
}
}
public function testChecksProvided() {
foreach ($this->checklist
->getChecks() as $check) {
$this
->assertTrue(in_array($check
->id(), $this->checkIDs), $check
->getTitle() . ' found.');
}
}
public function testEnabledChecks() {
foreach ($this->checklist
->getEnabledChecks() as $check) {
$this
->assertFalse($check
->isSkipped(), $check
->getTitle() . ' is enabled.');
$check
->skip();
}
Checklist::clearCache();
$this
->assertEquals(0, count($this->checklist
->getEnabledChecks()), 'Disabled all checks.');
}
public function testCheckSearch() {
foreach ($this->checklist
->getChecks() as $check) {
$found = $this->checklist
->getCheck($check
->getMachineNamespace(), $check
->getMachineTitle());
$this
->assertEquals($check
->id(), $found
->id(), 'Found ' . $check
->getTitle() . '.');
$found = $this->checklist
->getCheckById($check
->id());
$this
->assertEquals($check
->id(), $found
->id(), 'Found ' . $check
->getTitle() . '.');
}
}
}