diff --git a/qtism/data/AssessmentItem.php b/qtism/data/AssessmentItem.php index 67fd9ef15..aec4ed8ff 100644 --- a/qtism/data/AssessmentItem.php +++ b/qtism/data/AssessmentItem.php @@ -222,7 +222,7 @@ public function __construct($identifier, $title, $timeDependent, $lang = '') */ public function setIdentifier($identifier) { - if (Format::isIdentifier($identifier, false)) { + if (Format::isNormalizedString($identifier)) { $this->identifier = $identifier; $this->notify(); } else { diff --git a/test/qtismtest/data/AssessmentItemTest.php b/test/qtismtest/data/AssessmentItemTest.php new file mode 100644 index 000000000..f3509fd94 --- /dev/null +++ b/test/qtismtest/data/AssessmentItemTest.php @@ -0,0 +1,136 @@ +subject = new AssessmentItem( + '123456789 asbcdżć', + 'title string', + true, + 'pinglish' + ); + } + + public function testAssessmentItemCreation(): void + { + $this->assertEquals('123456789 asbcdżć', $this->subject->getIdentifier()); + $this->assertEquals('title string', $this->subject->getTitle()); + $this->assertTrue($this->subject->isTimeDependent()); + $this->assertInstanceOf(ResponseDeclarationCollection::class, $this->subject->getResponseDeclarations()); + $this->assertInstanceOf(OutcomeDeclarationCollection::class, $this->subject->getOutcomeDeclarations()); + $this->assertInstanceOf(TemplateDeclarationCollection::class, $this->subject->getTemplateDeclarations()); + $this->assertInstanceOf(StylesheetCollection::class, $this->subject->getStylesheets()); + $this->assertInstanceOf(ModalFeedbackCollection::class, $this->subject->getModalFeedbacks()); + $this->assertEquals('assessmentItem', $this->subject->getQtiClassName()); + $this->assertInstanceOf(QtiComponentCollection::class, $this->subject->getComponents()); + } + + public function testAssessmentItemSetters(): void + { + $this->subject->setResponseProcessing(new ResponseProcessing()); + $this->subject->setToolName('toolName shorter 256 characters'); + $this->subject->setToolVersion('Tool version string shorter than 256 characters'); + + $this->subject->setItemBody( + new ItemBody('idString', 'classString', 'langString', 'labelString') + ); + + $this->assertInstanceOf(StylesheetCollection::class, $this->subject->getStylesheets()); + $this->assertInstanceOf(ItemBody::class, $this->subject->getItemBody()); + $this->assertInstanceOf(ResponseProcessing::class, $this->subject->getResponseProcessing()); + $this->assertInstanceOf(ModalFeedbackCollection::class, $this->subject->getModalFeedbacks()); + $this->assertEquals('assessmentItem', $this->subject->getQtiClassName()); + $this->assertInstanceOf(QtiComponentCollection::class, $this->subject->getComponents()); + $this->assertEquals('toolName shorter 256 characters', $this->subject->getToolName()); + $this->assertTrue($this->subject->hasToolName()); + $this->assertEquals('Tool version string shorter than 256 characters', $this->subject->getToolVersion()); + $this->assertTrue($this->subject->hasToolVersion()); + $this->assertInstanceOf(ItemBody::class, $this->subject->getItemBody()); + $this->assertTrue($this->subject->hasItemBody()); + } + + /** + * @dataProvider getInvalidAssessmentItemData + */ + public function testAssessmentItemValidation($identifier, $title, $timeDependent, $lang) + { + $this->expectException(InvalidArgumentException::class); + new AssessmentItem($identifier, $title, $timeDependent, $lang); + } + + public function setToolNameTest() + { + $this->expectException(InvalidArgumentException::class); + $this->subject->setToolName(str_repeat('a', 257)); + } + + public function setToolVersionTest() + { + $this->expectException(InvalidArgumentException::class); + $this->subject->setToolVersion(str_repeat('a', 257)); + } + + public function getInvalidAssessmentItemData() + { + return [ + 'Wrong identifier' => ["string \t with tab", 'title string', true ,'pinglish'], + 'Wrong title' => [ + '123456789 asbcdżć', + 1234, + true, + 'pinglish' + ], + 'Wrong isTimeDependent' => [ + '123456789 asbcdżć', + 'title string', + 'true', + 'pinglish' + ], + 'Wrong lang' => [ + '123456789 asbcdżć', + 'title string', + 'true', + true + ], + ]; + } +}