public function testNoChildComponents() { $baseValue = new BaseValue(BaseType::FLOAT, 10); $iterator = new QtiComponentIterator($baseValue); $this->assertFalse($iterator->valid()); $this->assertSame($iterator->current(), null); // Just try to iterate again, just for fun... $iterator->next(); $this->assertFalse($iterator->valid()); $this->assertTrue($iterator->current() === null); }
/** * Seek for the position of $component in the AssessmentTest tree. * * @param QtiComponent $component A QtiComponent object which is supposed to be in the AssessmentTest tree. * @return integer The position of $component in the AssessmentTest tree. * @throws OutOfBoundsException If no such $component could be found in the AssessmentTest tree. */ public function seekPosition(QtiComponent $component) { if (($position = $this->getPositionFromComponentStore($component)) !== false) { // Already explored. return $position; } // We have to find it! while ($this->iterator->valid() === true) { $current = $this->iterator->current(); $newPosition = $this->addToComponentStore($current); $this->iterator->next(); if ($current === $component) { return $newPosition; } } $class = $component->getQtiClassName(); $msg = "Unable to find the position of a QtiComponent with QTI class '{$class}'."; throw new OutOfBoundsException($msg); }