public function testBuildingWithNewAtomicRenderer()
 {
     /**
      * ___________
      * |test-value|
      * |__________|
      */
     $oneCellTable = new NewAtomicType("test-value");
     ob_start();
     ?>
         <table>
             <tr>
                 <td colspan="1" rowspan="1">test-value</td>
             </tr>
         </table>
     <?php 
     $expectedHTML = ob_get_clean();
     //add support of a new atomic value
     $this->builder->addAtomicValueRenderer(NewAtomicType::class, new NewAtomicTypeRenderer());
     $renderer = $this->builder->buildRenderer();
     $renderedHTML = $renderer->renderHTMLBasedOn($oneCellTable);
     $this->assertXmlStringEqualsXmlString($expectedHTML, $renderedHTML);
 }
示例#2
0
<?php

/**
 * This file is part of the TableRenderer library.
 *
 * @author Łukasz Makuch <*****@*****.**>
 * @license MIT http://opensource.org/licenses/MIT
 */
require_once __DIR__ . "/../vendor/autoload.php";
use lukaszmakuch\ObjectAttributeContainer\Impl\ObjectAttributeContainerImpl;
use lukaszmakuch\TableRenderer\HorizontalContainer;
use lukaszmakuch\TableRenderer\HTMLRenderer\HTMLRendererBuilder;
use lukaszmakuch\TableRenderer\VerticalContainer;
use lukaszmakuch\TableRenderer\TextValue;
//will hold attributes used by the HTML renderer
$attrs = new ObjectAttributeContainerImpl();
//table with a border attribute assigned for the HTML renderer
$tableModel = $attrs->addObjAttrs((new HorizontalContainer())->add((new VerticalContainer())->add((new HorizontalContainer())->add(new TextValue("tree"))->add(new TextValue("structures")))->add($attrs->addObjAttrs(new TextValue("may"), ["attrs" => ["style" => "background-color: #d33; color: #fff"]]))->add((new HorizontalContainer())->add(new TextValue("be"))->add(new TextValue("rendered"))->add(new TextValue("as"))))->add((new VerticalContainer())->add(new TextValue("a"))->add(new TextValue("table"))), ["attrs" => ["border" => 1]]);
//get the builder
$rendererBuilder = new HTMLRendererBuilder();
//provide source of additional attributes
$rendererBuilder->setAttributeContainer($attrs);
//build the renderer
$renderer = $rendererBuilder->buildRenderer();
//check how does this table look rendered in HTML
echo $renderer->renderHTMLBasedOn($tableModel);