Skip to content

Commit

Permalink
No empty identifier allowed.
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Apr 28, 2016
1 parent 4a7e2f1 commit fc1cc18
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/qtism/common/datatypes/QtiIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
15 changes: 13 additions & 2 deletions test/qtismtest/common/datatypes/IdentifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

public function testEmptyIdentifier() {
$this->setExpectedException(
'\\InvalidArgumentException',
'The Identifier Datatype do not accept empty strings as valid identifiers.'
);
$float = new QtiIdentifier('');
}
}

0 comments on commit fc1cc18

Please sign in to comment.