Example #1
0
 /**
  * @param DOMNode        $node
  * @param ReferenceTable $table
  *
  * @return mixed|void
  */
 public function parse(DOMNode $node, ReferenceTable &$table)
 {
     // Tr adds a new row
     $table->nextRow();
     $table->setColumn($table->getStartColumn());
     $table->resetContent();
     // Next element
     $this->next($node, $table);
 }
Example #2
0
 public function test_tr_element_gets_parsed()
 {
     $dom = new \DOMElement('tr', '');
     $table = new ReferenceTable();
     // Fake as if we are inside a <table>
     $table->setColumn($table->setStartColumn());
     $sheet = $this->mockSheet();
     $this->assertEquals(0, $table->getRow());
     $element = new TrElement($sheet);
     $element->parse($dom, $table);
     $this->assertEquals(1, $table->getRow());
 }
Example #3
0
 public function test_if_align_attribute_gets_translated_to_aligned_cells()
 {
     $table = new ReferenceTable();
     // Fake as if we are inside a <table>
     $table->setColumn($table->setStartColumn());
     // Fake as if we are inside a <tr>
     $table->nextRow();
     $node = new \DOMAttr('align', 'center');
     $sheet = $this->mockSheet();
     $attribute = new AlignAttribute($sheet);
     $attribute->parse($node, $table);
     $this->assertContains('center', $sheet->cell($table->getCoordinate())->align()->getHorizontal());
 }
Example #4
0
 public function test_if_style_attribute()
 {
     $table = new ReferenceTable();
     // Fake as if we are inside a <table>
     $table->setColumn($table->setStartColumn());
     // Fake as if we are inside a <tr>
     $table->nextRow();
     $node = new \DOMAttr('style', 'text-align:center;');
     $sheet = $this->mockSheet();
     $attribute = new StyleAttribute($sheet);
     $attribute->parse($node, $table);
     $this->assertContains('center', $sheet->cell($table->getCoordinate())->align()->getHorizontal());
 }
Example #5
0
 public function test_if_rowspan_attribute_gets_translated_to_a_merged_rows()
 {
     $table = new ReferenceTable();
     // Fake as if we are inside a <table>
     $table->setColumn($table->setStartColumn());
     // Fake as if we are inside a <tr>
     $table->nextRow();
     $node = new \DOMAttr('rowspan', 3);
     $sheet = $this->mockSheet();
     $attribute = new RowspanAttribute($sheet);
     $attribute->parse($node, $table);
     // 3 rows in the first column
     $this->assertContains('A1:A3', $sheet->getMergeCells());
 }
Example #6
0
 public function test_td_element_gets_parsed()
 {
     $dom = new \DOMElement('td', 'Patrick');
     $table = new ReferenceTable();
     // Fake as if we are inside a <table>
     $table->setColumn($table->setStartColumn());
     // Fake as if we are inside a <tr>
     $table->nextRow();
     $this->assertEquals('A', $table->getColumn());
     $sheet = $this->mockSheet();
     $element = new TdElement($sheet);
     $element->parse($dom, $table);
     // Flush the element
     $element->flush($table);
     $this->assertEquals('B', $table->getColumn());
 }
Example #7
0
 public function test_a_element_gets_parsed()
 {
     $doc = new DOMDocument();
     $dom = $doc->createElement('a');
     $dom->setAttribute('href', 'http://google.com');
     $sheet = $this->mockSheet();
     $table = new ReferenceTable();
     // Fake as if we are inside a <table>
     $table->setColumn($table->setStartColumn());
     // Fake as if we are inside a <tr>
     $table->nextRow();
     $element = new AElement($sheet);
     $element->parse($dom, $table);
     $this->assertEquals('http://google.com', $sheet->getCell($table->getCoordinate())->getHyperlink()->getUrl());
     // Text color should be blue
     $sheet->cell($table->getCoordinate(), function ($cell) {
         $this->assertEquals('0000ff', $cell->font()->getColor());
     });
 }