public function convert(BaseQuestionType $questionType, $interactionIdentifier, $interactionLabel) { /** @var shorttext $question */ $question = $questionType; // Extra text that can't be mapped since we are in textEntryInteraction which does not have prompt $this->extraContent = $question->get_stimulus(); $interaction = new TextEntryInteraction($interactionIdentifier); $interaction->setLabel($interactionLabel); // Build placeholder $placeholderText = $question->get_placeholder(); if (!empty($placeholderText)) { $interaction->setPlaceholderText($placeholderText); } // Use 15 as default $interaction->setExpectedLength($question->get_max_length() ? $question->get_max_length() : 15); // Build those validation $isCaseSensitive = $question->get_case_sensitive() === null ? true : $question->get_case_sensitive(); $validationBuilder = new ShorttextValidationBuilder($isCaseSensitive); list($responseDeclaration, $responseProcessing) = $validationBuilder->buildValidation($interactionIdentifier, $question->get_validation(), $isCaseSensitive); // TODO: This is a freaking hack // Wrap this interaction in a block since our `shorttext` meant to be blocky and not inline $div = new Div(); $content = new FlowCollection(); $content->attach($interaction); $div->setContent($content); return [$div, $responseDeclaration, $responseProcessing]; }
public function testMarshallMaximal() { $textEntryInteraction = new TextEntryInteraction('RESPONSE'); $textEntryInteraction->setBase(2); $textEntryInteraction->setStringIdentifier('mystring'); $textEntryInteraction->setExpectedLength(35); $textEntryInteraction->setPatternMask('[0-9]+'); $textEntryInteraction->setPlaceholderText('input here...'); $element = $this->getMarshallerFactory()->createMarshaller($textEntryInteraction)->marshall($textEntryInteraction); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<textEntryInteraction responseIdentifier="RESPONSE" base="2" stringIdentifier="mystring" expectedLength="35" patternMask="[0-9]+" placeholderText="input here..."/>', $dom->saveXML($element)); }