From fc1cc18ef14094e91a05583658cb4adba56f0e61 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 28 Apr 2016 14:26:48 +0200 Subject: [PATCH] No empty identifier allowed. --- src/qtism/common/datatypes/QtiIdentifier.php | 3 +++ .../qtismtest/common/datatypes/IdentifierTest.php | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/qtism/common/datatypes/QtiIdentifier.php b/src/qtism/common/datatypes/QtiIdentifier.php index 4136e9953..f658868ac 100644 --- a/src/qtism/common/datatypes/QtiIdentifier.php +++ b/src/qtism/common/datatypes/QtiIdentifier.php @@ -44,6 +44,9 @@ protected function checkType($value) if (is_string($value) !== true) { $msg = "The Identifier Datatype only accepts to store identifier values."; throw new InvalidArgumentException($msg); + } elseif ($value === '') { + $msg = "The Identifier Datatype do not accept empty strings as valid identifiers."; + throw new InvalidArgumentException($msg); } } diff --git a/test/qtismtest/common/datatypes/IdentifierTest.php b/test/qtismtest/common/datatypes/IdentifierTest.php index 7451c800f..558fd4b81 100644 --- a/test/qtismtest/common/datatypes/IdentifierTest.php +++ b/test/qtismtest/common/datatypes/IdentifierTest.php @@ -7,7 +7,18 @@ class IdentifierTest extends QtiSmTestCase { public function testWrongValue() { - $this->setExpectedException('\\InvalidArgumentException'); + $this->setExpectedException( + '\\InvalidArgumentException', + 'The Identifier Datatype only accepts to store identifier values.' + ); $float = new QtiIdentifier(1337); } -} \ No newline at end of file + + public function testEmptyIdentifier() { + $this->setExpectedException( + '\\InvalidArgumentException', + 'The Identifier Datatype do not accept empty strings as valid identifiers.' + ); + $float = new QtiIdentifier(''); + } +}