/**
  * Unmarshall a DOMElement object corresponding to an XHTML col element.
  * 
  * @param DOMElement $element A DOMElement object.
  * @return QtiComponent A Col object.
  * @throws UnmarshallingException
  */
 protected function unmarshall(DOMElement $element)
 {
     $component = new Col();
     if (($span = self::getDOMElementAttributeAs($element, 'span', 'integer')) !== null) {
         $component->setSpan($span);
     }
     self::fillBodyElement($component, $element);
     return $component;
 }
Пример #2
0
 public function testMarshall()
 {
     $th1 = new Th('firstname');
     $th1->setContent(new FlowCollection(array(new TextRun('First Name'))));
     $th1->setAxis('identity');
     $th1->setScope(TableCellScope::COL);
     $th2 = new Th('lastname');
     $th2->setContent(new FlowCollection(array(new TextRun('Last Name'))));
     $th2->setAxis('identity');
     $th2->setScope(TableCellScope::COL);
     $tr = new Tr(new TableCellCollection(array($th1, $th2)));
     $thead = new Thead(new TrCollection(array($tr)));
     $caption = new Caption();
     $strong = new Strong();
     $strong->setContent(new InlineCollection(array(new TextRun('people'))));
     $caption->setContent(new InlineCollection(array(new TextRun('Some '), $strong, new TextRun(' ...'))));
     $col1 = new Col();
     $col1->setSpan(1);
     $col2 = new Col();
     $col2->setSpan(1);
     $cols = new ColCollection(array($col1, $col2));
     $td1 = new Td();
     $td1->setContent(new FlowCollection(array(new TextRun('John'))));
     $td1->setRowspan(1);
     $td1->setColspan(1);
     $td1->setHeaders(new IdentifierCollection(array('firstname')));
     $td2 = new Td();
     $td2->setContent(new FlowCollection(array(new TextRun('Dunbar Smith Wayson'))));
     $td2->setHeaders(new IdentifierCollection(array('lastname')));
     $td2->setAbbr('Dunbar S.W.');
     $tr1 = new Tr(new TableCellCollection(array($td1, $td2)));
     $td1 = new Td();
     $td1->setContent(new FlowCollection(array(new TextRun('Flash'))));
     $td2 = new Td();
     $td2->setContent(new FlowCollection(array(new TextRun('Gordon'))));
     $tr2 = new Tr(new TableCellCollection(array($td1, $td2)));
     $tbody = new Tbody(new TrCollection(array($tr1, $tr2)));
     $tbodies = new TbodyCollection(array($tbody));
     $table = new Table($tbodies, 'my-table', 'qti table');
     $table->setSummary('Some people...');
     $table->setThead($thead);
     $table->setCaption($caption);
     $table->setCols($cols);
     $marshaller = $this->getMarshallerFactory('2.1.0')->createMarshaller($table);
     $element = $marshaller->marshall($table);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $expected = '<table summary="Some people..." id="my-table" class="qti table">';
     $expected .= '<caption>Some <strong>people</strong> ...</caption>';
     $expected .= '<col/>';
     $expected .= '<col/>';
     $expected .= '<thead>';
     $expected .= '<tr>';
     $expected .= '<th scope="col" axis="identity" id="firstname">First Name</th>';
     $expected .= '<th scope="col" axis="identity" id="lastname">Last Name</th>';
     $expected .= '</tr>';
     $expected .= '</thead>';
     $expected .= '<tbody>';
     $expected .= '<tr>';
     $expected .= '<td headers="firstname" rowspan="1" colspan="1">John</td>';
     $expected .= '<td headers="lastname" abbr="Dunbar S.W.">Dunbar Smith Wayson</td>';
     $expected .= '</tr>';
     $expected .= '<tr>';
     $expected .= '<td>Flash</td>';
     $expected .= '<td>Gordon</td>';
     $expected .= '</tr>';
     $expected .= '</tbody>';
     $expected .= '</table>';
     $this->assertEquals($expected, $dom->saveXML($element));
 }