Skip to content

Commit

Permalink
Minor test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Erkelens committed Jul 16, 2023
1 parent e4b091f commit e9b9c8c
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions tests/unit/ControllerExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,20 @@ public function testInit()
public function testNonceOnExcludedControllers()
{
//when CSPBackend.useNonce is true, it should only apply to controllers
//with the extension applied. By default, this is page controller
//with the extension applied. By default, this is root controller
CSPBackend::setUsesNonce(true);
$page = new Page();
$controller = new PageController($page);
$extension = new ControllerCSPExtension();

$extension->setOwner($controller);

//useNonce is set but only applies on the PageController.
//let's check Security controller for logins: it should be absent
//let's check Security controller for logins: it should be there
$secController = new Security();
$this->expectException('BadMethodCallException');
$this->assertNull($secController->getNonce());
$this->assertNotNull($secController->getNonce());

//also check CMS-level controllers
$cmsController = new LeftAndMain();
$this->expectException('BadMethodCallException');
$this->assertNull($secController->getNonce());

//now apply the extension, getNonce should not be null
$extension2 = new ControllerCSPExtension();

$extension2->setOwner($secController);
$this->assertNotNull($secController->getNonce());

$extension3 = new ControllerCSPExtension();

$extension3->setOwner($cmsController);
$this->assertNotNull($cmsController->getNonce());
}
}

0 comments on commit e9b9c8c

Please sign in to comment.