config export

This commit is contained in:
Roland Gruber 2020-05-07 21:10:47 +02:00
parent a246fde0e2
commit ffd74d88e4
2 changed files with 128 additions and 1 deletions

View File

@ -542,6 +542,28 @@ class PDFStructure {
private $sections = array();
/**
* Returns an array representation of the structure.
*
* @return array export data
*/
public function export() {
$data = array();
$data['title'] = $this->title;
$data['foldingMarks'] = $this->foldingMarks;
$data['logo'] = $this->logo;
$data['sections'] = array();
foreach($this->sections as $section) {
$type = ($section instanceof PDFTextSection) ? 'text' : 'entry';
$sectionData = $section->export();
$data['sections'][] = array(
'type' => $type,
'data' => $sectionData
);
}
return $data;
}
/**
* Returns the logo file path.
*
@ -634,6 +656,15 @@ class PDFTextSection {
$this->text = $text;
}
/**
* Exports the section.
*
* @return string text
*/
public function export() {
return $this->getText();
}
/**
* Returns the text.
*
@ -664,6 +695,21 @@ class PDFEntrySection {
$this->title = $title;
}
/**
* Exports the section.
*
* @return array export data
*/
public function export() {
$data = array();
$data['title'] = $this->title;
$data['entries'] = array();
foreach($this->getEntries() as $entry) {
$data['entries'][] = $entry->getKey();
}
return $data;
}
/**
* Returns if the title is an attribute value.
*

View File

@ -1,4 +1,6 @@
<?php
use LAM\PDF\PDFSectionEntry;
use LAM\PDF\PDFTextSection;
use LAM\PDF\PDFEntrySection;
use LAM\PDF\PDFStructureReader;
@ -26,7 +28,7 @@ use PHPUnit\Framework\TestCase;
*/
include_once 'lam/lib/pdfstruct.inc';
include_once __DIR__ . '/../../lib/pdfstruct.inc';
/**
* Reads a sample PDF structure.
@ -114,4 +116,83 @@ class ReadStructureTest extends TestCase {
}
/**
* Tests PDFTextSection
*/
class PDFTextSectionTest extends TestCase {
public function testExport() {
$section = new PDFTextSection('sometext');
$data = $section->export();
$this->assertEquals('sometext', $data);
}
}
/**
* Tests PDFEntrySection
*/
class PDFEntrySectionTest extends TestCase {
public function testExport() {
$section = new PDFEntrySection('mytitle');
$section->setEntries(array(new PDFSectionEntry('key1'), new PDFSectionEntry('key2')));
$data = $section->export();
$expected = array(
'title' => 'mytitle',
'entries' => array('key1', 'key2')
);
$this->assertEquals($expected, $data);
}
}
/**
* Tests PDFStructure
*/
class PDFStructureTest extends TestCase {
public function testExport() {
$structure = new PDFStructure();
$structure->setFoldingMarks(PDFStructure::FOLDING_STANDARD);
$structure->setLogo('somelogo');
$structure->setTitle('mytitle');
$entrySection = new PDFEntrySection('sometitle');
$entrySection->setEntries(array(new PDFSectionEntry('key1')));
$structure->setSections(array(
new PDFTextSection('sometext'),
$entrySection
));
$data = $structure->export();
$expected = array(
'title' => 'mytitle',
'foldingMarks' => PDFStructure::FOLDING_STANDARD,
'logo' => 'somelogo',
'sections' => array(
array(
'type' => 'text',
'data' => 'sometext'
),
array(
'type' => 'entry',
'data' => array(
'title' => 'sometitle',
'entries' => array('key1')
)
)
)
);
$this->assertEquals($expected, $data);
}
}
?>