stringValidator = UtilityFactory::getInstance()->newValidatorFactory()->newStringValidator();
}
public function testCanConstruct() {
$this->assertInstanceOf(
'\SMW\MediaWiki\Renderer\HtmlTableRenderer',
new HtmlTableRenderer()
);
}
public function testAddHeaderItem() {
$instance = new HtmlTableRenderer();
$instance->addHeaderItem( 'span', 'lala' );
$this->stringValidator->assertThatStringContains(
'lala',
$instance->getHeaderItems()
);
}
public function testAddTableHeader() {
$instance = new HtmlTableRenderer();
$instance->addHeader( 'lala' );
$this->stringValidator->assertThatStringContains(
'
lala | ',
$instance->getHtml()
);
$instance = new HtmlTableRenderer( true );
$instance->addHeader( 'lila' );
$this->stringValidator->assertThatStringContains(
'| lila |
',
$instance->getHtml()
);
}
public function testAddTableRow() {
$instance = new HtmlTableRenderer();
$instance
->addCell( 'lala', [ 'class' => 'foo' ] )
->addRow()
->addCell( 'lula' )
->addRow();
$this->stringValidator->assertThatStringContains(
'| lala |
| lula |
',
$instance->getHtml()
);
$instance = new HtmlTableRenderer();
$instance
->setHtmlContext( true )
->addCell( 'lila' )
->addRow();
$this->stringValidator->assertThatStringContains(
'| lila |
',
$instance->getHtml()
);
}
public function testStandardTable() {
$instance = new HtmlTableRenderer();
$instance
->addCell( 'lala', [ 'rel' => 'tuuu' ] )
->addRow( [ 'class' => 'foo' ] );
$this->stringValidator->assertThatStringContains(
'',
$instance->getHtml()
);
$instance = new HtmlTableRenderer();
$instance
->addHeader( 'lula' )
->addCell( 'lala' )
->addRow();
$this->stringValidator->assertThatStringContains(
'',
$instance->getHtml()
);
$instance = new HtmlTableRenderer( true );
$instance
->addHeader( 'lula' )
->addCell( 'lala' )
->addRow();
$this->stringValidator->assertThatStringContains(
'',
$instance->getHtml()
);
}
public function testTransposedTable() {
$instance = new HtmlTableRenderer();
// We need a dedicated header definition to support a table transpose
$instance
->transpose( true )
->addHeader( 'Foo' )->addHeader( 'Bar' )
->addCell( 'lala', [ 'class' => 'foo' ] )
->addRow()
->addCell( 'lula', [ 'rel' => 'tuuu' ] )->addCell( 'lila' )
->addRow();
$this->stringValidator->assertThatStringContains(
'',
$instance->getHtml()
);
$instance = new HtmlTableRenderer( true );
$instance
->transpose( true )
->addHeader( 'Foo' )->addHeader( 'Bar' )
->addCell( 'lala', [ 'class' => 'foo' ] )
->addRow()
->addCell( 'lula' )->addCell( 'lila' )
->addRow();
$this->stringValidator->assertThatStringContains( // @codingStandardsIgnoreStart phpcs, ignore --sniffs=Generic.Files.LineLength
'', // @codingStandardsIgnoreEnd
$instance->getHtml()
);
}
public function testEmptyTable() {
$instance = new HtmlTableRenderer();
$instance
->addCell()
->addRow();
$this->assertEmpty(
$instance->getHtml()
);
}
}