diff --git a/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php b/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php index c7d8216..0db8f21 100644 --- a/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php @@ -72,18 +72,6 @@ public function testValidate() { $token = $this->generator->get('bar'); $this->assertTrue($this->generator->validate($token, 'bar')); - // The following checks will throw PHP fatals and notices, so we disable - // error assertions. - set_error_handler(array($this, "errorHandler")); - $this->assertFalse($this->generator->validate(NULL, new \stdClass()), 'Token NULL, value object returns FALSE.'); - $this->assertFalse($this->generator->validate(0, array()), 'Token 0, value array returns FALSE.'); - $this->assertFalse($this->generator->validate('', array()), "Token '', value array returns FALSE."); - $this->assertFalse('' === $this->generator->validate(array()), 'Token generation does not return an empty string on invalid parameters.'); - restore_error_handler(); - - $this->assertFalse($this->generator->validate(TRUE, 'foo'), 'Token TRUE, value foo returns FALSE.'); - $this->assertFalse($this->generator->validate(0, 'foo'), 'Token 0, value foo returns FALSE.'); - // Check the skip_anonymous option with both a anonymous user and a real // user. $account = $this->getMock('Drupal\Core\Session\AccountInterface'); @@ -103,10 +91,40 @@ public function testValidate() { } /** - * Provides a custom error handler that disables all reporting. + * Tests CsrfTokenGenerator::validate() with different parameter types. + * + * @param mixed $token + * The token to be validated. + * @param mixed $value + * (optional) An additional value to base the token on. + * @param mixed $expected + * (optional) The expected result of validate(). Defaults to FALSE. + * + * @dataProvider providerTestValidateParameterTypes */ - public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) { - return TRUE; + public function testValidateParameterTypes($token, $value = '', $expected = FALSE) { + // The following check might throw PHP fatals and notices, so we disable + // error assertions. + set_error_handler(function () {return TRUE;}); + $this->assertSame($expected, $this->generator->validate($token, $value)); + restore_error_handler(); + } + + /** + * Provides data for the validate test. + * + * @return array + * An array of data used by the test. + */ + public function providerTestValidateParameterTypes() { + return array( + array(NULL, new \stdClass()), + array(0, array()), + array('', array()), + array(array()), + array(TRUE, 'foo'), + array(0, 'foo'), + ); } }