diff --git a/.atoum.php b/.atoum.php
deleted file mode 100644
index c4fce602..00000000
--- a/.atoum.php
+++ /dev/null
@@ -1,60 +0,0 @@
-addDefaultReport();
-
-/*
-LOGO
-
-// This will add the atoum logo before each run.
-$report->addField(new atoum\report\fields\runner\atoum\logo());
-
-// This will add a green or red logo after each run depending on its status.
-$report->addField(new atoum\report\fields\runner\result\logo());
-*/
-
-/*
-CODE COVERAGE SETUP
-*/
-// Please replace in next line "Project Name" by your project name and "/path/to/destination/directory" by your destination directory path for html files.
-$coverageField = new atoum\report\fields\runner\coverage\html('PdfParser', 'coverage');
-
-// Please replace in next line http://url/of/web/site by the root url of your code coverage web site.
-$coverageField->setRootUrl('http://test.local');
-
-$report->addField($coverageField);
-/**/
-
-/*
-TEST GENERATOR SETUP
-
-$testGenerator = new atoum\test\generator();
-
-// Please replace in next line "/path/to/your/tests/units/classes/directory" by your unit test's directory.
-$testGenerator->setTestClassesDirectory('path/to/your/tests/units/classes/directory');
-
-// Please replace in next line "your\project\namespace\tests\units" by your unit test's namespace.
-$testGenerator->setTestClassNamespace('your\project\namespace\tests\units');
-
-// Please replace in next line "/path/to/your/classes/directory" by your classes directory.
-$testGenerator->setTestedClassesDirectory('path/to/your/classes/directory');
-
-// Please replace in next line "your\project\namespace" by your project namespace.
-$testGenerator->setTestedClassNamespace('your\project\namespace');
-
-// Please replace in next line "path/to/your/tests/units/runner.php" by path to your unit test's runner.
-$testGenerator->setRunnerPath('path/to/your/tests/units/runner.php');
-
-$script->getRunner()->setTestGenerator($testGenerator);
-*/
diff --git a/.gitignore b/.gitignore
index a7e9973d..5528f912 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,7 +2,6 @@
/coverage/*
/samples/*
/vendor/*
-/test*
/xdebug/*
/composer.phar
/composer
diff --git a/.php_cs b/.php_cs
index b0f56713..cde339a6 100644
--- a/.php_cs
+++ b/.php_cs
@@ -18,5 +18,7 @@ return PhpCsFixer\Config::create()
->files()
->in(__DIR__ . '/samples')
->in(__DIR__ . '/src')
+ ->in(__DIR__ . '/test')
+ ->in(__DIR__ . '/tests')
->name('*.php')
- );
\ No newline at end of file
+ );
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
new file mode 100644
index 00000000..7eb104be
--- /dev/null
+++ b/.scrutinizer.yml
@@ -0,0 +1,11 @@
+# For more information about code coverage
+# See: https://scrutinizer-ci.com/docs/build/code_coverage
+build:
+ nodes:
+ coverage:
+ tests:
+ override:
+ - command: vendor/bin/phpunit --coverage-clover coverage/clover.xml
+ coverage:
+ file: coverage/clover.xml
+ format: clover
diff --git a/.travis.yml b/.travis.yml
index 8cfb6554..400c3814 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,9 +18,11 @@ jobs:
include:
- php: 7.2
env: COMPOSER_FLAGS="--prefer-lowest"
+ - php: 7.4
+ env: COVERAGE_FLAGS="--coverage-clover coverage/clover.xml"
install:
- composer self-update
- composer update --prefer-dist --no-progress --no-suggest --optimize-autoloader $COMPOSER_FLAGS
-script: ./vendor/bin/atoum -d src/Smalot/PdfParser/Tests/ -ncc
+script: vendor/bin/phpunit $COVERAGE_FLAGS
diff --git a/composer.json b/composer.json
index a66171aa..2956746e 100644
--- a/composer.json
+++ b/composer.json
@@ -21,7 +21,7 @@
"tecnickcom/tcpdf": "^6.2.22"
},
"require-dev": {
- "atoum/atoum": "^3.1",
+ "phpunit/phpunit": "^5.7.27|^6",
"friendsofphp/php-cs-fixer": "^2.16.3"
},
"autoload": {
@@ -29,6 +29,12 @@
"Smalot\\PdfParser\\": "src/"
}
},
+ "autoload-dev": {
+ "psr-4": {
+ "Test\\Smalot\\PdfParser\\": "test/",
+ "Tests\\Smalot\\PdfParser\\": "tests/"
+ }
+ },
"config": {
"process-timeout": 1200
}
diff --git a/phpunit.xml b/phpunit.xml
new file mode 100644
index 00000000..c7dadfa5
--- /dev/null
+++ b/phpunit.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ tests
+
+
+
+
+ src
+
+
+
diff --git a/src/Smalot/PdfParser/Element.php b/src/Smalot/PdfParser/Element.php
index 801dade5..805a0c51 100644
--- a/src/Smalot/PdfParser/Element.php
+++ b/src/Smalot/PdfParser/Element.php
@@ -51,9 +51,6 @@ class Element
*/
protected $document = null;
- /**
- * @var mixed
- */
protected $value = null;
/**
diff --git a/src/Smalot/PdfParser/Page.php b/src/Smalot/PdfParser/Page.php
index 1b9409dd..cc7085f0 100644
--- a/src/Smalot/PdfParser/Page.php
+++ b/src/Smalot/PdfParser/Page.php
@@ -35,9 +35,6 @@
use Smalot\PdfParser\Element\ElementNull;
use Smalot\PdfParser\Element\ElementXRef;
-/**
- * Class Page
- */
class Page extends PDFObject
{
/**
@@ -272,16 +269,13 @@ public function getTextArray(self $page = null)
return [];
}
- /*
+ /**
* Gets all the text data with its internal representation of the page.
*
* @return array An array with the data and the internal representation
- *
*/
-
public function extractRawData()
{
- $text = $this->getText();
/*
* Now you can get the complete content of the object with the text on it
*/
@@ -313,14 +307,13 @@ public function extractRawData()
return $extractedData;
}
- /*
+ /**
* Gets all the decoded text data with it internal representation from a page.
*
* @param array $extractedRawData the extracted data return by extractRawData or
* null if extractRawData should be called
*
* @return array An array with the data and the internal representation
- *
*/
public function extractDecodedRawData($extractedRawData = null)
{
@@ -331,14 +324,13 @@ public function extractDecodedRawData($extractedRawData = null)
$currentFont = null;
foreach ($extractedRawData as &$command) {
if ('Tj' == $command['o'] or 'TJ' == $command['o']) {
- $text = [];
$data = $command['c'];
if (!\is_array($data)) {
if (isset($currentFont)) {
$tmpText = $currentFont->decodeOctal($data);
//$tmpText = $currentFont->decodeHexadecimal($tmpText, false);
}
- $tmpText = $tjText = str_replace(
+ $tmpText = str_replace(
['\\\\', '\(', '\)', '\n', '\r', '\t', '\ '],
['\\', '(', ')', "\n", "\r", "\t", ' '],
$tmpText
@@ -360,7 +352,7 @@ public function extractDecodedRawData($extractedRawData = null)
$decodedText = $currentFont->decodeOctal($tmpText);
//$tmpText = $currentFont->decodeHexadecimal($tmpText, false);
}
- $decodedText = $tjText = str_replace(
+ $decodedText = str_replace(
['\\\\', '\(', '\)', '\n', '\r', '\t', '\ '],
['\\', '(', ')', "\n", "\r", "\t", ' '],
$decodedText
@@ -382,18 +374,17 @@ public function extractDecodedRawData($extractedRawData = null)
return $extractedRawData;
}
- /*
+ /**
* Gets just the Text commands that are involved in text positions and
* Text Matrix (Tm)
*
* It extract just the PDF commands that are involved with text positions, and
* the Text Matrix (Tm). These are: BT, ET, TL, Td, TD, Tm, T*, Tj, ', ", and TJ
*
- * @param array $extractedDecodedRawData The data extracted by extractDecodeRawData
- if it is null, the method extractDecodeRawData is called.
+ * @param array $extractedDecodedRawData The data extracted by extractDecodeRawData.
+ * If it is null, the method extractDecodeRawData is called.
*
* @return array An array with the text command of the page
- *
*/
public function getDataCommands($extractedDecodedRawData = null)
{
@@ -527,7 +518,7 @@ public function getDataCommands($extractedDecodedRawData = null)
return $extractedData;
}
- /*
+ /**
* Gets the Text Matrix of the text in the page
*
* Return an array where every item is an array where the first item is the
@@ -536,12 +527,11 @@ public function getDataCommands($extractedDecodedRawData = null)
* text. The first 4 numbers has to be with Scalation, Rotation and Skew of the text.
*
* @param array $dataCommands the data extracted by getDataCommands
- * if null getDataCommands is called.
+ * if null getDataCommands is called
*
- * @return array An array with the data of the page including the Tm information
- * of any text in the page.
+ * @return array an array with the data of the page including the Tm information
+ * of any text in the page
*/
-
public function getDataTm($dataCommands = null)
{
if (!isset($dataCommands) or !$dataCommands) {
@@ -731,17 +721,17 @@ public function getDataTm($dataCommands = null)
return $extractedData;
}
- /*
+ /**
* Gets text data that are around the given coordinates (X,Y)
*
* If the text is in near the given coordinates (X,Y) (or the TM info),
* the text is returned. The extractedData return by getDataTm, could be use to see
* where is the coordinates of a given text, using the TM info for it.
*
- * @param float $x The X value of the coordinate to search for. if null
- * just the Y value is considered (same Row)
- * @param float $y The Y value of the coordinate to search for
- * just the X value is considered (same column)
+ * @param float $x The X value of the coordinate to search for. if null
+ * just the Y value is considered (same Row)
+ * @param float $y The Y value of the coordinate to search for
+ * just the X value is considered (same column)
* @param float $xError The value less or more to consider an X to be "near"
* @param float $yError The value less or more to consider an Y to be "near"
*
diff --git a/src/Smalot/PdfParser/Tests/Units/Document.php b/src/Smalot/PdfParser/Tests/Units/Document.php
deleted file mode 100644
index 31fbb524..00000000
--- a/src/Smalot/PdfParser/Tests/Units/Document.php
+++ /dev/null
@@ -1,182 +0,0 @@
-
- * @date 2017-01-03
- *
- * @license LGPLv3
- * @url
- *
- * PdfParser is a pdf library written in PHP, extraction oriented.
- * Copyright (C) 2017 - Sébastien MALOT
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.
- * If not, see .
- */
-
-namespace Smalot\PdfParser\Tests\Units;
-
-use mageekguy\atoum;
-
-/**
- * Class Document
- */
-class Document extends atoum\test
-{
- public function testSetObjects()
- {
- $document = new \Smalot\PdfParser\Document();
- $object = new \Smalot\PdfParser\PDFObject($document);
- // Obj #1 is missing
- $this->assert->variable($document->getObjectById(1))->isNull();
- $document->setObjects([1 => $object]);
- // Obj #1 exists
- $this->assert->object($document->getObjectById(1))->isInstanceOf('\Smalot\PdfParser\PDFObject');
-
- $content = '<>';
- $header = \Smalot\PdfParser\Header::parse($content, $document);
- $object = new \Smalot\PdfParser\PDFObject($document, $header);
- $document->setObjects([2 => $object]);
- // Obj #1 is missing
- $this->assert->assert->variable($document->getObjectById(1))->isNull();
- // Obj #2 exists
- $this->assert->object($document->getObjectById(2))->isInstanceOf('\Smalot\PdfParser\PDFObject');
- }
-
- public function testGetObjects()
- {
- $document = new \Smalot\PdfParser\Document();
- $object1 = new \Smalot\PdfParser\PDFObject($document);
- $content = '<>unparsed content';
- $header = \Smalot\PdfParser\Header::parse($content, $document);
-
- $object2 = new \Smalot\PdfParser\Page($document, $header);
- $document->setObjects([1 => $object1, 2 => $object2]);
-
- $this->assert->integer(\count($objects = $document->getObjects()))->isEqualTo(2);
- $this->assert->object($objects[1])->isInstanceOf('\Smalot\PdfParser\PDFObject');
- $this->assert->object($objects[2])->isInstanceOf('\Smalot\PdfParser\PDFObject');
- $this->assert->object($objects[2])->isInstanceOf('\Smalot\PdfParser\Page');
- }
-
- public function testDictionary()
- {
- $document = new \Smalot\PdfParser\Document();
- $this->assert->integer(\count($objects = $document->getDictionary()))->isEqualTo(0);
- $object1 = new \Smalot\PdfParser\PDFObject($document);
- $content = '<>';
- $header = \Smalot\PdfParser\Header::parse($content, $document);
- $object2 = new \Smalot\PdfParser\Page($document, $header);
- $document->setObjects([1 => $object1, 2 => $object2]);
- $this->assert->integer(\count($objects = $document->getDictionary()))->isEqualTo(1);
- $this->assert->integer(\count($objects['Page']))->isEqualTo(1);
- $this->assert->integer($objects['Page'][2])->isEqualTo(2);
- }
-
- public function testGetObjectsByType()
- {
- $document = new \Smalot\PdfParser\Document();
- $object1 = new \Smalot\PdfParser\PDFObject($document);
- $content = '<>';
- $header = \Smalot\PdfParser\Header::parse($content, $document);
- $object2 = new \Smalot\PdfParser\Page($document, $header);
- $document->setObjects([1 => $object1, 2 => $object2]);
- $this->assert->integer(\count($objects = $document->getObjectsByType('Page')))->isEqualTo(1);
- $this->assert->object($objects[2])->isInstanceOf('\Smalot\PdfParser\PDFObject');
- $this->assert->object($objects[2])->isInstanceOf('\Smalot\PdfParser\Page');
- }
-
- public function testGetPages()
- {
- // Missing catalog
- $document = new \Smalot\PdfParser\Document();
- try {
- $pages = $document->getPages();
- $this->assert->boolean($pages)->isEqualTo(false);
- } catch (\Exception $e) {
- $this->assert->object($e)->isInstanceOf('\Exception');
- }
-
- // Listing pages from type Page
- $content = '<>';
- $header = \Smalot\PdfParser\Header::parse($content, $document);
- $object1 = new \Smalot\PdfParser\Page($document, $header);
- $header = \Smalot\PdfParser\Header::parse($content, $document);
- $object2 = new \Smalot\PdfParser\Page($document, $header);
- $document->setObjects([1 => $object1, 2 => $object2]);
- $pages = $document->getPages();
- $this->assert->integer(\count($pages))->isEqualTo(2);
- $this->assert->object($pages[0])->isInstanceOf('\Smalot\PdfParser\Page');
- $this->assert->object($pages[1])->isInstanceOf('\Smalot\PdfParser\Page');
-
- // Listing pages from type Pages (kids)
- $content = '<>';
- $header = \Smalot\PdfParser\Header::parse($content, $document);
- $object1 = new \Smalot\PdfParser\Page($document, $header);
- $header = \Smalot\PdfParser\Header::parse($content, $document);
- $object2 = new \Smalot\PdfParser\Page($document, $header);
- $header = \Smalot\PdfParser\Header::parse($content, $document);
- $object3 = new \Smalot\PdfParser\Page($document, $header);
- $content = '<>';
- $header = \Smalot\PdfParser\Header::parse($content, $document);
- $object4 = new \Smalot\PdfParser\Pages($document, $header);
- $content = '<>';
- $header = \Smalot\PdfParser\Header::parse($content, $document);
- $object5 = new \Smalot\PdfParser\Pages($document, $header);
- $document->setObjects(
- ['1_0' => $object1, '2_0' => $object2, '3_0' => $object3, '4_0' => $object4, '5_0' => $object5]
- );
- $pages = $document->getPages();
- $this->assert->integer(\count($pages))->isEqualTo(3);
- $this->assert->object($pages[0])->isInstanceOf('\Smalot\PdfParser\Page');
- $this->assert->object($pages[1])->isInstanceOf('\Smalot\PdfParser\Page');
- $this->assert->object($pages[2])->isInstanceOf('\Smalot\PdfParser\Page');
-
- // Listing pages from type Catalog
- $content = '<>';
- $header = \Smalot\PdfParser\Header::parse($content, $document);
- $object1 = new \Smalot\PdfParser\Page($document, $header);
- $header = \Smalot\PdfParser\Header::parse($content, $document);
- $object2 = new \Smalot\PdfParser\Page($document, $header);
- $header = \Smalot\PdfParser\Header::parse($content, $document);
- $object3 = new \Smalot\PdfParser\Page($document, $header);
- $content = '<>';
- $header = \Smalot\PdfParser\Header::parse($content, $document);
- $object4 = new \Smalot\PdfParser\Pages($document, $header);
- $content = '<>';
- $header = \Smalot\PdfParser\Header::parse($content, $document);
- $object5 = new \Smalot\PdfParser\Pages($document, $header);
- $content = '<>';
- $header = \Smalot\PdfParser\Header::parse($content, $document);
- $object6 = new \Smalot\PdfParser\Pages($document, $header);
- $document->setObjects(
- [
- '1_0' => $object1,
- '2_0' => $object2,
- '3_0' => $object3,
- '4_0' => $object4,
- '5_0' => $object5,
- '6_0' => $object6,
- ]
- );
- $pages = $document->getPages();
- $this->assert->integer(\count($pages))->isEqualTo(3);
- $this->assert->object($pages[0])->isInstanceOf('\Smalot\PdfParser\Page');
- $this->assert->object($pages[1])->isInstanceOf('\Smalot\PdfParser\Page');
- $this->assert->object($pages[2])->isInstanceOf('\Smalot\PdfParser\Page');
- }
-}
diff --git a/src/Smalot/PdfParser/Tests/Units/Element.php b/src/Smalot/PdfParser/Tests/Units/Element.php
deleted file mode 100644
index 00cc28ae..00000000
--- a/src/Smalot/PdfParser/Tests/Units/Element.php
+++ /dev/null
@@ -1,152 +0,0 @@
-
- * @date 2017-01-03
- *
- * @license LGPLv3
- * @url
- *
- * PdfParser is a pdf library written in PHP, extraction oriented.
- * Copyright (C) 2017 - Sébastien MALOT
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.
- * If not, see .
- */
-
-namespace Smalot\PdfParser\Tests\Units;
-
-use mageekguy\atoum;
-
-/**
- * Class Element
- */
-class Element extends atoum\test
-{
- public function testParse()
- {
- $document = new \Smalot\PdfParser\Document([]);
-
- // Only_values = false.
- $content = '/NameType /FlateDecode
- /Contents[4 0 R 42]/Fonts<>/NullType
- null/StringType(hello)/DateType(D:20130901235555+02\'00\')/XRefType 2 0 R
- /NumericType 8/HexaType<0020>/BooleanType false';
- $offset = 0;
- $elements = \Smalot\PdfParser\Element::parse($content, $document, $offset, false);
-
- $this->assert->array($elements)->hasKey('NameType');
- $this->assert->object($elements['NameType'])->isInstanceOf('\Smalot\PdfParser\Element\ElementName');
- $this->assert->string($elements['NameType']->getContent())->isEqualTo('FlateDecode');
-
- $this->assert->boolean(\array_key_exists('Contents', $elements))->isEqualTo(true);
- $this->assert->object($elements['Contents'])->isInstanceOf('\Smalot\PdfParser\Element\ElementArray');
- $this->assert->boolean($elements['Contents']->contains(42))->isEqualTo(true);
-
- $this->assert->boolean(\array_key_exists('Fonts', $elements))->isEqualTo(true);
- $this->assert->object($elements['Fonts'])->isInstanceOf('\Smalot\PdfParser\Header');
-
- $this->assert->boolean(\array_key_exists('NullType', $elements))->isEqualTo(true);
- $this->assert->object($elements['NullType'])->isInstanceOf('\Smalot\PdfParser\Element\ElementNull');
- $this->assert->castToString($elements['NullType'])->isEqualTo('null');
-
- $this->assert->boolean(\array_key_exists('StringType', $elements))->isEqualTo(true);
- $this->assert->object($elements['StringType'])->isInstanceOf('\Smalot\PdfParser\Element\ElementString');
- $this->assert->string($elements['StringType']->getContent())->isEqualTo('hello');
-
- $this->assert->boolean(\array_key_exists('DateType', $elements))->isEqualTo(true);
- $this->assert->object($elements['DateType'])->isInstanceOf('\Smalot\PdfParser\Element\ElementDate');
-// $this->assert->castToString($elements['DateType'])->isEqualTo('2013-09-01T23:55:55+02:00');
-
- $this->assert->boolean(\array_key_exists('XRefType', $elements))->isEqualTo(true);
- $this->assert->object($elements['XRefType'])->isInstanceOf('\Smalot\PdfParser\Element\ElementXRef');
- $this->assert->string($elements['XRefType']->getId())->isEqualTo('2_0');
-
- $this->assert->boolean(\array_key_exists('NumericType', $elements))->isEqualTo(true);
- $this->assert->object($elements['NumericType'])->isInstanceOf('\Smalot\PdfParser\Element\ElementNumeric');
- $this->assert->castToString($elements['NumericType'])->isEqualTo('8');
-
- $this->assert->boolean(\array_key_exists('HexaType', $elements))->isEqualTo(true);
- $this->assert->object($elements['HexaType'])->isInstanceOf('\Smalot\PdfParser\Element\ElementString');
- $this->assert->string($elements['HexaType']->getContent())->isEqualTo(' ');
-
- $this->assert->boolean(\array_key_exists('BooleanType', $elements))->isEqualTo(true);
- $this->assert->object($elements['BooleanType'])->isInstanceOf('\Smalot\PdfParser\Element\ElementBoolean');
- $this->assert->boolean($elements['BooleanType']->getContent())->isEqualTo(false);
-
- // Only_values = true.
- $content = '/NameType /FlateDecode';
- $offset = 0;
- $elements = \Smalot\PdfParser\Element::parse($content, $document, $offset, true);
- $this->assert->array($elements)->hasSize(2);
- $this->assert->integer($offset)->isEqualTo(22);
-
- // Test error.
- $content = '/NameType /FlateDecode $$$';
- $offset = 0;
- $elements = \Smalot\PdfParser\Element::parse($content, $document, $offset, false);
- $this->assert->array($elements)->hasSize(1);
- $this->assert->integer($offset)->isEqualTo(22);
- $this->assert->string(key($elements))->isEqualTo('NameType');
- $this->assert->object(current($elements))->isInstanceOf('\Smalot\PdfParser\Element\ElementName');
-
- $content = '/NameType $$$';
- $offset = 0;
- $elements = \Smalot\PdfParser\Element::parse($content, $document, $offset, false);
- $this->assert->integer($offset)->isEqualTo(0);
- $this->assert->array($elements)->isEmpty();
-
- /*$this->assert->boolean(array_key_exists('NameType', $elements))->isEqualTo(true);
- $this->assert->boolean($elements['NameType'])->isInstanceOf('\Smalot\PdfParser\Element\ElementName)->isEqualTo(true);
- $this->assert->string($elements['NameType']->getContent())->isEqualTo('FlateDecode');*/
- }
-
- public function testGetContent()
- {
- $element = new \Smalot\PdfParser\Element(42);
- $content = $element->getContent();
- $this->assert->integer($content)->isEqualTo(42);
-
- $element = new \Smalot\PdfParser\Element([4, 2]);
- $content = $element->getContent();
- $this->assert->array($content)->hasSize(2);
- }
-
- public function testEquals()
- {
- $element = new \Smalot\PdfParser\Element(2);
-
- $this->assert->boolean($element->equals(2))->isEqualTo(true);
- $this->assert->boolean($element->equals(8))->isEqualTo(false);
- }
-
- public function testContains()
- {
- $val_4 = new \Smalot\PdfParser\Element(4);
- $val_2 = new \Smalot\PdfParser\Element(2);
- $element = new \Smalot\PdfParser\Element([$val_4, $val_2]);
-
- $this->assert->boolean($element->contains(2))->isEqualTo(true);
- $this->assert->boolean($element->contains(8))->isEqualTo(false);
- }
-
- public function test__toString()
- {
- $element = new \Smalot\PdfParser\Element(2);
- $this->assert->castToString($element)->isEqualTo('2');
- }
-}
diff --git a/src/Smalot/PdfParser/Tests/Units/Element/ElementArray.php b/src/Smalot/PdfParser/Tests/Units/Element/ElementArray.php
deleted file mode 100644
index 64af5e94..00000000
--- a/src/Smalot/PdfParser/Tests/Units/Element/ElementArray.php
+++ /dev/null
@@ -1,187 +0,0 @@
-
- * @date 2017-01-03
- *
- * @license LGPLv3
- * @url
- *
- * PdfParser is a pdf library written in PHP, extraction oriented.
- * Copyright (C) 2017 - Sébastien MALOT
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.
- * If not, see .
- */
-
-namespace Smalot\PdfParser\Tests\Units\Element;
-
-use mageekguy\atoum;
-use Smalot\PdfParser\Document;
-use Smalot\PdfParser\Header;
-use Smalot\PdfParser\Page;
-
-/**
- * Class ElementArray
- */
-class ElementArray extends atoum\test
-{
- public function testParse()
- {
- $document = new \Smalot\PdfParser\Document([]);
-
- // Skipped.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementArray::parse('ABC', $document, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementArray::parse(' / [ 4 2 ] ', $document, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementArray::parse(' 0 [ 4 2 ] ', $document, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementArray::parse(" 0 \n [ 4 2 ] ", $document, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
-
- // Valid.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementArray::parse(' [ 4 2 ] ', $document, $offset);
- $this->assert->boolean($element->contains(4))->isEqualTo(true);
- $this->assert->boolean($element->contains(2))->isEqualTo(true);
- $this->assert->boolean($element->contains(8))->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(8);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementArray::parse(' [ 4 2 ]', $document, $offset);
- $this->assert->boolean($element->contains(4))->isEqualTo(true);
- $this->assert->boolean($element->contains(2))->isEqualTo(true);
- $this->assert->boolean($element->contains(8))->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(8);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementArray::parse('[ 4 2 ]', $document, $offset);
- $this->assert->boolean($element->contains(4))->isEqualTo(true);
- $this->assert->boolean($element->contains(2))->isEqualTo(true);
- $this->assert->boolean($element->contains(8))->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(7);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementArray::parse(" \n [ 4 2 ] ", $document, $offset);
- $this->assert->boolean($element->contains(4))->isEqualTo(true);
- $this->assert->boolean($element->contains(2))->isEqualTo(true);
- $this->assert->boolean($element->contains(8))->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(10);
- }
-
- public function testGetContent()
- {
- $val_4 = new \Smalot\PdfParser\Element\ElementNumeric('4');
- $val_2 = new \Smalot\PdfParser\Element\ElementNumeric('2');
- $element = new \Smalot\PdfParser\Element\ElementArray([$val_4, $val_2]);
-
- $content = $element->getContent();
- $this->assert->array($content)->hasSize(2);
- }
-
- public function testContains()
- {
- $val_4 = new \Smalot\PdfParser\Element\ElementNumeric('4');
- $val_2 = new \Smalot\PdfParser\Element\ElementNumeric('2');
- $element = new \Smalot\PdfParser\Element\ElementArray([$val_4, $val_2]);
-
- $this->assert->boolean($element->contains(2))->isEqualTo(true);
- $this->assert->boolean($element->contains(8))->isEqualTo(false);
- }
-
- public function testResolveXRef()
- {
- // Document with text.
- $filename = __DIR__.'/../../../../../../samples/Document1_pdfcreator_nocompressed.pdf';
- $parser = new \Smalot\PdfParser\Parser();
- $document = $parser->parseFile($filename);
- $object = $document->getObjectById('3_0');
- $kids = $object->get('Kids');
-
- $this->assert->object($kids)->isInstanceOf('\Smalot\PdfParser\Element\ElementArray');
- $this->assert->array($kids->getContent())->hasSize(1);
-
- $pages = $kids->getContent();
- $this->assert->object(reset($pages))->isInstanceOf('\Smalot\PdfParser\Page');
- }
-
- public function testGetDetails()
- {
-// // Document with text.
-// $filename = __DIR__ . '/../../../../../../samples/Document1_pdfcreator_nocompressed.pdf';
-// $parser = new \Smalot\PdfParser\Parser();
-// $document = $parser->parseFile($filename);
-// $object = $document->getObjectById('3_0');
-// /** @var \Smalot\PdfParser\Element\ElementArray $kids */
-// $kids = $object->get('Kids');
-// $details = $kids->getDetails();
-//
-// $this->assert->array($details)->hasSize(1);
-// $this->assert->string($details[0]['Type'])->isEqualTo('Page');
-
- $document = new Document();
- $content = '<> [8 [9 <>]]]>>';
- $details_reference = [
- 'Type' => 'Page',
- 'Types' => [
- 8,
- ],
- 'Sizes' => [
- 1,
- 2,
- 3,
- 4,
- 5,
- [
- 'Subtype' => 'XObject',
- ],
- [
- 8,
- [
- 9,
- [
- 'FontSize' => 10,
- ],
- ],
- ],
- ],
- ];
- $header = Header::parse($content, $document);
- $details = $header->getDetails();
-
- $this->assert->array($details)->hasSize(3);
- $this->assert->array($details)->isEqualTo($details_reference);
- }
-
- public function test__toString()
- {
- $val_4 = new \Smalot\PdfParser\Element\ElementNumeric('4');
- $val_2 = new \Smalot\PdfParser\Element\ElementNumeric('2');
- $element = new \Smalot\PdfParser\Element\ElementArray([$val_4, $val_2]);
- $this->assert->castToString($element)->isEqualTo('4,2');
-
- $document = new \Smalot\PdfParser\Document([]);
- $element = \Smalot\PdfParser\Element\ElementArray::parse(' [ 4 2 ]', $document);
- $this->assert->castToString($element)->isEqualTo('4,2');
- }
-}
diff --git a/src/Smalot/PdfParser/Tests/Units/Element/ElementBoolean.php b/src/Smalot/PdfParser/Tests/Units/Element/ElementBoolean.php
deleted file mode 100644
index 58ba15c8..00000000
--- a/src/Smalot/PdfParser/Tests/Units/Element/ElementBoolean.php
+++ /dev/null
@@ -1,133 +0,0 @@
-
- * @date 2017-01-03
- *
- * @license LGPLv3
- * @url
- *
- * PdfParser is a pdf library written in PHP, extraction oriented.
- * Copyright (C) 2017 - Sébastien MALOT
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.
- * If not, see .
- */
-
-namespace Smalot\PdfParser\Tests\Units\Element;
-
-use mageekguy\atoum;
-
-/**
- * Class ElementBoolean
- */
-class ElementBoolean extends atoum\test
-{
- public function testParse()
- {
- // Skipped.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementBoolean::parse('ABC', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementBoolean::parse(' [ false ]', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementBoolean::parse(' << true >>', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementBoolean::parse(' / false ', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementBoolean::parse(' 0 true ', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementBoolean::parse(" 0 \n true ", null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
-
- // Valid.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementBoolean::parse(' true ', null, $offset);
- $this->assert->boolean($element->getContent())->isEqualTo(true);
- $this->assert->integer($offset)->isEqualTo(5);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementBoolean::parse(' TRUE ', null, $offset);
- $this->assert->boolean($element->getContent())->isEqualTo(true);
- $this->assert->integer($offset)->isEqualTo(5);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementBoolean::parse(' True', null, $offset);
- $this->assert->boolean($element->getContent())->isEqualTo(true);
- $this->assert->integer($offset)->isEqualTo(5);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementBoolean::parse('true', null, $offset);
- $this->assert->boolean($element->getContent())->isEqualTo(true);
- $this->assert->integer($offset)->isEqualTo(4);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementBoolean::parse('False', null, $offset);
- $this->assert->boolean($element->getContent())->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(5);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementBoolean::parse(" \n true ", null, $offset);
- $this->assert->boolean($element->getContent())->isEqualTo(true);
- $this->assert->integer($offset)->isEqualTo(7);
- }
-
- public function testGetContent()
- {
- $element = new \Smalot\PdfParser\Element\ElementBoolean('true');
- $this->assert->boolean($element->getContent())->isEqualTo(true);
- $element = new \Smalot\PdfParser\Element\ElementBoolean('false');
- $this->assert->boolean($element->getContent())->isEqualTo(false);
- }
-
- public function testEquals()
- {
- $element = new \Smalot\PdfParser\Element\ElementBoolean('true');
- $this->assert->boolean($element->equals(true))->isEqualTo(true);
- $this->assert->boolean($element->equals(1))->isEqualTo(false);
- $this->assert->boolean($element->equals(false))->isEqualTo(false);
- $this->assert->boolean($element->equals(null))->isEqualTo(false);
-
- $element = new \Smalot\PdfParser\Element\ElementBoolean('false');
- $this->assert->boolean($element->equals(false))->isEqualTo(true);
- $this->assert->boolean($element->equals(0))->isEqualTo(false);
- $this->assert->boolean($element->equals(true))->isEqualTo(false);
- $this->assert->boolean($element->equals(null))->isEqualTo(false);
- }
-
- public function testContains()
- {
- $element = new \Smalot\PdfParser\Element\ElementBoolean('true');
- $this->assert->boolean($element->contains(true))->isEqualTo(true);
- $this->assert->boolean($element->contains(false))->isEqualTo(false);
- $this->assert->boolean($element->contains(1))->isEqualTo(false);
- }
-
- public function test__toString()
- {
- $element = new \Smalot\PdfParser\Element\ElementBoolean('true');
- $this->assert->castToString($element)->isEqualTo('true');
- $element = new \Smalot\PdfParser\Element\ElementBoolean('false');
- $this->assert->castToString($element)->isEqualTo('false');
- }
-}
diff --git a/src/Smalot/PdfParser/Tests/Units/Element/ElementDate.php b/src/Smalot/PdfParser/Tests/Units/Element/ElementDate.php
deleted file mode 100644
index 9a2aedbb..00000000
--- a/src/Smalot/PdfParser/Tests/Units/Element/ElementDate.php
+++ /dev/null
@@ -1,162 +0,0 @@
-
- * @date 2017-01-03
- *
- * @license LGPLv3
- * @url
- *
- * PdfParser is a pdf library written in PHP, extraction oriented.
- * Copyright (C) 2017 - Sébastien MALOT
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.
- * If not, see .
- */
-
-namespace Smalot\PdfParser\Tests\Units\Element;
-
-use mageekguy\atoum;
-
-/**
- * Class ElementDate
- */
-class ElementDate extends atoum\test
-{
- public function testParse()
- {
- // Skipped.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementDate::parse('ABC', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementDate::parse(' [ (ABC) 5 6 ]', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementDate::parse(' << (invalid) >>', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementDate::parse(' / (FlateDecode) ', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementDate::parse(' 0 (FlateDecode) ', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementDate::parse(" 0 \n (FlateDecode) ", null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
-
- // Valid.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementDate::parse(' (D:20130901235555+02\'00\') ', null, $offset);
- $element->setFormat('c');
- $this->assert->object($element->getContent())->isInstanceOf('\DateTime');
- $this->assert->castToString($element)->isEqualTo('2013-09-01T23:55:55+02:00');
- $this->assert->integer($offset)->isEqualTo(26);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementDate::parse(' (D:20130901235555+02\'00\') ', null, $offset);
- $element->setFormat('c');
- $this->assert->object($element->getContent())->isInstanceOf('\DateTime');
- $this->assert->castToString($element)->isEqualTo('2013-09-01T23:55:55+02:00');
- $this->assert->integer($offset)->isEqualTo(26);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementDate::parse(' (D:20130901235555+02\'00\')', null, $offset);
- $element->setFormat('c');
- $this->assert->object($element->getContent())->isInstanceOf('\DateTime');
- $this->assert->castToString($element)->isEqualTo('2013-09-01T23:55:55+02:00');
- $this->assert->integer($offset)->isEqualTo(26);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementDate::parse('(D:20130901235555+02\'00\')', null, $offset);
- $element->setFormat('c');
- $this->assert->object($element->getContent())->isInstanceOf('\DateTime');
- $this->assert->castToString($element)->isEqualTo('2013-09-01T23:55:55+02:00');
- $this->assert->integer($offset)->isEqualTo(25);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementDate::parse(" \n (D:20130901235555+02'00') ", null, $offset);
- $element->setFormat('c');
- $this->assert->object($element->getContent())->isInstanceOf('\DateTime');
- $this->assert->castToString($element)->isEqualTo('2013-09-01T23:55:55+02:00');
- $this->assert->integer($offset)->isEqualTo(28);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementDate::parse(" \n (D:20130901235555) ", null, $offset);
- $element->setFormat('c');
- $this->assert->object($element->getContent())->isInstanceOf('\DateTime');
- $this->assert->boolean($element->equals(new \DateTime('2013-09-01T23:55:55+00:00')))->isEqualTo(true);
- $this->assert->integer($offset)->isEqualTo(21);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementDate::parse("(D:20131206091846Z00'00')", null, $offset);
- $element->setFormat('c');
- $this->assert->object($element->getContent())->isInstanceOf('\DateTime');
- //$this->assert->boolean($element->equals(new \DateTime('2013-09-01T23:55:55')))->isEqualTo(true);
- $this->assert->integer($offset)->isEqualTo(25);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementDate::parse(" \n (D:1-23-2014, 19:02:15-03'00') ", null, $offset);
- $element->setFormat('c');
- $this->assert->object($element->getContent())->isInstanceOf('\DateTime');
- $this->assert->castToString($element)->isEqualTo('2014-01-23T19:02:15-03:00');
- $this->assert->integer($offset)->isEqualTo(33);
-
- // Format invalid
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementDate::parse(" \n (D:2013+02'00') ", null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- }
-
- public function testGetContent()
- {
- $element = new \Smalot\PdfParser\Element\ElementDate(new \DateTime('2013-09-01 23:55:55+02:00'));
- $this->assert->dateTime($element->getContent())->isEqualTo(new \DateTime('2013-09-01 21:55:55+00:00'));
-
- try {
- $element = new \Smalot\PdfParser\Element\ElementDate('2013-09-01 23:55:55+02:00');
- $this->assert->boolean(false)->isEqualTo(true);
- } catch (\Exception $e) {
- $this->assert->exception($e)->hasMessage('DateTime required.');
- }
- }
-
- public function testEquals()
- {
- $element = new \Smalot\PdfParser\Element\ElementDate(new \DateTime('2013-09-01 23:55:55+02:00'));
- $element->setFormat('c');
- $this->assert->boolean($element->equals('2013-09-01T23:55:55+02:00'))->isEqualTo(true);
- $this->assert->boolean($element->equals('2013-09-01T23:55:55+01:00'))->isEqualTo(false);
- $this->assert->boolean($element->equals(new \DateTime('2013-09-01T21:55:55+00:00')))->isEqualTo(true);
- $this->assert->boolean($element->equals(new \DateTime('2013-09-01T23:55:55+01:00')))->isEqualTo(false);
- $this->assert->boolean($element->equals('ABC'))->isEqualTo(false);
- }
-
- public function testContains()
- {
- $element = new \Smalot\PdfParser\Element\ElementDate(new \DateTime('2013-09-01 23:55:55+02:00'));
- $this->assert->boolean($element->contains('2013-09-01T21:55:55+00:00'))->isEqualTo(true);
- $this->assert->boolean($element->contains('2013-06-15'))->isEqualTo(false);
- }
-
- public function test__toString()
- {
- $element = new \Smalot\PdfParser\Element\ElementDate(new \DateTime('2013-09-01 23:55:55+02:00'));
- $element->setFormat('c');
- $this->assert->castToString($element)->isEqualTo('2013-09-01T23:55:55+02:00');
- }
-}
diff --git a/src/Smalot/PdfParser/Tests/Units/Element/ElementHexa.php b/src/Smalot/PdfParser/Tests/Units/Element/ElementHexa.php
deleted file mode 100644
index 71dc822d..00000000
--- a/src/Smalot/PdfParser/Tests/Units/Element/ElementHexa.php
+++ /dev/null
@@ -1,104 +0,0 @@
-
- * @date 2017-01-03
- *
- * @license LGPLv3
- * @url
- *
- * PdfParser is a pdf library written in PHP, extraction oriented.
- * Copyright (C) 2017 - Sébastien MALOT
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.
- * If not, see .
- */
-
-namespace Smalot\PdfParser\Tests\Units\Element;
-
-use mageekguy\atoum;
-
-/**
- * Class ElementHexa
- */
-class ElementHexa extends atoum\test
-{
- public function testParse()
- {
- // Skipped.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementHexa::parse('ABC', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementHexa::parse(' [ <0020> 5 6 ]', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementHexa::parse(' << <0020> >>', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementHexa::parse(' / <0020> ', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementHexa::parse(' 0 <0020> ', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementHexa::parse(" 0 \n <0020> ", null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
-
- // Valid.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementHexa::parse(' <0020> ', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo(' ');
- $this->assert->integer($offset)->isEqualTo(7);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementHexa::parse(' <0020> ', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo(' ');
- $this->assert->integer($offset)->isEqualTo(7);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementHexa::parse(' <0020>', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo(' ');
- $this->assert->integer($offset)->isEqualTo(7);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementHexa::parse('<0020>', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo(' ');
- $this->assert->integer($offset)->isEqualTo(6);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementHexa::parse(" \n <0020> ", null, $offset);
- $this->assert->string($element->getContent())->isEqualTo(' ');
- $this->assert->integer($offset)->isEqualTo(9);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementHexa::parse(" \n <5465616d204d616e6167656d656e742053797374656d73> ", null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('Team Management Systems');
- $this->assert->integer($offset)->isEqualTo(51);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementHexa::parse(" \n <5265706f72744275696c646572> ", null, $offset);
- $this->assert->object($element)->isInstanceOf('\Smalot\PdfParser\Element\ElementString');
- $this->assert->string($element->getContent())->isEqualTo('ReportBuilder');
- $this->assert->integer($offset)->isEqualTo(31);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementHexa::parse(" \n <443a3230313331323137313334303435303027303027> ", null, $offset);
- $this->assert->object($element)->isInstanceOf('\Smalot\PdfParser\Element\ElementDate');
- $this->assert->castToString($element)->isEqualTo('2013-12-17T13:40:45+00:00');
- $this->assert->integer($offset)->isEqualTo(49);
- }
-}
diff --git a/src/Smalot/PdfParser/Tests/Units/Element/ElementMissing.php b/src/Smalot/PdfParser/Tests/Units/Element/ElementMissing.php
deleted file mode 100644
index ee1b40f7..00000000
--- a/src/Smalot/PdfParser/Tests/Units/Element/ElementMissing.php
+++ /dev/null
@@ -1,69 +0,0 @@
-
- * @date 2017-01-03
- *
- * @license LGPLv3
- * @url
- *
- * PdfParser is a pdf library written in PHP, extraction oriented.
- * Copyright (C) 2017 - Sébastien MALOT
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.
- * If not, see .
- */
-
-namespace Smalot\PdfParser\Tests\Units\Element;
-
-use mageekguy\atoum;
-
-/**
- * Class ElementMissing
- */
-class ElementMissing extends atoum\test
-{
- public function testEquals()
- {
- $element = new \Smalot\PdfParser\Element\ElementMissing(null);
- $this->assert->boolean($element->equals(null))->isEqualTo(false);
- $this->assert->boolean($element->equals(true))->isEqualTo(false);
- $this->assert->boolean($element->equals('A'))->isEqualTo(false);
- $this->assert->boolean($element->equals(false))->isEqualTo(false);
- }
-
- public function testGetContent()
- {
- $element = new \Smalot\PdfParser\Element\ElementMissing(null);
- $this->assert->boolean($element->getContent())->isEqualTo(false);
- }
-
- public function testContains()
- {
- $element = new \Smalot\PdfParser\Element\ElementMissing(null);
- $this->assert->boolean($element->contains(null))->isEqualTo(false);
- $this->assert->boolean($element->contains(true))->isEqualTo(false);
- $this->assert->boolean($element->contains('A'))->isEqualTo(false);
- $this->assert->boolean($element->contains(false))->isEqualTo(false);
- }
-
- public function test__toString()
- {
- $element = new \Smalot\PdfParser\Element\ElementMissing(null);
- $this->assert->castToString($element)->isEqualTo('');
- }
-}
diff --git a/src/Smalot/PdfParser/Tests/Units/Element/ElementName.php b/src/Smalot/PdfParser/Tests/Units/Element/ElementName.php
deleted file mode 100644
index 24ba194d..00000000
--- a/src/Smalot/PdfParser/Tests/Units/Element/ElementName.php
+++ /dev/null
@@ -1,154 +0,0 @@
-
- * @date 2017-01-03
- *
- * @license LGPLv3
- * @url
- *
- * PdfParser is a pdf library written in PHP, extraction oriented.
- * Copyright (C) 2017 - Sébastien MALOT
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.
- * If not, see .
- */
-
-namespace Smalot\PdfParser\Tests\Units\Element;
-
-use mageekguy\atoum;
-
-/**
- * Class ElementName
- */
-class ElementName extends atoum\test
-{
- public function testParse()
- {
- // Skipped.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementName::parse('ABC', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementName::parse(' [ /ABC 5 6 ]', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementName::parse(' << invalid >>', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementName::parse(' / FlateDecode ', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementName::parse(' 0 /FlateDecode ', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementName::parse(" 0 \n /FlateDecode ", null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
-
- // Valid.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementName::parse(' /FlateDecode ', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('FlateDecode');
- $this->assert->integer($offset)->isEqualTo(13);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementName::parse(' /FlateDecode', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('FlateDecode');
- $this->assert->integer($offset)->isEqualTo(13);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementName::parse('/FlateDecode', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('FlateDecode');
- $this->assert->integer($offset)->isEqualTo(12);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementName::parse(" \n /FlateDecode ", null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('FlateDecode');
- $this->assert->integer($offset)->isEqualTo(15);
-
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementName::parse('/FlateDecode2', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('FlateDecode2');
- $this->assert->integer($offset)->isEqualTo(13);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementName::parse('/Flate-Decode2', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('Flate-Decode2');
- $this->assert->integer($offset)->isEqualTo(14);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementName::parse('/OJHCYD+Cambria', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('OJHCYD+Cambria');
- $this->assert->integer($offset)->isEqualTo(15);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementName::parse('/OJHCYD+Cambria,Bold', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('OJHCYD+Cambria,Bold');
- $this->assert->integer($offset)->isEqualTo(20);
-
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementName::parse('/Flate_Decode2', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('Flate');
- $this->assert->integer($offset)->isEqualTo(6);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementName::parse('/Flate.Decode2', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('Flate.Decode2');
- $this->assert->integer($offset)->isEqualTo(14);
- }
-
- public function testGetContent()
- {
- $element = new \Smalot\PdfParser\Element\ElementName('FlateDecode');
- $this->assert->string($element->getContent())->isEqualTo('FlateDecode');
- }
-
- public function testEquals()
- {
- $element = new \Smalot\PdfParser\Element\ElementName('FlateDecode');
- $this->assert->boolean($element->equals('FlateDecode'))->isEqualTo(true);
- $this->assert->boolean($element->equals('Flatedecode'))->isEqualTo(false);
-
- $element = new \Smalot\PdfParser\Element\ElementName('FlateDecode2');
- $this->assert->boolean($element->equals('FlateDecode2'))->isEqualTo(true);
- $this->assert->boolean($element->equals('FlateDecode3'))->isEqualTo(false);
-
- $element = new \Smalot\PdfParser\Element\ElementName('Flate-Decode2');
- $this->assert->boolean($element->equals('Flate-Decode2'))->isEqualTo(true);
- $this->assert->boolean($element->equals('Flate-Decode3'))->isEqualTo(false);
- }
-
- public function testContains()
- {
- $element = new \Smalot\PdfParser\Element\ElementName('FlateDecode');
- $this->assert->boolean($element->contains('FlateDecode'))->isEqualTo(true);
- $this->assert->boolean($element->contains('Flatedecode'))->isEqualTo(false);
-
- $element = new \Smalot\PdfParser\Element\ElementName('FlateDecode2');
- $this->assert->boolean($element->contains('FlateDecode2'))->isEqualTo(true);
- $this->assert->boolean($element->contains('FlateDecode3'))->isEqualTo(false);
-
- $element = new \Smalot\PdfParser\Element\ElementName('Flate-Decode2');
- $this->assert->boolean($element->contains('Flate-Decode2'))->isEqualTo(true);
- $this->assert->boolean($element->contains('Flate-Decode3'))->isEqualTo(false);
- }
-
- public function test__toString()
- {
- $element = new \Smalot\PdfParser\Element\ElementName('FlateDecode');
- $this->assert->castToString($element)->isEqualTo('FlateDecode');
- }
-}
diff --git a/src/Smalot/PdfParser/Tests/Units/Element/ElementNull.php b/src/Smalot/PdfParser/Tests/Units/Element/ElementNull.php
deleted file mode 100644
index c67b9663..00000000
--- a/src/Smalot/PdfParser/Tests/Units/Element/ElementNull.php
+++ /dev/null
@@ -1,119 +0,0 @@
-
- * @date 2017-01-03
- *
- * @license LGPLv3
- * @url
- *
- * PdfParser is a pdf library written in PHP, extraction oriented.
- * Copyright (C) 2017 - Sébastien MALOT
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.
- * If not, see .
- */
-
-namespace Smalot\PdfParser\Tests\Units\Element;
-
-use mageekguy\atoum;
-
-/**
- * Class ElementNull
- */
-class ElementNull extends atoum\test
-{
- public function testParse()
- {
- // Skipped.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNull::parse('ABC', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNull::parse(' [ null ]', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNull::parse(' << null >>', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNull::parse(' / null ', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNull::parse(' 0 null ', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNull::parse(" 0 \n null ", null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
-
- // Valid.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNull::parse(' null ', null, $offset);
- $this->assert->boolean(null === $element->getContent())->isEqualTo(true);
- $this->assert->integer($offset)->isEqualTo(5);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNull::parse(' null ', null, $offset);
- $this->assert->boolean(null === $element->getContent())->isEqualTo(true);
- $this->assert->integer($offset)->isEqualTo(5);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNull::parse(' null', null, $offset);
- $this->assert->boolean(null === $element->getContent())->isEqualTo(true);
- $this->assert->integer($offset)->isEqualTo(5);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNull::parse('null', null, $offset);
- $this->assert->boolean(null === $element->getContent())->isEqualTo(true);
- $this->assert->integer($offset)->isEqualTo(4);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNull::parse(" \n null ", null, $offset);
- $this->assert->boolean(null === $element->getContent())->isEqualTo(true);
- $this->assert->integer($offset)->isEqualTo(7);
- }
-
- public function testGetContent()
- {
- $element = new \Smalot\PdfParser\Element\ElementNull('null');
- $this->assert->boolean(null === $element->getContent())->isEqualTo(true);
- }
-
- public function testEquals()
- {
- $element = new \Smalot\PdfParser\Element\ElementNull('null');
- $this->assert->boolean($element->equals(null))->isEqualTo(true);
- $this->assert->boolean($element->equals(false))->isEqualTo(false);
- $this->assert->boolean($element->equals(0))->isEqualTo(false);
- $this->assert->boolean($element->equals(1))->isEqualTo(false);
- }
-
- public function testContains()
- {
- $element = new \Smalot\PdfParser\Element\ElementNull('null');
- $this->assert->boolean($element->contains(null))->isEqualTo(true);
- $this->assert->boolean($element->contains(false))->isEqualTo(false);
- $this->assert->boolean($element->contains(0))->isEqualTo(false);
- }
-
- public function test__toString()
- {
- $element = new \Smalot\PdfParser\Element\ElementNull('null');
- $this->assert->castToString($element)->isEqualTo('null');
- }
-}
diff --git a/src/Smalot/PdfParser/Tests/Units/Element/ElementNumeric.php b/src/Smalot/PdfParser/Tests/Units/Element/ElementNumeric.php
deleted file mode 100644
index bffa28f5..00000000
--- a/src/Smalot/PdfParser/Tests/Units/Element/ElementNumeric.php
+++ /dev/null
@@ -1,182 +0,0 @@
-
- * @date 2017-01-03
- *
- * @license LGPLv3
- * @url
- *
- * PdfParser is a pdf library written in PHP, extraction oriented.
- * Copyright (C) 2017 - Sébastien MALOT
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.
- * If not, see .
- */
-
-namespace Smalot\PdfParser\Tests\Units\Element;
-
-use mageekguy\atoum;
-
-/**
- * Class ElementNumeric
- */
-class ElementNumeric extends atoum\test
-{
- public function testParse()
- {
- // Skipped.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNumeric::parse('ABC', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNumeric::parse(' [ 2 ]', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNumeric::parse(' /2', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNumeric::parse(" /2 \n 2", null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
-
- // Valid.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNumeric::parse(' -2', null, $offset);
- $this->assert->float($element->getContent())->isEqualTo(-2.0);
- $this->assert->integer($offset)->isEqualTo(3);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNumeric::parse('2BC', null, $offset);
- $this->assert->float($element->getContent())->isEqualTo(2.0);
- $this->assert->integer($offset)->isEqualTo(1);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNumeric::parse(' 2BC', null, $offset);
- $this->assert->float($element->getContent())->isEqualTo(2.0);
- $this->assert->integer($offset)->isEqualTo(2);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNumeric::parse(' -2BC', null, $offset);
- $this->assert->float($element->getContent())->isEqualTo(-2.0);
- $this->assert->integer($offset)->isEqualTo(3);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNumeric::parse(' -2', null, $offset);
- $this->assert->float($element->getContent())->isEqualTo(-2.0);
- $this->assert->integer($offset)->isEqualTo(3);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNumeric::parse(' 2 0 obj', null, $offset);
- $this->assert->float($element->getContent())->isEqualTo(2.0);
- $this->assert->integer($offset)->isEqualTo(2);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementNumeric::parse(" \n -2 ", null, $offset);
- $this->assert->float($element->getContent())->isEqualTo(-2.0);
- $this->assert->integer($offset)->isEqualTo(5);
- }
-
- public function testGetContent()
- {
- $element = new \Smalot\PdfParser\Element\ElementNumeric('B');
- $this->assert->float($element->getContent())->isEqualTo(0.0);
- $element = new \Smalot\PdfParser\Element\ElementNumeric('-2.5');
- $this->assert->float($element->getContent())->isEqualTo(-2.5);
- $element = new \Smalot\PdfParser\Element\ElementNumeric('-2');
- $this->assert->float($element->getContent())->isEqualTo(-2.0);
- $element = new \Smalot\PdfParser\Element\ElementNumeric(' -2');
- $this->assert->float($element->getContent())->isEqualTo(-2.0);
- $element = new \Smalot\PdfParser\Element\ElementNumeric('2.5');
- $this->assert->float($element->getContent())->isEqualTo(2.5);
- $element = new \Smalot\PdfParser\Element\ElementNumeric('2');
- $this->assert->float($element->getContent())->isEqualTo(2.0);
- }
-
- public function testEquals()
- {
- $element = new \Smalot\PdfParser\Element\ElementNumeric('1');
- $this->assert->boolean($element->equals('B'))->isEqualTo(false);
- $element = new \Smalot\PdfParser\Element\ElementNumeric('1.5');
- $this->assert->boolean($element->equals('B'))->isEqualTo(false);
-
- $element = new \Smalot\PdfParser\Element\ElementNumeric('2');
- $this->assert->boolean($element->equals('2'))->isEqualTo(true);
- $element = new \Smalot\PdfParser\Element\ElementNumeric('2');
- $this->assert->boolean($element->equals('3'))->isEqualTo(false);
-
- $element = new \Smalot\PdfParser\Element\ElementNumeric('-2');
- $this->assert->boolean($element->equals('-2'))->isEqualTo(true);
- $element = new \Smalot\PdfParser\Element\ElementNumeric('-2');
- $this->assert->boolean($element->equals('-3'))->isEqualTo(false);
-
- $element = new \Smalot\PdfParser\Element\ElementNumeric('2.5');
- $this->assert->boolean($element->equals('2.5'))->isEqualTo(true);
- $element = new \Smalot\PdfParser\Element\ElementNumeric('2.5');
- $this->assert->boolean($element->equals('3.5'))->isEqualTo(false);
-
- $element = new \Smalot\PdfParser\Element\ElementNumeric('-2.5');
- $this->assert->boolean($element->equals('-2.5'))->isEqualTo(true);
- $element = new \Smalot\PdfParser\Element\ElementNumeric('-2.5');
- $this->assert->boolean($element->equals('-3.5'))->isEqualTo(false);
- }
-
- public function testContains()
- {
- $element = new \Smalot\PdfParser\Element\ElementNumeric('1');
- $this->assert->boolean($element->contains('B'))->isEqualTo(false);
- $element = new \Smalot\PdfParser\Element\ElementNumeric('1.5');
- $this->assert->boolean($element->contains('B'))->isEqualTo(false);
-
- $element = new \Smalot\PdfParser\Element\ElementNumeric('2');
- $this->assert->boolean($element->contains('2'))->isEqualTo(true);
- $element = new \Smalot\PdfParser\Element\ElementNumeric('2');
- $this->assert->boolean($element->contains('3'))->isEqualTo(false);
-
- $element = new \Smalot\PdfParser\Element\ElementNumeric('-2');
- $this->assert->boolean($element->contains('-2'))->isEqualTo(true);
- $element = new \Smalot\PdfParser\Element\ElementNumeric('-2');
- $this->assert->boolean($element->contains('-3'))->isEqualTo(false);
-
- $element = new \Smalot\PdfParser\Element\ElementNumeric('2.5');
- $this->assert->boolean($element->contains('2.5'))->isEqualTo(true);
- $element = new \Smalot\PdfParser\Element\ElementNumeric('2.5');
- $this->assert->boolean($element->contains('3.5'))->isEqualTo(false);
-
- $element = new \Smalot\PdfParser\Element\ElementNumeric('-2.5');
- $this->assert->boolean($element->contains('-2.5'))->isEqualTo(true);
- $element = new \Smalot\PdfParser\Element\ElementNumeric('-2.5');
- $this->assert->boolean($element->contains('-3.5'))->isEqualTo(false);
- }
-
- public function test__toString()
- {
- $element = new \Smalot\PdfParser\Element\ElementNumeric('B');
- $this->assert->castToString($element)->isEqualTo('0');
- $element = new \Smalot\PdfParser\Element\ElementNumeric('1B');
- $this->assert->castToString($element)->isEqualTo('1');
-
- $element = new \Smalot\PdfParser\Element\ElementNumeric('2');
- $this->assert->castToString($element)->isEqualTo('2');
-
- $element = new \Smalot\PdfParser\Element\ElementNumeric('-2');
- $this->assert->castToString($element)->isEqualTo('-2');
-
- $element = new \Smalot\PdfParser\Element\ElementNumeric('2.5');
- $this->assert->castToString($element)->isEqualTo('2.5');
-
- $element = new \Smalot\PdfParser\Element\ElementNumeric('-2.5');
- $this->assert->castToString($element)->isEqualTo('-2.5');
- }
-}
diff --git a/src/Smalot/PdfParser/Tests/Units/Element/ElementString.php b/src/Smalot/PdfParser/Tests/Units/Element/ElementString.php
deleted file mode 100644
index 625e0dc7..00000000
--- a/src/Smalot/PdfParser/Tests/Units/Element/ElementString.php
+++ /dev/null
@@ -1,154 +0,0 @@
-
- * @date 2017-01-03
- *
- * @license LGPLv3
- * @url
- *
- * PdfParser is a pdf library written in PHP, extraction oriented.
- * Copyright (C) 2017 - Sébastien MALOT
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.
- * If not, see .
- */
-
-namespace Smalot\PdfParser\Tests\Units\Element;
-
-use mageekguy\atoum;
-
-/**
- * Class ElementString
- */
-class ElementString extends atoum\test
-{
- public function testParse()
- {
- // Skipped.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementString::parse('ABC', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementString::parse(' [ (ABC) 5 6 ]', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementString::parse(' << (invalid) >>', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementString::parse(' / (FlateDecode) ', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementString::parse(' 0 (FlateDecode) ', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementString::parse(" 0 \n (FlateDecode) ", null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
-
- // Valid.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementString::parse(' (Copyright) ', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('Copyright');
- $this->assert->integer($offset)->isEqualTo(12);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementString::parse(' (Copyright) ', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('Copyright');
- $this->assert->integer($offset)->isEqualTo(12);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementString::parse(' (Copyright)', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('Copyright');
- $this->assert->integer($offset)->isEqualTo(12);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementString::parse('(Copyright)', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('Copyright');
- $this->assert->integer($offset)->isEqualTo(11);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementString::parse('(Copy-right2)', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('Copy-right2');
- $this->assert->integer($offset)->isEqualTo(13);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementString::parse(" \n (Copyright) ", null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('Copyright');
- $this->assert->integer($offset)->isEqualTo(14);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementString::parse('()', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('');
- $this->assert->integer($offset)->isEqualTo(2);
-
- // Complex study case : Unicode + octal.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementString::parse('(ABC\\))', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('ABC)');
- $this->assert->integer($offset)->isEqualTo(7);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementString::parse("(\xFE\xFF\\000M)", null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('M');
- $this->assert->integer($offset)->isEqualTo(9);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementString::parse('(<20>)', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo(' ');
- $this->assert->integer($offset)->isEqualTo(6);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementString::parse('(Gutter\\ console\\ assembly)', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('Gutter console assembly');
- $this->assert->integer($offset)->isEqualTo(27);
- }
-
- public function testGetContent()
- {
- $element = new \Smalot\PdfParser\Element\ElementString('Copyright');
- $this->assert->string($element->getContent())->isEqualTo('Copyright');
- }
-
- public function testEquals()
- {
- $element = new \Smalot\PdfParser\Element\ElementString('CopyRight');
- $this->assert->boolean($element->equals('CopyRight'))->isEqualTo(true);
- $this->assert->boolean($element->equals('Flatedecode'))->isEqualTo(false);
-
- $element = new \Smalot\PdfParser\Element\ElementString('CopyRight2');
- $this->assert->boolean($element->equals('CopyRight2'))->isEqualTo(true);
- $this->assert->boolean($element->equals('CopyRight3'))->isEqualTo(false);
-
- $element = new \Smalot\PdfParser\Element\ElementString('Flate-Decode2');
- $this->assert->boolean($element->equals('Flate-Decode2'))->isEqualTo(true);
- $this->assert->boolean($element->equals('Flate-Decode3'))->isEqualTo(false);
- }
-
- public function testContains()
- {
- $element = new \Smalot\PdfParser\Element\ElementString('CopyRight');
- $this->assert->boolean($element->contains('CopyRight'))->isEqualTo(true);
- $this->assert->boolean($element->contains('Copyright'))->isEqualTo(false);
-
- $element = new \Smalot\PdfParser\Element\ElementString('CopyRight2');
- $this->assert->boolean($element->contains('CopyRight2'))->isEqualTo(true);
- $this->assert->boolean($element->contains('CopyRight3'))->isEqualTo(false);
- }
-
- public function test__toString()
- {
- $element = new \Smalot\PdfParser\Element\ElementString('CopyRight');
- $this->assert->castToString($element)->isEqualTo('CopyRight');
- }
-}
diff --git a/src/Smalot/PdfParser/Tests/Units/Element/ElementStruct.php b/src/Smalot/PdfParser/Tests/Units/Element/ElementStruct.php
deleted file mode 100644
index aaeeb5d2..00000000
--- a/src/Smalot/PdfParser/Tests/Units/Element/ElementStruct.php
+++ /dev/null
@@ -1,96 +0,0 @@
-
- * @date 2017-01-03
- *
- * @license LGPLv3
- * @url
- *
- * PdfParser is a pdf library written in PHP, extraction oriented.
- * Copyright (C) 2017 - Sébastien MALOT
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.
- * If not, see .
- */
-
-namespace Smalot\PdfParser\Tests\Units\Element;
-
-use mageekguy\atoum;
-
-/**
- * Class ElementStruct
- */
-class ElementStruct extends atoum\test
-{
- public function testParse()
- {
- $document = new \Smalot\PdfParser\Document([]);
-
- // Skipped.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementStruct::parse('ABC', $document, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementStruct::parse(
- ' [ << /Filter /FlateDecode >> ]',
- $document,
- $offset
- );
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementStruct::parse(' / << /Filter /FlateDecode >> ', $document, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementStruct::parse(' 0 << /Filter /FlateDecode >> ', $document, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementStruct::parse(
- " 0 \n << /Filter /FlateDecode >> ",
- $document,
- $offset
- );
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
-
- // Valid.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementStruct::parse(' << /Filter /FlateDecode >> ', $document, $offset);
- $this->assert->object($element)->isInstanceOf('\Smalot\PdfParser\Header');
- $this->assert->integer($offset)->isEqualTo(27);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementStruct::parse(' << /Filter /FlateDecode >>', $document, $offset);
- $this->assert->object($element)->isInstanceOf('\Smalot\PdfParser\Header');
- $this->assert->integer($offset)->isEqualTo(27);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementStruct::parse('<< /Filter /FlateDecode >>', $document, $offset);
- $this->assert->object($element)->isInstanceOf('\Smalot\PdfParser\Header');
- $this->assert->integer($offset)->isEqualTo(26);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementStruct::parse(
- " \n << /Filter /FlateDecode >> ",
- $document,
- $offset
- );
- $this->assert->object($element)->isInstanceOf('\Smalot\PdfParser\Header');
- $this->assert->integer($offset)->isEqualTo(29);
- }
-}
diff --git a/src/Smalot/PdfParser/Tests/Units/Element/ElementXRef.php b/src/Smalot/PdfParser/Tests/Units/Element/ElementXRef.php
deleted file mode 100644
index 22e3aaee..00000000
--- a/src/Smalot/PdfParser/Tests/Units/Element/ElementXRef.php
+++ /dev/null
@@ -1,124 +0,0 @@
-
- * @date 2017-01-03
- *
- * @license LGPLv3
- * @url
- *
- * PdfParser is a pdf library written in PHP, extraction oriented.
- * Copyright (C) 2017 - Sébastien MALOT
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.
- * If not, see .
- */
-
-namespace Smalot\PdfParser\Tests\Units\Element;
-
-use mageekguy\atoum;
-
-/**
- * Class ElementXRef
- */
-class ElementXRef extends atoum\test
-{
- public function testParse()
- {
- // Skipped.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementXRef::parse('ABC', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementXRef::parse(' [ 5 0 R ]', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementXRef::parse(' << 5 0 R >>', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementXRef::parse(' / 5 0 R ', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementXRef::parse(' 0 5 0 R ', null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementXRef::parse(" 0 \n 5 0 R ", null, $offset);
- $this->assert->boolean($element)->isEqualTo(false);
- $this->assert->integer($offset)->isEqualTo(0);
-
- // Valid.
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementXRef::parse(' 5 0 R ', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('5_0');
- $this->assert->integer($offset)->isEqualTo(6);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementXRef::parse(' 5 0 R ', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('5_0');
- $this->assert->integer($offset)->isEqualTo(6);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementXRef::parse(' 5 0 R', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('5_0');
- $this->assert->integer($offset)->isEqualTo(6);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementXRef::parse('5 0 R', null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('5_0');
- $this->assert->integer($offset)->isEqualTo(5);
- $offset = 0;
- $element = \Smalot\PdfParser\Element\ElementXRef::parse(" \n 5 0 R ", null, $offset);
- $this->assert->string($element->getContent())->isEqualTo('5_0');
- $this->assert->integer($offset)->isEqualTo(8);
- }
-
- public function testGetContent()
- {
- $element = new \Smalot\PdfParser\Element\ElementXRef('5_0');
- $this->assert->string($element->getContent())->isEqualTo('5_0');
- }
-
- public function testGetId()
- {
- $element = new \Smalot\PdfParser\Element\ElementXRef('5_0');
- $this->assert->string($element->getId())->isEqualTo('5_0');
- }
-
- public function testEquals()
- {
- $element = new \Smalot\PdfParser\Element\ElementXRef('5_0');
- $this->assert->boolean($element->equals(5))->isEqualTo(true);
- $this->assert->boolean($element->equals(8))->isEqualTo(false);
- $this->assert->boolean($element->equals($element))->isEqualTo(true);
- }
-
- public function testContains()
- {
- $element = new \Smalot\PdfParser\Element\ElementXRef('5_0');
- $this->assert->boolean($element->contains(5))->isEqualTo(true);
- $this->assert->boolean($element->contains(8))->isEqualTo(false);
- $this->assert->boolean($element->contains($element))->isEqualTo(true);
- }
-
- public function test__toString()
- {
- $element = new \Smalot\PdfParser\Element\ElementXRef('5_0');
- $this->assert->castToString($element)->isEqualTo('#Obj#5_0');
- }
-}
diff --git a/src/Smalot/PdfParser/Tests/Units/Header.php b/src/Smalot/PdfParser/Tests/Units/Header.php
deleted file mode 100644
index 0be20471..00000000
--- a/src/Smalot/PdfParser/Tests/Units/Header.php
+++ /dev/null
@@ -1,136 +0,0 @@
-
- * @date 2017-01-03
- *
- * @license LGPLv3
- * @url
- *
- * PdfParser is a pdf library written in PHP, extraction oriented.
- * Copyright (C) 2017 - Sébastien MALOT
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.
- * If not, see .
- */
-
-namespace Smalot\PdfParser\Tests\Units;
-
-use mageekguy\atoum;
-
-/**
- * Class Header
- */
-class Header extends atoum\test
-{
- public function testParse()
- {
- $document = new \Smalot\PdfParser\Document();
-
- $content = '<>foo';
- $position = 0;
- $header = \Smalot\PdfParser\Header::parse($content, $document, $position);
-
- $this->assert->object($header)->isInstanceOf('\Smalot\PdfParser\Header');
- $this->assert->integer($position)->isEqualTo(27);
- $this->assert->array($header->getElements())->hasSize(2);
-
- // No header to parse
- $this->assert->castToString($header->get('Type'))->isEqualTo('Page');
- $content = 'foo';
- $position = 0;
- $header = \Smalot\PdfParser\Header::parse($content, $document, $position);
-
- $this->assert->object($header)->isInstanceOf('\Smalot\PdfParser\Header');
- $this->assert->integer($position)->isEqualTo(0);
- $this->assert->array($header->getElements())->hasSize(0);
-
- $position = 0;
- $content = "<>";
- $header = \Smalot\PdfParser\Header::parse($content, $document, $position);
- $this->assert->integer($position)->isEqualTo(212);
-
- $position = 0;
- $content = '[5 0 R ] foo';
- $header = \Smalot\PdfParser\Header::parse($content, $document, $position);
- $this->assert->integer($position)->isEqualTo(8);
- $this->assert->array($header->getElements())->hasSize(1);
- }
-
- public function testGetElements()
- {
- $document = new \Smalot\PdfParser\Document();
-
- $content = '<>foo';
- $position = 0;
- $header = \Smalot\PdfParser\Header::parse($content, $document, $position);
-
- $this->assert->array($elements = $header->getElements())->hasSize(2);
- $this->assert->object(current($elements))->isInstanceOf('\Smalot\PdfParser\Element\ElementName');
-
- $types = $header->getElementTypes();
- $this->assert->array($types);
- $this->assert->string($types['Type'])->isEqualTo('Smalot\PdfParser\Element\ElementName');
- $this->assert->string($types['Subtype'])->isEqualTo('Smalot\PdfParser\Element\ElementName');
- }
-
- public function testHas()
- {
- $document = new \Smalot\PdfParser\Document();
-
- $content = '<>foo';
- $position = 0;
- $header = \Smalot\PdfParser\Header::parse($content, $document, $position);
-
- $this->assert->boolean($header->has('Type'))->isEqualTo(true);
- $this->assert->boolean($header->has('SubType'))->isEqualTo(true);
- $this->assert->boolean($header->has('Font'))->isEqualTo(true);
- $this->assert->boolean($header->has('Text'))->isEqualTo(false);
- }
-
- public function testGet()
- {
- $document = new \Smalot\PdfParser\Document();
-
- $content = '<>foo';
- $position = 0;
- $header = \Smalot\PdfParser\Header::parse($content, $document, $position);
- $object = new \Smalot\PdfParser\Page($document, $header);
- $document->setObjects(['5_0' => $object]);
-
- $this->assert->object($header->get('Type'))->isInstanceOf('\Smalot\PdfParser\Element\ElementName');
- $this->assert->object($header->get('SubType'))->isInstanceOf('\Smalot\PdfParser\Element\ElementName');
- $this->assert->object($header->get('Font'))->isInstanceOf('\Smalot\PdfParser\Page');
- $this->assert->object($header->get('Image'))->isInstanceOf('\Smalot\PdfParser\Element\ElementMissing');
- $this->assert->object($header->get('Resources'))->isInstanceOf('\Smalot\PdfParser\Element\ElementMissing');
- }
-
- public function testResolveXRef()
- {
- $document = new \Smalot\PdfParser\Document();
- $content = '<>foo';
- $position = 0;
- $header = \Smalot\PdfParser\Header::parse($content, $document, $position);
- $object = new \Smalot\PdfParser\Page($document, $header);
- $document->setObjects(['5_0' => $object]);
-
- $this->assert->object($header->get('Font'))->isInstanceOf('\Smalot\PdfParser\PDFObject');
-
- $header = $header->get('Resources');
- $this->assert->object($header)->isInstanceOf('\Smalot\PdfParser\Element\ElementMissing');
- }
-}
diff --git a/src/Smalot/PdfParser/Tests/Units/Page.php b/src/Smalot/PdfParser/Tests/Units/Page.php
deleted file mode 100644
index 6428bc05..00000000
--- a/src/Smalot/PdfParser/Tests/Units/Page.php
+++ /dev/null
@@ -1,386 +0,0 @@
-
- * @date 2017-01-03
- *
- * @license LGPLv3
- * @url
- *
- * PdfParser is a pdf library written in PHP, extraction oriented.
- * Copyright (C) 2017 - Sébastien MALOT
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.
- * If not, see .
- */
-
-namespace Smalot\PdfParser\Tests\Units;
-
-use mageekguy\atoum;
-
-/**
- * Class Page
- */
-class Page extends atoum\test
-{
- public function testGetFonts()
- {
- // Document with text.
- $filename = __DIR__.'/../../../../../samples/Document1_pdfcreator_nocompressed.pdf';
- $parser = new \Smalot\PdfParser\Parser();
- $document = $parser->parseFile($filename);
- $pages = $document->getPages();
- $page = $pages[0];
-
- // the first to load data.
- $fonts = $page->getFonts();
- $this->assert->array($fonts)->isNotEmpty();
- foreach ($fonts as $font) {
- $this->assert->object($font)->isInstanceOf('\Smalot\PdfParser\Font');
- }
- // the second to use cache.
- $fonts = $page->getFonts();
- $this->assert->array($fonts)->isNotEmpty();
-
- // ------------------------------------------------------
- // Document without text.
- $filename = __DIR__.'/../../../../../samples/Document3_pdfcreator_nocompressed.pdf';
- $document = $parser->parseFile($filename);
- $pages = $document->getPages();
- $page = $pages[0];
-
- // the first to load data.
- $fonts = $page->getFonts();
- $this->assert->array($fonts)->isEmpty();
- // the second to use cache.
- $fonts = $page->getFonts();
- $this->assert->array($fonts)->isEmpty();
- }
-
- public function testGetFont()
- {
- // Document with text.
- $filename = __DIR__.'/../../../../../samples/Document1_pdfcreator_nocompressed.pdf';
- $parser = new \Smalot\PdfParser\Parser();
- $document = $parser->parseFile($filename);
- $pages = $document->getPages();
- $page = $pages[0];
-
- // the first to load data.
- $font = $page->getFont('R7');
- $this->assert->object($font)->isInstanceOf('\Smalot\PdfParser\Font');
- $font = $page->getFont('ABC7');
- $this->assert->object($font)->isInstanceOf('\Smalot\PdfParser\Font');
- }
-
- public function testGetText()
- {
- // Document with text.
- $filename = __DIR__.'/../../../../../samples/Document1_pdfcreator_nocompressed.pdf';
- $parser = new \Smalot\PdfParser\Parser();
- $document = $parser->parseFile($filename);
- $pages = $document->getPages();
- $page = $pages[0];
- $text = $page->getText();
-
- $this->assert->string($text)->hasLengthGreaterThan(150);
- $this->assert->string($text)->contains('Document title');
- $this->assert->string($text)->contains('Lorem ipsum');
-
- $this->assert->string($text)->contains('Calibri');
- $this->assert->string($text)->contains('Arial');
- $this->assert->string($text)->contains('Times');
- $this->assert->string($text)->contains('Courier New');
- $this->assert->string($text)->contains('Verdana');
- }
-
- public function testExtractRawData()
- {
- // Document with text.
- $filename = __DIR__.'/../../../../../samples/Document1_pdfcreator_nocompressed.pdf';
- $parser = new \Smalot\PdfParser\Parser();
- $document = $parser->parseFile($filename);
- $pages = $document->getPages();
- $page = $pages[0];
- $extractedRawData = $page->extractRawData();
- $tmItem = $extractedRawData[1];
-
- $this->assert->array($extractedRawData)->hasSize(172);
- $this->assert->array($tmItem)->hasSize(3);
- $this->assert->array($tmItem)->hasKeys(['t', 'o', 'c']);
- $this->assert->string($tmItem['o'])->contains('Tm');
- $this->assert->string($tmItem['c'])->contains('0.999429 0 0 1 201.96 720.68');
- }
-
- public function testExtractDecodedRawData()
- {
- // Document with text.
- $filename = __DIR__.'/../../../../../samples/Document1_pdfcreator_nocompressed.pdf';
- $parser = new \Smalot\PdfParser\Parser();
- $document = $parser->parseFile($filename);
- $pages = $document->getPages();
- $page = $pages[0];
- $extractedDecodedRawData = $page->extractDecodedRawData();
- $tmItem = $extractedDecodedRawData[1];
- $this->assert->array($extractedDecodedRawData)->hasSize(172);
- $this->assert->array($tmItem)->hasSize(3);
- $this->assert->array($tmItem)->hasKeys(['t', 'o', 'c']);
- $this->assert->string($tmItem['o'])->contains('Tm');
- $this->assert->string($tmItem['c'])->contains('0.999429 0 0 1 201.96 720.68');
- $tjItem = $extractedDecodedRawData[2];
- $this->assert->array($tmItem)->hasSize(3);
- $this->assert->array($tmItem)->hasKeys(['t', 'o', 'c']);
- $this->assert->string($tjItem['o'])->contains('TJ');
- $this->assert->string($tjItem['c'][0]['t'])->contains('(');
- $this->assert->string($tjItem['c'][0]['c'])->contains('D');
- $this->assert->string($tjItem['c'][1]['t'])->contains('n');
- $this->assert->string($tjItem['c'][1]['c'])->contains('0.325008');
- $this->assert->string($tjItem['c'][2]['t'])->contains('(');
- $this->assert->string($tjItem['c'][2]['c'])->contains('o');
- }
-
- public function testGetDataCommands()
- {
- // Document with text.
- $filename = __DIR__.'/../../../../../samples/Document1_pdfcreator_nocompressed.pdf';
- $parser = new \Smalot\PdfParser\Parser();
- $document = $parser->parseFile($filename);
- $pages = $document->getPages();
- $page = $pages[0];
- $dataCommands = $page->getDataCommands();
- $tmItem = $dataCommands[0];
- $this->assert->array($dataCommands)->hasSize(166);
- $this->assert->array($tmItem)->hasSize(3);
- $this->assert->array($tmItem)->hasKeys(['t', 'o', 'c']);
- $this->assert->string($tmItem['o'])->contains('Tm');
- $this->assert->string($tmItem['c'])->contains('0.999429 0 0 1 201.96 720.68');
- $tjItem = $dataCommands[1];
- $this->assert->array($tjItem)->hasSize(3);
- $this->assert->array($tjItem)->hasKeys(['t', 'o', 'c']);
- $this->assert->string($tjItem['o'])->contains('TJ');
- $this->assert->string($tjItem['c'][0]['t'])->contains('(');
- $this->assert->string($tjItem['c'][0]['c'])->contains('D');
- $this->assert->string($tjItem['c'][1]['t'])->contains('n');
- $this->assert->string($tjItem['c'][1]['c'])->contains('0.325008');
- $this->assert->string($tjItem['c'][2]['t'])->contains('(');
- $this->assert->string($tjItem['c'][2]['c'])->contains('o');
- }
-
- public function testGetDataTm()
- {
- // Document with text.
- $filename = __DIR__.'/../../../../../samples/Document1_pdfcreator_nocompressed.pdf';
- $parser = new \Smalot\PdfParser\Parser();
- $document = $parser->parseFile($filename);
- $pages = $document->getPages();
- $page = $pages[0];
- $dataTm = $page->getDataTm();
- $item = $dataTm[0];
- $this->assert->array($dataTm)->hasSize(81);
- $this->assert->array($item)->hasSize(2);
- $this->assert->array($item[0])->hasSize(6);
- $this->assert->array($item[0])->containsValues([
- '0.999429',
- '0',
- '0',
- '1',
- '201.96',
- '720.68',
- ]);
- $this->assert->string($item[1])->contains('Document title');
- $item = $dataTm[2];
- $this->assert->array($item[0])->containsValues([
- '0.999402',
- '0',
- '0',
- '1',
- '70.8',
- '673.64',
- ]);
- $this->assert->string($item[1])->contains('Calibri : Lorem ipsum dolor sit amet, consectetur a');
- $item = $dataTm[80];
- $this->assert->array($item[0])->containsValues([
- '0.999402',
- '0',
- '0',
- '1',
- '343.003',
- '81.44',
- ]);
- $this->assert->string($item[1])->contains('nenatis.');
-
- // ------------------------------------------------------
- // Document is a form
- $filename = __DIR__.'/../../../../../samples/SimpleInvoiceFilledExample1.pdf';
- $document = $parser->parseFile($filename);
- $pages = $document->getPages();
- $page = $pages[0];
- $dataTm = $page->getDataTm();
- $item = $dataTm[2];
- $this->assert->array($dataTm)->hasSize(105);
- $this->assert->array($item)->hasSize(2);
- $this->assert->array($item[0])->hasSize(6);
- $this->assert->array($item[0])->containsValues([
- '1',
- '0',
- '0',
- '1',
- '167.3',
- '894.58',
- ]);
- $this->assert->string($item[1])->contains('MyName MyLastName');
- $item = $dataTm[6];
- $this->assert->array($item[0])->containsValues([
- '1',
- '0',
- '0',
- '1',
- '681.94',
- '877.42',
- ]);
- $this->assert->string($item[1])->contains('1/1/2020');
- $item = $dataTm[8];
- $this->assert->array($item[0])->containsValues([
- '1',
- '0',
- '0',
- '1',
- '174.86',
- '827.14',
- ]);
- $this->assert->string($item[1])->contains('Purchase 1');
-
- // ------------------------------------------------------
- // Document is another form of the same type
- $filename = __DIR__.'/../../../../../samples/SimpleInvoiceFilledExample2.pdf';
- $document = $parser->parseFile($filename);
- $pages = $document->getPages();
- $page = $pages[0];
- $dataTm = $page->getDataTm();
- $item = $dataTm[2];
- $this->assert->array($dataTm)->hasSize(105);
- $this->assert->array($item)->hasSize(2);
- $this->assert->array($item[0])->hasSize(6);
- $this->assert->array($item[0])->containsValues([
- '1',
- '0',
- '0',
- '1',
- '167.3',
- '894.58',
- ]);
- $this->assert->string($item[1])->contains("Other'sName Other'sLastName");
- $item = $dataTm[6];
- $this->assert->array($item[0])->containsValues([
- '1',
- '0',
- '0',
- '1',
- '681.94',
- '877.42',
- ]);
- $this->assert->string($item[1])->contains('2/2/2020');
- $item = $dataTm[8];
- $this->assert->array($item[0])->containsValues([
- '1',
- '0',
- '0',
- '1',
- '174.86',
- '827.14',
- ]);
- $this->assert->string($item[1])->contains('Purchase 2');
- }
-
- public function testGetTextXY()
- {
- // Document with text.
- $filename = __DIR__.'/../../../../../samples/Document1_pdfcreator_nocompressed.pdf';
- $parser = new \Smalot\PdfParser\Parser();
- $document = $parser->parseFile($filename);
- $pages = $document->getPages();
- $page = $pages[0];
- $result = $page->getTextXY(201.96, 720.68);
- $this->assert->array($result)->hasSize(1);
- $this->assert->array($result[0])->hasSize(2);
- $this->assert->array($result[0][0])->containsValues([
- '0.999429',
- '0',
- '0',
- '1',
- '201.96',
- '720.68',
- ]);
- $this->assert->string($result[0][1])->contains('Document title');
- $result = $page->getTextXY(201, 720);
- $this->assert->array($result)->hasSize(0);
- $result = $page->getTextXY(201, 720, 1, 1);
- $this->assert->array($result)->hasSize(1);
- $this->assert->array($result[0])->hasSize(2);
- $this->assert->array($result[0][0])->containsValues([
- '0.999429',
- '0',
- '0',
- '1',
- '201.96',
- '720.68',
- ]);
- $this->assert->string($result[0][1])->contains('Document title');
-
- // ------------------------------------------------------
- // Document is a form
- $filename = __DIR__.'/../../../../../samples/SimpleInvoiceFilledExample1.pdf';
- $document = $parser->parseFile($filename);
- $pages = $document->getPages();
- $page = $pages[0];
- $result = $page->getTextXY(167, 894, 1, 1);
- $this->assert->array($result[0][0])->containsValues([
- '1',
- '0',
- '0',
- '1',
- '167.3',
- '894.58',
- ]);
- $this->assert->string($result[0][1])->contains('MyName MyLastName');
- $result = $page->getTextXY(681, 877, 1, 1);
- $this->assert->string($result[0][1])->contains('1/1/2020');
- $result = $page->getTextXY(174, 827, 1, 1);
- $this->assert->string($result[0][1])->contains('Purchase 1');
-
- // ------------------------------------------------------
- // Document is another form of the same type
- $filename = __DIR__.'/../../../../../samples/SimpleInvoiceFilledExample2.pdf';
- $document = $parser->parseFile($filename);
- $pages = $document->getPages();
- $page = $pages[0];
- $result = $page->getTextXY(167, 894, 1, 1);
- $this->assert->array($result[0][0])->containsValues([
- '1',
- '0',
- '0',
- '1',
- '167.3',
- '894.58',
- ]);
- $this->assert->string($result[0][1])->contains("Other'sName Other'sLastName");
- $result = $page->getTextXY(681, 877, 1, 1);
- $this->assert->string($result[0][1])->contains('2/2/2020');
- $result = $page->getTextXY(174, 827, 1, 1);
- $this->assert->string($result[0][1])->contains('Purchase 2');
- }
-}
diff --git a/test/TestCase.php b/test/TestCase.php
new file mode 100644
index 00000000..de3681fa
--- /dev/null
+++ b/test/TestCase.php
@@ -0,0 +1,70 @@
+
+ * @date 2020-06-02
+ *
+ * @author Sébastien MALOT
+ * @date 2017-01-03
+ *
+ * @license LGPLv3
+ * @url
+ *
+ * PdfParser is a pdf library written in PHP, extraction oriented.
+ * Copyright (C) 2017 - Sébastien MALOT
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.
+ * If not, see .
+ */
+
+namespace Test\Smalot\PdfParser;
+
+use PHPUnit\Framework\TestCase as PHPTestCase;
+use Smalot\PdfParser\Document;
+use Smalot\PdfParser\Element;
+use Smalot\PdfParser\Parser;
+
+abstract class TestCase extends PHPTestCase
+{
+ /**
+ * Contains an instance of the class to test.
+ */
+ protected $fixture;
+
+ protected $rootDir;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->rootDir = __DIR__.'/..';
+ }
+
+ protected function getDocumentInstance()
+ {
+ return new Document();
+ }
+
+ protected function getElementInstance($value)
+ {
+ return new Element($value);
+ }
+
+ protected function getParserInstance()
+ {
+ return new Parser();
+ }
+}
diff --git a/tests/Integration/DocumentTest.php b/tests/Integration/DocumentTest.php
new file mode 100644
index 00000000..9dedfd25
--- /dev/null
+++ b/tests/Integration/DocumentTest.php
@@ -0,0 +1,241 @@
+
+ * @date 2020-06-01
+ *
+ * @author Sébastien MALOT
+ * @date 2017-01-03
+ *
+ * @license LGPLv3
+ * @url
+ *
+ * PdfParser is a pdf library written in PHP, extraction oriented.
+ * Copyright (C) 2017 - Sébastien MALOT
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.
+ * If not, see .
+ */
+
+namespace Tests\Smalot\PdfParser\Integration;
+
+use Exception;
+use Smalot\PdfParser\Document;
+use Smalot\PdfParser\Header;
+use Smalot\PdfParser\Page;
+use Smalot\PdfParser\Pages;
+use Smalot\PdfParser\PDFObject;
+use Test\Smalot\PdfParser\TestCase;
+
+class DocumentTest extends TestCase
+{
+ protected function getDocumentInstance()
+ {
+ return new Document();
+ }
+
+ /**
+ * @param Document $document
+ */
+ protected function getPDFObjectInstance($document, $header = null)
+ {
+ return new PDFObject($document, $header);
+ }
+
+ /**
+ * @param Document $document
+ * @param Header $header
+ */
+ protected function getPageInstance($document, $header)
+ {
+ return new Page($document, $header);
+ }
+
+ /**
+ * @param Document $document
+ * @param Header $header
+ */
+ protected function getPagesInstance($document, $header)
+ {
+ return new Pages($document, $header);
+ }
+
+ public function testSetObjects()
+ {
+ $document = $this->getDocumentInstance();
+ $object = $this->getPDFObjectInstance($document);
+
+ // Obj #1 is missing
+ $this->assertNull($document->getObjectById(1));
+ $document->setObjects([1 => $object]);
+
+ // Obj #1 exists
+ $this->assertTrue($document->getObjectById(1) instanceof PDFObject);
+
+ $content = '<>';
+ $header = Header::parse($content, $document);
+ $object = $this->getPDFObjectInstance($document, $header);
+ $document->setObjects([2 => $object]);
+
+ // Obj #1 is missing
+ $this->assertNull($document->getObjectById(1));
+
+ // Obj #2 exists
+ $this->assertTrue($document->getObjectById(2) instanceof PDFObject);
+ }
+
+ public function testGetObjects()
+ {
+ $document = $this->getDocumentInstance();
+ $object1 = $this->getPDFObjectInstance($document);
+ $content = '<>unparsed content';
+ $header = Header::parse($content, $document);
+
+ $object2 = $this->getPageInstance($document, $header);
+ $document->setObjects([1 => $object1, 2 => $object2]);
+
+ $objects = $document->getObjects();
+ $this->assertEquals(2, \count($objects));
+ $this->assertTrue($objects[1] instanceof PDFObject);
+ $this->assertTrue($objects[2] instanceof PDFObject);
+ $this->assertTrue($objects[2] instanceof Page);
+ }
+
+ public function testDictionary()
+ {
+ $document = $this->getDocumentInstance();
+ $objects = $document->getDictionary();
+ $this->assertEquals(0, \count($objects));
+ $object1 = $this->getPDFObjectInstance($document);
+
+ $content = '<>';
+ $header = Header::parse($content, $document);
+ $object2 = $this->getPageInstance($document, $header);
+ $document->setObjects([1 => $object1, 2 => $object2]);
+
+ $objects = $document->getDictionary();
+ $this->assertEquals(1, \count($objects));
+ $this->assertEquals(1, \count($objects['Page']));
+ $this->assertEquals(2, $objects['Page'][2]);
+ }
+
+ public function testGetObjectsByType()
+ {
+ $document = $this->getDocumentInstance();
+ $object1 = $this->getPDFObjectInstance($document);
+ $content = '<>';
+ $header = Header::parse($content, $document);
+ $object2 = $this->getPageInstance($document, $header);
+ $document->setObjects([1 => $object1, 2 => $object2]);
+
+ $objects = $document->getObjectsByType('Page');
+ $this->assertEquals(1, \count($objects));
+ $this->assertTrue($objects[2] instanceof PDFObject);
+ $this->assertTrue($objects[2] instanceof Page);
+ }
+
+ public function testGetPages()
+ {
+ $document = $this->getDocumentInstance();
+
+ // Listing pages from type Page
+ $content = '<>';
+ $header = Header::parse($content, $document);
+ $object1 = $this->getPageInstance($document, $header);
+ $header = Header::parse($content, $document);
+ $object2 = $this->getPageInstance($document, $header);
+ $document->setObjects([1 => $object1, 2 => $object2]);
+ $pages = $document->getPages();
+
+ $this->assertEquals(2, \count($pages));
+ $this->assertTrue($pages[0] instanceof Page);
+ $this->assertTrue($pages[1] instanceof Page);
+
+ // Listing pages from type Pages (kids)
+ $content = '<>';
+ $header = Header::parse($content, $document);
+ $object1 = $this->getPageInstance($document, $header);
+ $header = Header::parse($content, $document);
+ $object2 = $this->getPageInstance($document, $header);
+ $header = Header::parse($content, $document);
+ $object3 = $this->getPageInstance($document, $header);
+
+ $content = '<>';
+ $header = Header::parse($content, $document);
+ $object4 = $this->getPagesInstance($document, $header);
+
+ $content = '<>';
+ $header = Header::parse($content, $document);
+ $object5 = $this->getPagesInstance($document, $header);
+
+ $document->setObjects([
+ '1_0' => $object1,
+ '2_0' => $object2,
+ '3_0' => $object3,
+ '4_0' => $object4,
+ '5_0' => $object5,
+ ]);
+ $pages = $document->getPages();
+
+ $this->assertEquals(3, \count($pages));
+ $this->assertTrue($pages[0] instanceof Page);
+ $this->assertTrue($pages[1] instanceof Page);
+ $this->assertTrue($pages[2] instanceof Page);
+
+ // Listing pages from type Catalog
+ $content = '<>';
+ $header = Header::parse($content, $document);
+ $object1 = $this->getPageInstance($document, $header);
+ $header = Header::parse($content, $document);
+ $object2 = $this->getPageInstance($document, $header);
+ $header = Header::parse($content, $document);
+ $object3 = $this->getPageInstance($document, $header);
+ $content = '<>';
+ $header = Header::parse($content, $document);
+ $object4 = $this->getPagesInstance($document, $header);
+ $content = '<>';
+ $header = Header::parse($content, $document);
+ $object5 = $this->getPagesInstance($document, $header);
+ $content = '<>';
+ $header = Header::parse($content, $document);
+ $object6 = $this->getPagesInstance($document, $header);
+ $document->setObjects(
+ [
+ '1_0' => $object1,
+ '2_0' => $object2,
+ '3_0' => $object3,
+ '4_0' => $object4,
+ '5_0' => $object5,
+ '6_0' => $object6,
+ ]
+ );
+ $pages = $document->getPages();
+ $this->assertEquals(3, \count($pages));
+ $this->assertTrue($pages[0] instanceof Page);
+ $this->assertTrue($pages[1] instanceof Page);
+ $this->assertTrue($pages[2] instanceof Page);
+ }
+
+ public function testGetPagesMissingCatalog()
+ {
+ $this->expectException(Exception::class);
+ $this->expectExceptionMessage('Missing catalog.');
+
+ // Missing catalog
+ $document = $this->getDocumentInstance();
+ $document->getPages();
+ }
+}
diff --git a/tests/Integration/Element/ElementArrayTest.php b/tests/Integration/Element/ElementArrayTest.php
new file mode 100644
index 00000000..183eb6a5
--- /dev/null
+++ b/tests/Integration/Element/ElementArrayTest.php
@@ -0,0 +1,184 @@
+
+ * @date 2020-06-02
+ *
+ * @author Sébastien MALOT
+ * @date 2017-01-03
+ *
+ * @license LGPLv3
+ * @url
+ *
+ * PdfParser is a pdf library written in PHP, extraction oriented.
+ * Copyright (C) 2017 - Sébastien MALOT
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.
+ * If not, see .
+ */
+
+namespace Tests\Smalot\PDFParser\Integration\Element;
+
+use Smalot\PdfParser\Document;
+use Smalot\PdfParser\Element\ElementArray;
+use Smalot\PdfParser\Element\ElementNumeric;
+use Smalot\PdfParser\Header;
+use Smalot\PdfParser\Page;
+use Test\Smalot\PdfParser\TestCase;
+
+class ElementArrayTest extends TestCase
+{
+ public function testParse()
+ {
+ $document = $this->getDocumentInstance();
+
+ // Skipped.
+ $offset = 0;
+ $element = ElementArray::parse('ABC', $document, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementArray::parse(' / [ 4 2 ] ', $document, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementArray::parse(' 0 [ 4 2 ] ', $document, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementArray::parse(" 0 \n [ 4 2 ] ", $document, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ // Valid.
+ $offset = 0;
+ $element = ElementArray::parse(' [ 4 2 ] ', $document, $offset);
+ $this->assertTrue($element->contains(2));
+ $this->assertTrue($element->contains(4));
+ $this->assertFalse($element->contains(8));
+ $this->assertEquals(8, $offset);
+
+ $offset = 0;
+ $element = ElementArray::parse(' [ 4 2 ]', $document, $offset);
+ $this->assertTrue($element->contains(2));
+ $this->assertTrue($element->contains(4));
+ $this->assertFalse($element->contains(8));
+ $this->assertEquals(8, $offset);
+
+ $offset = 0;
+ $element = ElementArray::parse('[ 4 2 ]', $document, $offset);
+ $this->assertTrue($element->contains(2));
+ $this->assertTrue($element->contains(4));
+ $this->assertFalse($element->contains(8));
+ $this->assertEquals(7, $offset);
+
+ $offset = 0;
+ $element = ElementArray::parse(" \n [ 4 2 ] ", $document, $offset);
+ $this->assertTrue($element->contains(2));
+ $this->assertTrue($element->contains(4));
+ $this->assertFalse($element->contains(8));
+ $this->assertEquals(10, $offset);
+ }
+
+ public function testGetContent()
+ {
+ $val_4 = new ElementNumeric('4');
+ $val_2 = new ElementNumeric('2');
+ $element = new ElementArray([$val_4, $val_2]);
+
+ $content = $element->getContent();
+ $this->assertCount(2, $content);
+ }
+
+ public function testContains()
+ {
+ $val_4 = new ElementNumeric('4');
+ $val_2 = new ElementNumeric('2');
+ $element = new ElementArray([$val_4, $val_2]);
+
+ $this->assertTrue($element->contains(2));
+ $this->assertTrue($element->contains(4));
+
+ $this->assertFalse($element->contains(8));
+ }
+
+ public function testResolveXRef()
+ {
+ // Document with text.
+ $filename = $this->rootDir.'/samples/Document1_pdfcreator_nocompressed.pdf';
+ $parser = $this->getParserInstance();
+ $document = $parser->parseFile($filename);
+ $object = $document->getObjectById('3_0');
+ $kids = $object->get('Kids');
+
+ $this->assertTrue($kids instanceof ElementArray);
+ $this->assertCount(1, $kids->getContent());
+
+ $pages = $kids->getContent();
+ $this->assertTrue(reset($pages) instanceof Page);
+ }
+
+ public function testGetDetails()
+ {
+ $document = $this->getDocumentInstance();
+ $content = '<> [8 [9 <>]]]>>';
+ $details_reference = [
+ 'Type' => 'Page',
+ 'Types' => [
+ 8,
+ ],
+ 'Sizes' => [
+ 1,
+ 2,
+ 3,
+ 4,
+ 5,
+ [
+ 'Subtype' => 'XObject',
+ ],
+ [
+ 8,
+ [
+ 9,
+ [
+ 'FontSize' => 10,
+ ],
+ ],
+ ],
+ ],
+ ];
+ $header = Header::parse($content, $document);
+ $details = $header->getDetails();
+
+ $this->assertCount(3, $details);
+ $this->assertEquals($details_reference, $details);
+ }
+
+ public function test__toString()
+ {
+ $val_4 = new ElementNumeric('4');
+ $val_2 = new ElementNumeric('2');
+ $element = new ElementArray([$val_4, $val_2]);
+ $this->assertEquals('4,2', (string) $element);
+
+ $document = $this->getDocumentInstance();
+ $element = ElementArray::parse(' [ 4 2 ]', $document);
+ $this->assertEquals('4,2', (string) $element);
+ }
+}
diff --git a/tests/Integration/Element/ElementBooleanTest.php b/tests/Integration/Element/ElementBooleanTest.php
new file mode 100644
index 00000000..20b15210
--- /dev/null
+++ b/tests/Integration/Element/ElementBooleanTest.php
@@ -0,0 +1,145 @@
+
+ * @date 2020-06-02
+ *
+ * @author Sébastien MALOT
+ * @date 2017-01-03
+ *
+ * @license LGPLv3
+ * @url
+ *
+ * PdfParser is a pdf library written in PHP, extraction oriented.
+ * Copyright (C) 2017 - Sébastien MALOT
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.
+ * If not, see .
+ */
+
+namespace Tests\Smalot\PdfParser\Integration\Element;
+
+use Smalot\PdfParser\Element\ElementBoolean;
+use Test\Smalot\PdfParser\TestCase;
+
+class ElementBooleanTest extends TestCase
+{
+ public function testParse()
+ {
+ // Skipped.
+ $offset = 0;
+ $element = ElementBoolean::parse('ABC', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementBoolean::parse(' [ false ]', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementBoolean::parse(' << true >>', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementBoolean::parse(' / false ', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementBoolean::parse(' 0 true ', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementBoolean::parse(" 0 \n true ", null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ // Valid.
+ $offset = 0;
+ $element = ElementBoolean::parse(' true ', null, $offset);
+ $this->assertTrue($element->getContent());
+ $this->assertEquals(5, $offset);
+
+ $offset = 0;
+ $element = ElementBoolean::parse(' TRUE ', null, $offset);
+ $this->assertTrue($element->getContent());
+ $this->assertEquals(5, $offset);
+
+ $offset = 0;
+ $element = ElementBoolean::parse(' True', null, $offset);
+ $this->assertTrue($element->getContent());
+ $this->assertEquals(5, $offset);
+
+ $offset = 0;
+ $element = ElementBoolean::parse('true', null, $offset);
+ $this->assertTrue($element->getContent());
+ $this->assertEquals(4, $offset);
+
+ $offset = 0;
+ $element = ElementBoolean::parse('False', null, $offset);
+ $this->assertFalse($element->getContent());
+ $this->assertEquals(5, $offset);
+
+ $offset = 0;
+ $element = ElementBoolean::parse(" \n true ", null, $offset);
+ $this->assertTrue($element->getContent());
+ $this->assertEquals(7, $offset);
+ }
+
+ public function testGetContent()
+ {
+ $element = new ElementBoolean('true');
+ $this->assertTrue($element->getContent());
+
+ $element = new ElementBoolean('false');
+ $this->assertFalse($element->getContent());
+ }
+
+ public function testEquals()
+ {
+ $element = new ElementBoolean('true');
+ $this->assertTrue($element->equals(true));
+ $this->assertFalse($element->equals(1));
+ $this->assertFalse($element->equals(false));
+ $this->assertFalse($element->equals(null));
+
+ $element = new ElementBoolean('false');
+ $this->assertTrue($element->equals(false));
+ $this->assertFalse($element->equals(0));
+ $this->assertFalse($element->equals(true));
+ $this->assertFalse($element->equals(null));
+ }
+
+ public function testContains()
+ {
+ $element = new ElementBoolean('true');
+ $this->assertTrue($element->contains(true));
+ $this->assertFalse($element->contains(false));
+ $this->assertFalse($element->contains(1));
+ }
+
+ public function test__toString()
+ {
+ $element = new ElementBoolean('true');
+ $this->assertEquals('true', (string) $element);
+
+ $element = new ElementBoolean('false');
+ $this->assertEquals('false', (string) $element);
+ }
+}
diff --git a/tests/Integration/Element/ElementDateTest.php b/tests/Integration/Element/ElementDateTest.php
new file mode 100644
index 00000000..ee5e30b1
--- /dev/null
+++ b/tests/Integration/Element/ElementDateTest.php
@@ -0,0 +1,182 @@
+
+ * @date 2020-06-02
+ *
+ * @author Sébastien MALOT
+ * @date 2017-01-03
+ *
+ * @license LGPLv3
+ * @url
+ *
+ * PdfParser is a pdf library written in PHP, extraction oriented.
+ * Copyright (C) 2017 - Sébastien MALOT
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.
+ * If not, see .
+ */
+
+namespace Tests\Smalot\PdfParser\Integration\Element;
+
+use DateTime;
+use Exception;
+use Smalot\PdfParser\Element\ElementDate;
+use Test\Smalot\PdfParser\TestCase;
+
+class ElementDateTest extends TestCase
+{
+ public function testParse()
+ {
+ // Skipped.
+ $offset = 0;
+ $element = ElementDate::parse('ABC', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementDate::parse(' [ (ABC) 5 6 ]', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementDate::parse(' << (invalid) >>', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementDate::parse(' / (FlateDecode) ', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementDate::parse(' 0 (FlateDecode) ', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementDate::parse(" 0 \n (FlateDecode) ", null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ // Valid.
+ $offset = 0;
+ $element = ElementDate::parse(' (D:20130901235555+02\'00\') ', null, $offset);
+ $element->setFormat('c');
+ $this->assertTrue($element->getContent() instanceof DateTime);
+ $this->assertEquals('2013-09-01T23:55:55+02:00', (string) $element);
+ $this->assertEquals(26, $offset);
+
+ $offset = 0;
+ $element = ElementDate::parse(' (D:20130901235555+02\'00\') ', null, $offset);
+ $element->setFormat('c');
+ $this->assertTrue($element->getContent() instanceof DateTime);
+ $this->assertEquals('2013-09-01T23:55:55+02:00', (string) $element);
+ $this->assertEquals(26, $offset);
+
+ $offset = 0;
+ $element = ElementDate::parse(' (D:20130901235555+02\'00\')', null, $offset);
+ $element->setFormat('c');
+ $this->assertTrue($element->getContent() instanceof DateTime);
+ $this->assertEquals('2013-09-01T23:55:55+02:00', (string) $element);
+ $this->assertEquals(26, $offset);
+
+ $offset = 0;
+ $element = ElementDate::parse('(D:20130901235555+02\'00\')', null, $offset);
+ $element->setFormat('c');
+ $this->assertTrue($element->getContent() instanceof DateTime);
+ $this->assertEquals('2013-09-01T23:55:55+02:00', (string) $element);
+ $this->assertEquals(25, $offset);
+
+ $offset = 0;
+ $element = ElementDate::parse(" \n (D:20130901235555+02'00') ", null, $offset);
+ $element->setFormat('c');
+ $this->assertTrue($element->getContent() instanceof DateTime);
+ $this->assertEquals('2013-09-01T23:55:55+02:00', (string) $element);
+ $this->assertEquals(28, $offset);
+
+ $offset = 0;
+ $element = ElementDate::parse(" \n (D:20130901235555) ", null, $offset);
+ $element->setFormat('c');
+ $this->assertTrue($element->getContent() instanceof DateTime);
+ $this->assertEquals('2013-09-01T23:55:55+00:00', (string) $element);
+ $this->assertEquals(21, $offset);
+
+ $offset = 0;
+ $element = ElementDate::parse("(D:20131206091846Z00'00')", null, $offset);
+ $element->setFormat('c');
+ $this->assertTrue($element->getContent() instanceof DateTime);
+ $this->assertEquals('2013-12-06T09:18:46+00:00', (string) $element);
+ $this->assertEquals(25, $offset);
+
+ $offset = 0;
+ $element = ElementDate::parse(" \n (D:1-23-2014, 19:02:15-03'00') ", null, $offset);
+ $element->setFormat('c');
+ $this->assertTrue($element->getContent() instanceof DateTime);
+ $this->assertEquals('2014-01-23T19:02:15-03:00', (string) $element);
+ $this->assertEquals(33, $offset);
+
+ // Format invalid
+ $offset = 0;
+ $element = ElementDate::parse(" \n (D:2013+02'00') ", null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+ }
+
+ public function testGetContent()
+ {
+ $element = new ElementDate(new DateTime('2013-09-01 23:55:55+02:00'));
+ $this->assertEquals(new DateTime('2013-09-01 21:55:55+00:00'), $element->getContent());
+ }
+
+ public function testGetContentInvalidParameter()
+ {
+ $this->expectException(Exception::class);
+
+ $element = new ElementDate('2013-09-01 23:55:55+02:00');
+ $this->assertEquals(new DateTime('2013-09-01 21:55:55+02:00'), $element->getContent());
+ }
+
+ public function testEquals()
+ {
+ $element = new ElementDate(new DateTime('2013-09-01 23:55:55+02:00'));
+ $element->setFormat('c');
+
+ $this->assertTrue($element->equals('2013-09-01T23:55:55+02:00'));
+ $this->assertFalse($element->equals('2013-09-01T23:55:55+01:00'));
+
+ $this->assertTrue($element->equals(new DateTime('2013-09-01T21:55:55+00:00')));
+ $this->assertFalse($element->equals(new DateTime('2013-09-01T23:55:55+01:00')));
+
+ $this->assertFalse($element->equals('ABC'));
+ }
+
+ public function testContains()
+ {
+ $element = new ElementDate(new DateTime('2013-09-01 23:55:55+02:00'));
+
+ $this->assertTrue($element->contains('2013-09-01T21:55:55+00:00'));
+ $this->assertFalse($element->contains('2013-06-15'));
+ }
+
+ public function test__toString()
+ {
+ $element = new ElementDate(new DateTime('2013-09-01 23:55:55+02:00'));
+
+ $element->setFormat('c');
+ $this->assertEquals('2013-09-01T23:55:55+02:00', (string) $element);
+ }
+}
diff --git a/tests/Integration/Element/ElementHexaTest.php b/tests/Integration/Element/ElementHexaTest.php
new file mode 100644
index 00000000..caa9fea7
--- /dev/null
+++ b/tests/Integration/Element/ElementHexaTest.php
@@ -0,0 +1,118 @@
+
+ * @date 2020-06-02
+ *
+ * @author Sébastien MALOT
+ * @date 2017-01-03
+ *
+ * @license LGPLv3
+ * @url
+ *
+ * PdfParser is a pdf library written in PHP, extraction oriented.
+ * Copyright (C) 2017 - Sébastien MALOT
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.
+ * If not, see .
+ */
+
+namespace Tests\Smalot\PdfParser\Integration\Element;
+
+use Smalot\PdfParser\Element\ElementDate;
+use Smalot\PdfParser\Element\ElementHexa;
+use Smalot\PdfParser\Element\ElementString;
+use Test\Smalot\PdfParser\TestCase;
+
+class ElementHexaTest extends TestCase
+{
+ public function testParse()
+ {
+ // Skipped.
+ $offset = 0;
+ $element = ElementHexa::parse('ABC', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementHexa::parse(' [ <0020> 5 6 ]', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementHexa::parse(' << <0020> >>', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementHexa::parse(' / <0020> ', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementHexa::parse(' 0 <0020> ', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementHexa::parse(" 0 \n <0020> ", null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ // Valid.
+ $offset = 0;
+ $element = ElementHexa::parse(' <0020> ', null, $offset);
+ $this->assertEquals(' ', $element->getContent());
+ $this->assertEquals(7, $offset);
+
+ $offset = 0;
+ $element = ElementHexa::parse(' <0020> ', null, $offset);
+ $this->assertEquals(' ', $element->getContent());
+ $this->assertEquals(7, $offset);
+
+ $offset = 0;
+ $element = ElementHexa::parse(' <0020>', null, $offset);
+ $this->assertEquals(' ', $element->getContent());
+ $this->assertEquals(7, $offset);
+
+ $offset = 0;
+ $element = ElementHexa::parse('<0020>', null, $offset);
+ $this->assertEquals(' ', $element->getContent());
+ $this->assertEquals(6, $offset);
+
+ $offset = 0;
+ $element = ElementHexa::parse(" \n <0020> ", null, $offset);
+ $this->assertEquals(' ', $element->getContent());
+ $this->assertEquals(9, $offset);
+
+ $offset = 0;
+ $element = ElementHexa::parse(" \n <5465616d204d616e6167656d656e742053797374656d73> ", null, $offset);
+ $this->assertEquals('Team Management Systems', $element->getContent());
+ $this->assertEquals(51, $offset);
+
+ $offset = 0;
+ $element = ElementHexa::parse(" \n <5265706f72744275696c646572> ", null, $offset);
+ $this->assertTrue($element instanceof ElementString);
+ $this->assertEquals('ReportBuilder', $element->getContent());
+ $this->assertEquals(31, $offset);
+
+ $offset = 0;
+ $element = ElementHexa::parse(" \n <443a3230313331323137313334303435303027303027> ", null, $offset);
+ $this->assertTrue($element instanceof ElementDate);
+ $this->assertEquals('2013-12-17T13:40:45+00:00', (string) $element);
+ $this->assertEquals(49, $offset);
+ }
+}
diff --git a/tests/Integration/Element/ElementMissingTest.php b/tests/Integration/Element/ElementMissingTest.php
new file mode 100644
index 00000000..cdc69b30
--- /dev/null
+++ b/tests/Integration/Element/ElementMissingTest.php
@@ -0,0 +1,69 @@
+
+ * @date 2020-06-02
+ *
+ * @author Sébastien MALOT
+ * @date 2017-01-03
+ *
+ * @license LGPLv3
+ * @url
+ *
+ * PdfParser is a pdf library written in PHP, extraction oriented.
+ * Copyright (C) 2017 - Sébastien MALOT
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.
+ * If not, see .
+ */
+
+namespace Tests\Smalot\PdfParser\Integration\Element;
+
+use Smalot\PdfParser\Element\ElementMissing;
+use Test\Smalot\PdfParser\TestCase;
+
+class ElementMissingTest extends TestCase
+{
+ public function testEquals()
+ {
+ $element = new ElementMissing(null);
+ $this->assertFalse($element->equals(null));
+ $this->assertFalse($element->equals(true));
+ $this->assertFalse($element->equals('A'));
+ $this->assertFalse($element->equals(false));
+ }
+
+ public function testGetContent()
+ {
+ $element = new ElementMissing(null);
+ $this->assertFalse($element->getContent());
+ }
+
+ public function testContains()
+ {
+ $element = new ElementMissing(null);
+ $this->assertFalse($element->contains(null));
+ $this->assertFalse($element->contains(true));
+ $this->assertFalse($element->contains('A'));
+ $this->assertFalse($element->contains(false));
+ }
+
+ public function test__toString()
+ {
+ $element = new ElementMissing(null);
+ $this->assertEquals('', (string) $element);
+ }
+}
diff --git a/tests/Integration/Element/ElementNameTest.php b/tests/Integration/Element/ElementNameTest.php
new file mode 100644
index 00000000..2a2b897d
--- /dev/null
+++ b/tests/Integration/Element/ElementNameTest.php
@@ -0,0 +1,161 @@
+
+ * @date 2020-06-02
+ *
+ * @author Sébastien MALOT
+ * @date 2017-01-03
+ *
+ * @license LGPLv3
+ * @url
+ *
+ * PdfParser is a pdf library written in PHP, extraction oriented.
+ * Copyright (C) 2017 - Sébastien MALOT
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.
+ * If not, see .
+ */
+
+namespace Tests\Smalot\PdfParser\Integration\Element;
+
+use Smalot\PdfParser\Element\ElementName;
+use Test\Smalot\PdfParser\TestCase;
+
+class ElementNameTest extends TestCase
+{
+ public function testParse()
+ {
+ // Skipped.
+ $offset = 0;
+ $element = ElementName::parse('ABC', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+ $offset = 0;
+ $element = ElementName::parse(' [ /ABC 5 6 ]', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+ $offset = 0;
+ $element = ElementName::parse(' << invalid >>', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+ $offset = 0;
+ $element = ElementName::parse(' / FlateDecode ', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+ $offset = 0;
+ $element = ElementName::parse(' 0 /FlateDecode ', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+ $offset = 0;
+ $element = ElementName::parse(" 0 \n /FlateDecode ", null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ // Valid.
+ $offset = 0;
+ $element = ElementName::parse(' /FlateDecode ', null, $offset);
+ $this->assertEquals('FlateDecode', $element->getContent());
+ $this->assertEquals(13, $offset);
+
+ $offset = 0;
+ $element = ElementName::parse(' /FlateDecode', null, $offset);
+ $this->assertEquals('FlateDecode', $element->getContent());
+ $this->assertEquals(13, $offset);
+
+ $offset = 0;
+ $element = ElementName::parse('/FlateDecode', null, $offset);
+ $this->assertEquals('FlateDecode', $element->getContent());
+ $this->assertEquals(12, $offset);
+
+ $offset = 0;
+ $element = ElementName::parse(" \n /FlateDecode ", null, $offset);
+ $this->assertEquals('FlateDecode', $element->getContent());
+ $this->assertEquals(15, $offset);
+
+ $offset = 0;
+ $element = ElementName::parse('/FlateDecode2', null, $offset);
+ $this->assertEquals('FlateDecode2', $element->getContent());
+ $this->assertEquals(13, $offset);
+
+ $offset = 0;
+ $element = ElementName::parse('/Flate-Decode2', null, $offset);
+ $this->assertEquals('Flate-Decode2', $element->getContent());
+ $this->assertEquals(14, $offset);
+
+ $offset = 0;
+ $element = ElementName::parse('/OJHCYD+Cambria', null, $offset);
+ $this->assertEquals('OJHCYD+Cambria', $element->getContent());
+ $this->assertEquals(15, $offset);
+
+ $offset = 0;
+ $element = ElementName::parse('/OJHCYD+Cambria,Bold', null, $offset);
+ $this->assertEquals('OJHCYD+Cambria,Bold', $element->getContent());
+ $this->assertEquals(20, $offset);
+
+ $offset = 0;
+ $element = ElementName::parse('/Flate_Decode2', null, $offset);
+ $this->assertEquals('Flate', $element->getContent());
+ $this->assertEquals(6, $offset);
+
+ $offset = 0;
+ $element = ElementName::parse('/Flate.Decode2', null, $offset);
+ $this->assertEquals('Flate.Decode2', $element->getContent());
+ $this->assertEquals(14, $offset);
+ }
+
+ public function testGetContent()
+ {
+ $element = new ElementName('FlateDecode');
+ $this->assertEquals('FlateDecode', $element->getContent());
+ }
+
+ public function testEquals()
+ {
+ $element = new ElementName('FlateDecode');
+ $this->assertTrue($element->equals('FlateDecode'));
+ $this->assertFalse($element->equals('Flatedecode'));
+
+ $element = new ElementName('FlateDecode2');
+ $this->assertTrue($element->equals('FlateDecode2'));
+ $this->assertFalse($element->equals('FlateDecode3'));
+
+ $element = new ElementName('Flate-Decode2');
+ $this->assertTrue($element->equals('Flate-Decode2'));
+ $this->assertFalse($element->equals('Flate-Decode3'));
+ }
+
+ public function testContains()
+ {
+ $element = new ElementName('FlateDecode');
+ $this->assertTrue($element->contains('FlateDecode'));
+ $this->assertFalse($element->contains('Flatedecode'));
+
+ $element = new ElementName('FlateDecode2');
+ $this->assertTrue($element->contains('FlateDecode2'));
+ $this->assertFalse($element->contains('FlateDecode3'));
+
+ $element = new ElementName('Flate-Decode2');
+ $this->assertTrue($element->contains('Flate-Decode2'));
+ $this->assertFalse($element->contains('Flate-Decode3'));
+ }
+
+ public function test__toString()
+ {
+ $element = new ElementName('FlateDecode');
+ $this->assertEquals('FlateDecode', (string) $element);
+ }
+}
diff --git a/tests/Integration/Element/ElementNullTest.php b/tests/Integration/Element/ElementNullTest.php
new file mode 100644
index 00000000..c800b1de
--- /dev/null
+++ b/tests/Integration/Element/ElementNullTest.php
@@ -0,0 +1,128 @@
+
+ * @date 2020-06-02
+ *
+ * @author Sébastien MALOT
+ * @date 2017-01-03
+ *
+ * @license LGPLv3
+ * @url
+ *
+ * PdfParser is a pdf library written in PHP, extraction oriented.
+ * Copyright (C) 2017 - Sébastien MALOT
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.
+ * If not, see .
+ */
+
+namespace Tests\Smalot\PdfParser\Integration\Element;
+
+use Smalot\PdfParser\Element\ElementNull;
+use Test\Smalot\PdfParser\TestCase;
+
+class ElementNullTest extends TestCase
+{
+ public function testParse()
+ {
+ // Skipped.
+ $offset = 0;
+ $element = ElementNull::parse('ABC', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementNull::parse(' [ null ]', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementNull::parse(' << null >>', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementNull::parse(' / null ', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementNull::parse(' 0 null ', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementNull::parse(" 0 \n null ", null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ // Valid.
+ $offset = 0;
+ $element = ElementNull::parse(' null ', null, $offset);
+ $this->assertTrue(null === $element->getContent());
+ $this->assertEquals(5, $offset);
+
+ $offset = 0;
+ $element = ElementNull::parse(' null ', null, $offset);
+ $this->assertTrue(null === $element->getContent());
+ $this->assertEquals(5, $offset);
+
+ $offset = 0;
+ $element = ElementNull::parse(' null', null, $offset);
+ $this->assertTrue(null === $element->getContent());
+ $this->assertEquals(5, $offset);
+
+ $offset = 0;
+ $element = ElementNull::parse('null', null, $offset);
+ $this->assertTrue(null === $element->getContent());
+ $this->assertEquals(4, $offset);
+
+ $offset = 0;
+ $element = ElementNull::parse(" \n null ", null, $offset);
+ $this->assertTrue(null === $element->getContent());
+ $this->assertEquals(7, $offset);
+ }
+
+ public function testGetContent()
+ {
+ $element = new ElementNull('null');
+ $this->assertTrue(null === $element->getContent());
+ }
+
+ public function testEquals()
+ {
+ $element = new ElementNull('null');
+ $this->assertTrue($element->equals(null));
+ $this->assertFalse($element->equals(false));
+ $this->assertFalse($element->equals(0));
+ $this->assertFalse($element->equals(1));
+ }
+
+ public function testContains()
+ {
+ $element = new ElementNull('null');
+ $this->assertTrue($element->contains(null));
+ $this->assertFalse($element->contains(false));
+ $this->assertFalse($element->contains(0));
+ }
+
+ public function test__toString()
+ {
+ $element = new ElementNull('null');
+ $this->assertEquals('null', (string) $element);
+ }
+}
diff --git a/tests/Integration/Element/ElementNumericTest.php b/tests/Integration/Element/ElementNumericTest.php
new file mode 100644
index 00000000..56c02dd5
--- /dev/null
+++ b/tests/Integration/Element/ElementNumericTest.php
@@ -0,0 +1,196 @@
+
+ * @date 2020-06-02
+ *
+ * @author Sébastien MALOT
+ * @date 2017-01-03
+ *
+ * @license LGPLv3
+ * @url
+ *
+ * PdfParser is a pdf library written in PHP, extraction oriented.
+ * Copyright (C) 2017 - Sébastien MALOT
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.
+ * If not, see .
+ */
+
+namespace Tests\Smalot\PdfParser\Integration\Element;
+
+use Smalot\PdfParser\Element\ElementNumeric;
+use Test\Smalot\PdfParser\TestCase;
+
+class ElementNumericTest extends TestCase
+{
+ public function testParse()
+ {
+ // Skipped.
+ $offset = 0;
+ $element = ElementNumeric::parse('ABC', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementNumeric::parse(' [ 2 ]', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementNumeric::parse(' /2', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementNumeric::parse(" /2 \n 2", null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ // Valid.
+ $offset = 0;
+ $element = ElementNumeric::parse(' -2', null, $offset);
+ $this->assertEquals(-2.0, $element->getContent());
+ $this->assertEquals(3, $offset);
+
+ $offset = 0;
+ $element = ElementNumeric::parse('2BC', null, $offset);
+ $this->assertEquals(2.0, $element->getContent());
+ $this->assertEquals(1, $offset);
+
+ $offset = 0;
+ $element = ElementNumeric::parse(' 2BC', null, $offset);
+ $this->assertEquals(2.0, $element->getContent());
+ $this->assertEquals(2, $offset);
+
+ $offset = 0;
+ $element = ElementNumeric::parse(' -2BC', null, $offset);
+ $this->assertEquals(-2.0, $element->getContent());
+ $this->assertEquals(3, $offset);
+
+ $offset = 0;
+ $element = ElementNumeric::parse(' -2', null, $offset);
+ $this->assertEquals(-2.0, $element->getContent());
+ $this->assertEquals(3, $offset);
+
+ $offset = 0;
+ $element = ElementNumeric::parse(' 2 0 obj', null, $offset);
+ $this->assertEquals(2.0, $element->getContent());
+ $this->assertEquals(2, $offset);
+
+ $offset = 0;
+ $element = ElementNumeric::parse(" \n -2 ", null, $offset);
+ $this->assertEquals(-2.0, $element->getContent());
+ $this->assertEquals(5, $offset);
+ }
+
+ public function testGetContent()
+ {
+ $element = new ElementNumeric('B');
+ $this->assertEquals(0.0, $element->getContent());
+
+ $element = new ElementNumeric('-2.5');
+ $this->assertEquals(-2.5, $element->getContent());
+
+ $element = new ElementNumeric('-2');
+ $this->assertEquals(-2.0, $element->getContent());
+
+ $element = new ElementNumeric(' -2');
+ $this->assertEquals(-2.0, $element->getContent());
+
+ $element = new ElementNumeric('2.5');
+ $this->assertEquals(2.5, $element->getContent());
+
+ $element = new ElementNumeric('2');
+ $this->assertEquals(2.0, $element->getContent());
+ }
+
+ public function testEquals()
+ {
+ $element = new ElementNumeric('1');
+ $this->assertFalse($element->equals('B'));
+ $element = new ElementNumeric('1.5');
+ $this->assertFalse($element->equals('B'));
+
+ $element = new ElementNumeric('2');
+ $this->assertTrue($element->equals('2'));
+ $element = new ElementNumeric('2');
+ $this->assertFalse($element->equals('3'));
+
+ $element = new ElementNumeric('-2');
+ $this->assertTrue($element->equals('-2'));
+ $element = new ElementNumeric('-2');
+ $this->assertFalse($element->equals('-3'));
+
+ $element = new ElementNumeric('2.5');
+ $this->assertTrue($element->equals('2.5'));
+ $element = new ElementNumeric('2.5');
+ $this->assertFalse($element->equals('3.5'));
+
+ $element = new ElementNumeric('-2.5');
+ $this->assertTrue($element->equals('-2.5'));
+ $element = new ElementNumeric('-2.5');
+ $this->assertFalse($element->equals('-3.5'));
+ }
+
+ public function testContains()
+ {
+ $element = new ElementNumeric('1');
+ $this->assertFalse($element->contains('B'));
+ $element = new ElementNumeric('1.5');
+ $this->assertFalse($element->contains('B'));
+
+ $element = new ElementNumeric('2');
+ $this->assertTrue($element->contains('2'));
+ $element = new ElementNumeric('2');
+ $this->assertFalse($element->contains('3'));
+
+ $element = new ElementNumeric('-2');
+ $this->assertTrue($element->contains('-2'));
+ $element = new ElementNumeric('-2');
+ $this->assertFalse($element->contains('-3'));
+
+ $element = new ElementNumeric('2.5');
+ $this->assertTrue($element->contains('2.5'));
+ $element = new ElementNumeric('2.5');
+ $this->assertFalse($element->contains('3.5'));
+
+ $element = new ElementNumeric('-2.5');
+ $this->assertTrue($element->contains('-2.5'));
+ $element = new ElementNumeric('-2.5');
+ $this->assertFalse($element->contains('-3.5'));
+ }
+
+ public function test__toString()
+ {
+ $element = new ElementNumeric('B');
+ $this->assertEquals('0', (string) $element);
+ $element = new ElementNumeric('1B');
+ $this->assertEquals('1', (string) $element);
+
+ $element = new ElementNumeric('2');
+ $this->assertEquals('2', (string) $element);
+
+ $element = new ElementNumeric('-2');
+ $this->assertEquals('-2', (string) $element);
+
+ $element = new ElementNumeric('2.5');
+ $this->assertEquals('2.5', (string) $element);
+
+ $element = new ElementNumeric('-2.5');
+ $this->assertEquals('-2.5', (string) $element);
+ }
+}
diff --git a/tests/Integration/Element/ElementStringTest.php b/tests/Integration/Element/ElementStringTest.php
new file mode 100644
index 00000000..140c862c
--- /dev/null
+++ b/tests/Integration/Element/ElementStringTest.php
@@ -0,0 +1,170 @@
+
+ * @date 2020-06-02
+ *
+ * @author Sébastien MALOT
+ * @date 2017-01-03
+ *
+ * @license LGPLv3
+ * @url
+ *
+ * PdfParser is a pdf library written in PHP, extraction oriented.
+ * Copyright (C) 2017 - Sébastien MALOT
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.
+ * If not, see .
+ */
+
+namespace Tests\Smalot\PdfParser\Integration\Element;
+
+use Smalot\PdfParser\Element\ElementString;
+use Test\Smalot\PdfParser\TestCase;
+
+class ElementStringTest extends TestCase
+{
+ public function testParse()
+ {
+ // Skipped.
+ $offset = 0;
+ $element = ElementString::parse('ABC', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementString::parse(' [ (ABC) 5 6 ]', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementString::parse(' << (invalid) >>', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementString::parse(' / (FlateDecode) ', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementString::parse(' 0 (FlateDecode) ', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementString::parse(" 0 \n (FlateDecode) ", null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ // Valid.
+ $offset = 0;
+ $element = ElementString::parse(' (Copyright) ', null, $offset);
+ $this->assertEquals('Copyright', $element->getContent());
+ $this->assertEquals(12, $offset);
+
+ $offset = 0;
+ $element = ElementString::parse(' (Copyright) ', null, $offset);
+ $this->assertEquals('Copyright', $element->getContent());
+ $this->assertEquals(12, $offset);
+
+ $offset = 0;
+ $element = ElementString::parse(' (Copyright)', null, $offset);
+ $this->assertEquals('Copyright', $element->getContent());
+ $this->assertEquals(12, $offset);
+
+ $offset = 0;
+ $element = ElementString::parse('(Copyright)', null, $offset);
+ $this->assertEquals('Copyright', $element->getContent());
+ $this->assertEquals(11, $offset);
+
+ $offset = 0;
+ $element = ElementString::parse('(Copy-right2)', null, $offset);
+ $this->assertEquals('Copy-right2', $element->getContent());
+ $this->assertEquals(13, $offset);
+
+ $offset = 0;
+ $element = ElementString::parse(" \n (Copyright) ", null, $offset);
+ $this->assertEquals('Copyright', $element->getContent());
+ $this->assertEquals(14, $offset);
+
+ $offset = 0;
+ $element = ElementString::parse('()', null, $offset);
+ $this->assertEquals('', $element->getContent());
+ $this->assertEquals(2, $offset);
+
+ /*
+ * Complex study case : Unicode + octal.
+ */
+ $offset = 0;
+ $element = ElementString::parse('(ABC\\))', null, $offset);
+ $this->assertEquals('ABC)', $element->getContent());
+ $this->assertEquals(7, $offset);
+
+ $offset = 0;
+ $element = ElementString::parse("(\xFE\xFF\\000M)", null, $offset);
+ $this->assertEquals('M', $element->getContent());
+ $this->assertEquals(9, $offset);
+
+ $offset = 0;
+ $element = ElementString::parse('(<20>)', null, $offset);
+ $this->assertEquals(' ', $element->getContent());
+ $this->assertEquals(6, $offset);
+
+ $offset = 0;
+ $element = ElementString::parse('(Gutter\\ console\\ assembly)', null, $offset);
+ $this->assertEquals('Gutter console assembly', $element->getContent());
+ $this->assertEquals(27, $offset);
+ }
+
+ public function testGetContent()
+ {
+ $element = new ElementString('Copyright');
+ $this->assertEquals('Copyright', $element->getContent());
+ }
+
+ public function testEquals()
+ {
+ $element = new ElementString('CopyRight');
+ $this->assertTrue($element->equals('CopyRight'));
+ $this->assertFalse($element->equals('Flatedecode'));
+
+ $element = new ElementString('CopyRight2');
+ $this->assertTrue($element->equals('CopyRight2'));
+ $this->assertFalse($element->equals('CopyRight3'));
+
+ $element = new ElementString('Flate-Decode2');
+ $this->assertTrue($element->equals('Flate-Decode2'));
+ $this->assertFalse($element->equals('Flate-Decode3'));
+ }
+
+ public function testContains()
+ {
+ $element = new ElementString('CopyRight');
+ $this->assertTrue($element->contains('CopyRight'));
+ $this->assertFalse($element->contains('Copyright'));
+
+ $element = new ElementString('CopyRight2');
+ $this->assertTrue($element->contains('CopyRight2'));
+ $this->assertFalse($element->contains('CopyRight3'));
+ }
+
+ public function test__toString()
+ {
+ $element = new ElementString('CopyRight');
+ $this->assertEquals('CopyRight', (string) $element);
+ }
+}
diff --git a/tests/Integration/Element/ElementStructTest.php b/tests/Integration/Element/ElementStructTest.php
new file mode 100644
index 00000000..fa97f364
--- /dev/null
+++ b/tests/Integration/Element/ElementStructTest.php
@@ -0,0 +1,92 @@
+
+ * @date 2020-06-02
+ *
+ * @author Sébastien MALOT
+ * @date 2017-01-03
+ *
+ * @license LGPLv3
+ * @url
+ *
+ * PdfParser is a pdf library written in PHP, extraction oriented.
+ * Copyright (C) 2017 - Sébastien MALOT
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.
+ * If not, see .
+ */
+
+namespace TestsIntegration\Element;
+
+use Smalot\PdfParser\Element\ElementStruct;
+use Smalot\PdfParser\Header;
+use Test\Smalot\PdfParser\TestCase;
+
+class ElementStructTest extends TestCase
+{
+ public function testParse()
+ {
+ $document = $this->getDocumentInstance();
+
+ // Skipped.
+ $offset = 0;
+ $element = ElementStruct::parse('ABC', $document, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementStruct::parse(' [ << /Filter /FlateDecode >> ]', $document, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementStruct::parse(' / << /Filter /FlateDecode >> ', $document, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementStruct::parse(' 0 << /Filter /FlateDecode >> ', $document, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementStruct::parse(" 0 \n << /Filter /FlateDecode >> ", $document, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ // Valid.
+ $offset = 0;
+ $element = ElementStruct::parse(' << /Filter /FlateDecode >> ', $document, $offset);
+ $this->assertTrue($element instanceof Header);
+ $this->assertEquals(27, $offset);
+
+ $offset = 0;
+ $element = ElementStruct::parse(' << /Filter /FlateDecode >>', $document, $offset);
+ $this->assertTrue($element instanceof Header);
+ $this->assertEquals(27, $offset);
+
+ $offset = 0;
+ $element = ElementStruct::parse('<< /Filter /FlateDecode >>', $document, $offset);
+ $this->assertTrue($element instanceof Header);
+ $this->assertEquals(26, $offset);
+
+ $offset = 0;
+ $element = ElementStruct::parse(" \n << /Filter /FlateDecode >> ", $document, $offset);
+ $this->assertTrue($element instanceof Header);
+ $this->assertEquals(29, $offset);
+ }
+}
diff --git a/tests/Integration/Element/ElementXRefTest.php b/tests/Integration/Element/ElementXRefTest.php
new file mode 100644
index 00000000..0e91e9eb
--- /dev/null
+++ b/tests/Integration/Element/ElementXRefTest.php
@@ -0,0 +1,133 @@
+
+ * @date 2020-06-02
+ *
+ * @author Sébastien MALOT
+ * @date 2017-01-03
+ *
+ * @license LGPLv3
+ * @url
+ *
+ * PdfParser is a pdf library written in PHP, extraction oriented.
+ * Copyright (C) 2017 - Sébastien MALOT
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.
+ * If not, see .
+ */
+
+namespace Tests\Smalot\PdfParser\Integration\Element;
+
+use Smalot\PdfParser\Element\ElementXRef;
+use Test\Smalot\PdfParser\TestCase;
+
+class ElementXRefTest extends TestCase
+{
+ public function testParse()
+ {
+ // Skipped.
+ $offset = 0;
+ $element = ElementXRef::parse('ABC', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementXRef::parse(' [ 5 0 R ]', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementXRef::parse(' << 5 0 R >>', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementXRef::parse(' / 5 0 R ', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementXRef::parse(' 0 5 0 R ', null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ $offset = 0;
+ $element = ElementXRef::parse(" 0 \n 5 0 R ", null, $offset);
+ $this->assertFalse($element);
+ $this->assertEquals(0, $offset);
+
+ // Valid.
+ $offset = 0;
+ $element = ElementXRef::parse(' 5 0 R ', null, $offset);
+ $this->assertEquals('5_0', $element->getContent());
+ $this->assertEquals(6, $offset);
+
+ $offset = 0;
+ $element = ElementXRef::parse(' 5 0 R ', null, $offset);
+ $this->assertEquals('5_0', $element->getContent());
+ $this->assertEquals(6, $offset);
+
+ $offset = 0;
+ $element = ElementXRef::parse(' 5 0 R', null, $offset);
+ $this->assertEquals('5_0', $element->getContent());
+ $this->assertEquals(6, $offset);
+
+ $offset = 0;
+ $element = ElementXRef::parse('5 0 R', null, $offset);
+ $this->assertEquals('5_0', $element->getContent());
+ $this->assertEquals(5, $offset);
+
+ $offset = 0;
+ $element = ElementXRef::parse(" \n 5 0 R ", null, $offset);
+ $this->assertEquals('5_0', $element->getContent());
+ $this->assertEquals(8, $offset);
+ }
+
+ public function testGetContent()
+ {
+ $element = new ElementXRef('5_0');
+ $this->assertEquals('5_0', $element->getContent());
+ }
+
+ public function testGetId()
+ {
+ $element = new ElementXRef('5_0');
+ $this->assertEquals('5_0', $element->getId());
+ }
+
+ public function testEquals()
+ {
+ $element = new ElementXRef('5_0');
+ $this->assertTrue($element->equals(5));
+ $this->assertFalse($element->equals(8));
+ $this->assertTrue($element->equals($element));
+ }
+
+ public function testContains()
+ {
+ $element = new ElementXRef('5_0');
+ $this->assertTrue($element->contains(5));
+ $this->assertFalse($element->contains(8));
+ $this->assertTrue($element->contains($element));
+ }
+
+ public function test__toString()
+ {
+ $element = new ElementXRef('5_0');
+ $this->assertEquals('#Obj#5_0', (string) $element);
+ }
+}
diff --git a/tests/Integration/ElementTest.php b/tests/Integration/ElementTest.php
new file mode 100644
index 00000000..5d5a8cbc
--- /dev/null
+++ b/tests/Integration/ElementTest.php
@@ -0,0 +1,152 @@
+
+ * @date 2020-06-01
+ *
+ * @author Sébastien MALOT
+ * @date 2017-01-03
+ *
+ * @license LGPLv3
+ * @url
+ *
+ * PdfParser is a pdf library written in PHP, extraction oriented.
+ * Copyright (C) 2017 - Sébastien MALOT
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.
+ * If not, see .
+ */
+
+namespace Tests\Smalot\PdfParser\Integration;
+
+use Smalot\PdfParser\Element;
+use Smalot\PdfParser\Element\ElementArray;
+use Smalot\PdfParser\Element\ElementBoolean;
+use Smalot\PdfParser\Element\ElementDate;
+use Smalot\PdfParser\Element\ElementName;
+use Smalot\PdfParser\Element\ElementNull;
+use Smalot\PdfParser\Element\ElementNumeric;
+use Smalot\PdfParser\Element\ElementString;
+use Smalot\PdfParser\Element\ElementXRef;
+use Smalot\PdfParser\Header;
+use Test\Smalot\PdfParser\TestCase;
+
+class ElementTest extends TestCase
+{
+ public function testParse()
+ {
+ $document = $this->getDocumentInstance();
+
+ // Only_values = false.
+ $content = '/NameType /FlateDecode
+ /Contents[4 0 R 42]/Fonts<>/NullType
+ null/StringType(hello)/DateType(D:20130901235555+02\'00\')/XRefType 2 0 R
+ /NumericType 8/HexaType<0020>/BooleanType false';
+ $offset = 0;
+
+ $elements = Element::parse($content, $document, $offset, false);
+
+ $this->assertTrue(\array_key_exists('NameType', $elements));
+ $this->assertTrue($elements['NameType'] instanceof ElementName);
+ $this->assertEquals('FlateDecode', $elements['NameType']->getContent());
+
+ $this->assertTrue(\array_key_exists('Contents', $elements));
+ $this->assertTrue($elements['Contents'] instanceof ElementArray);
+ $this->assertTrue($elements['Contents']->contains(42));
+
+ $this->assertTrue(\array_key_exists('Fonts', $elements));
+ $this->assertTrue($elements['Fonts'] instanceof Header);
+
+ $this->assertTrue(\array_key_exists('NullType', $elements));
+ $this->assertTrue($elements['NullType'] instanceof ElementNull);
+ $this->assertEquals('null', (string) $elements['NullType']);
+
+ $this->assertTrue(\array_key_exists('StringType', $elements));
+ $this->assertTrue($elements['StringType'] instanceof ElementString);
+ $this->assertEquals('hello', $elements['StringType']->getContent());
+
+ $this->assertTrue(\array_key_exists('DateType', $elements));
+ $this->assertTrue($elements['DateType'] instanceof ElementDate);
+
+ $this->assertTrue(\array_key_exists('XRefType', $elements));
+ $this->assertTrue($elements['XRefType'] instanceof ElementXRef);
+ $this->assertEquals('2_0', $elements['XRefType']->getId());
+
+ $this->assertTrue(\array_key_exists('NumericType', $elements));
+ $this->assertTrue($elements['NumericType'] instanceof ElementNumeric);
+ $this->assertEquals('8', (string) $elements['NumericType']);
+
+ $this->assertTrue(\array_key_exists('HexaType', $elements));
+ $this->assertTrue($elements['HexaType'] instanceof ElementString);
+ $this->assertEquals(' ', (string) $elements['HexaType']);
+
+ $this->assertTrue(\array_key_exists('BooleanType', $elements));
+ $this->assertTrue($elements['BooleanType'] instanceof ElementBoolean);
+ $this->assertFalse($elements['BooleanType']->getContent());
+
+ // Only_values = true.
+ $content = '/NameType /FlateDecode';
+ $offset = 0;
+ $elements = Element::parse($content, $document, $offset, true);
+ $this->assertEquals(2, \count($elements));
+ $this->assertEquals(22, $offset);
+
+ // Test error.
+ $content = '/NameType /FlateDecode $$$';
+ $offset = 0;
+ $elements = Element::parse($content, $document, $offset, false);
+ $this->assertEquals(1, \count($elements));
+ $this->assertEquals(22, $offset);
+ $this->assertEquals('NameType', key($elements));
+ $this->assertTrue(current($elements) instanceof ElementName);
+
+ $content = '/NameType $$$';
+ $offset = 0;
+ $elements = Element::parse($content, $document, $offset, false);
+ $this->assertEquals(0, $offset);
+ $this->assertEquals(0, \count($elements));
+ }
+
+ public function testGetContent()
+ {
+ $element = $this->getElementInstance(42);
+ $content = $element->getContent();
+ $this->assertEquals(42, $content);
+
+ $element = $this->getElementInstance([4, 2]);
+ $this->assertEquals(2, \count($element->getContent()));
+ }
+
+ public function testEquals()
+ {
+ $element = $this->getElementInstance(2);
+
+ $this->assertTrue($element->equals(2));
+ }
+
+ public function testContains()
+ {
+ $element = $this->getElementInstance([$this->getElementInstance(4), $this->getElementInstance(2)]);
+
+ $this->assertTrue($element->contains(2));
+ $this->assertFalse($element->contains(8));
+ }
+
+ public function test__toString()
+ {
+ $this->assertEquals((string) $this->getElementInstance('2'), '2');
+ }
+}
diff --git a/src/Smalot/PdfParser/Tests/Units/Font.php b/tests/Integration/FontTest.php
similarity index 54%
rename from src/Smalot/PdfParser/Tests/Units/Font.php
rename to tests/Integration/FontTest.php
index 17dfba3a..4936e490 100644
Binary files a/src/Smalot/PdfParser/Tests/Units/Font.php and b/tests/Integration/FontTest.php differ
diff --git a/tests/Integration/HeaderTest.php b/tests/Integration/HeaderTest.php
new file mode 100644
index 00000000..3baf76bf
--- /dev/null
+++ b/tests/Integration/HeaderTest.php
@@ -0,0 +1,144 @@
+
+ * @date 2020-06-01
+ *
+ * @author Sébastien MALOT
+ * @date 2017-01-03
+ *
+ * @license LGPLv3
+ * @url
+ *
+ * PdfParser is a pdf library written in PHP, extraction oriented.
+ * Copyright (C) 2017 - Sébastien MALOT
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.
+ * If not, see .
+ */
+
+namespace Tests\Smalot\PdfParser\Integration;
+
+use Smalot\PdfParser\Element\ElementMissing;
+use Smalot\PdfParser\Element\ElementName;
+use Smalot\PdfParser\Header;
+use Smalot\PdfParser\Page;
+use Smalot\PdfParser\PDFObject;
+use Test\Smalot\PdfParser\TestCase;
+
+/**
+ * Class Header
+ */
+class HeaderTest extends TestCase
+{
+ public function testParse()
+ {
+ $document = $this->getDocumentInstance();
+
+ $content = '<>foo';
+ $position = 0;
+ $header = Header::parse($content, $document, $position);
+
+ $this->assertTrue($header instanceof Header);
+ $this->assertEquals(27, $position);
+ $this->assertEquals(2, \count($header->getElements()));
+
+ // No header to parse
+ $this->assertEquals('Page', (string) $header->get('Type'));
+ $content = 'foo';
+ $position = 0;
+ $header = Header::parse($content, $document, $position);
+
+ $this->assertTrue($header instanceof Header);
+ $this->assertEquals(0, $position);
+ $this->assertEquals(0, \count($header->getElements()));
+
+ $position = 0;
+ $content = "<>";
+ Header::parse($content, $document, $position);
+ $this->assertEquals(212, $position);
+
+ $position = 0;
+ $content = '[5 0 R ] foo';
+ $header = Header::parse($content, $document, $position);
+ $this->assertEquals(8, $position);
+ $this->assertEquals(1, \count($header->getElements()));
+ }
+
+ public function testGetElements()
+ {
+ $document = $this->getDocumentInstance();
+
+ $content = '<>foo';
+ $position = 0;
+ $header = Header::parse($content, $document, $position);
+
+ $elements = $header->getElements();
+ $this->assertEquals(2, \count($elements));
+ $this->assertTrue(current($elements) instanceof ElementName);
+
+ $types = $header->getElementTypes();
+ $this->assertTrue(\is_array($types));
+ $this->assertEquals(ElementName::class, $types['Type']);
+ $this->assertEquals(ElementName::class, $types['Subtype']);
+ }
+
+ public function testHas()
+ {
+ $document = $this->getDocumentInstance();
+
+ $content = '<>foo';
+ $position = 0;
+ $header = Header::parse($content, $document, $position);
+
+ $this->assertTrue($header->has('Type'));
+ $this->assertTrue($header->has('SubType'));
+ $this->assertTrue($header->has('Font'));
+ $this->assertFalse($header->has('Text'));
+ }
+
+ public function testGet()
+ {
+ $document = $this->getDocumentInstance();
+
+ $content = '<>foo';
+ $position = 0;
+ $header = Header::parse($content, $document, $position);
+ $object = new Page($document, $header);
+ $document->setObjects(['5_0' => $object]);
+
+ $this->assertTrue($header->get('Type') instanceof ElementName);
+ $this->assertTrue($header->get('SubType') instanceof ElementName);
+ $this->assertTrue($header->get('Font') instanceof Page);
+ $this->assertTrue($header->get('Image') instanceof ElementMissing);
+ $this->assertTrue($header->get('Resources') instanceof ElementMissing);
+ }
+
+ public function testResolveXRef()
+ {
+ $document = $this->getDocumentInstance();
+ $content = '<>foo';
+ $position = 0;
+ $header = Header::parse($content, $document, $position);
+ $object = new Page($document, $header);
+ $document->setObjects(['5_0' => $object]);
+
+ $this->assertTrue($header->get('Font') instanceof PDFObject);
+
+ $header = $header->get('Resources');
+ $this->assertTrue($header instanceof ElementMissing);
+ }
+}
diff --git a/src/Smalot/PdfParser/Tests/Units/PDFObject.php b/tests/Integration/PDFObjectTest.php
similarity index 59%
rename from src/Smalot/PdfParser/Tests/Units/PDFObject.php
rename to tests/Integration/PDFObjectTest.php
index f01d3ba6..2b9c7084 100644
--- a/src/Smalot/PdfParser/Tests/Units/PDFObject.php
+++ b/tests/Integration/PDFObjectTest.php
@@ -1,8 +1,10 @@
+ * @date 2020-06-01
*
* @author Sébastien MALOT
* @date 2017-01-03
@@ -28,14 +30,13 @@
* If not, see .
*/
-namespace Smalot\PdfParser\Tests\Units;
+namespace Tests\Smalot\PdfParser\Integration;
-use mageekguy\atoum;
+use Smalot\PdfParser\Document;
+use Smalot\PdfParser\PDFObject;
+use Test\Smalot\PdfParser\TestCase;
-/**
- * Class PDFObject
- */
-class PDFObject extends atoum\test
+class PDFObjectTest extends TestCase
{
const TYPE = 't';
@@ -43,88 +44,11 @@ class PDFObject extends atoum\test
const COMMAND = 'c';
- public function testGetTextParts()
+ protected function getPdfObjectInstance($document)
{
+ return new PDFObject($document);
}
-// public function testGetCommandsImage()
-// {
-// $content = "/CS/RGB
- ///W 22
- ///H 1
- ///BPC 8
- ///F/Fl
- ///DP<>
- //ID \x00\x50c\x63
- //EI Q
- //q -124.774 124.127 5.64213 5.67154 930.307 4436.95 cm
- //BI
- //";
-//
-// $document = new \Smalot\PdfParser\Document();
-// $object = new \Smalot\PdfParser\PDFObject($document);
-// $offset = 0;
-// $parts = $object->getCommandsImage($content, $offset);
-// $reference = array(
-// array(
-// self::TYPE => '/',
-// self::OPERATOR => 'CS',
-// self::COMMAND => 'RGB',
-// ),
-// array(
-// self::TYPE => '/',
-// self::OPERATOR => 'W',
-// self::COMMAND => '22',
-// ),
-// array(
-// self::TYPE => '/',
-// self::OPERATOR => 'H',
-// self::COMMAND => '1',
-// ),
-// array(
-// self::TYPE => '/',
-// self::OPERATOR => 'BPC',
-// self::COMMAND => '8',
-// ),
-// array(
-// self::TYPE => '/',
-// self::OPERATOR => 'F',
-// self::COMMAND => 'Fl',
-// ),
-// array(
-// self::TYPE => 'struct',
-// self::OPERATOR => 'DP',
-// self::COMMAND => array(
-// array(
-// self::TYPE => '/',
-// self::OPERATOR => 'Predictor',
-// self::COMMAND => '15',
-// ),
-// array(
-// self::TYPE => '/',
-// self::OPERATOR => 'Columns',
-// self::COMMAND => '22',
-// ),
-// array(
-// self::TYPE => '/',
-// self::OPERATOR => 'Colors',
-// self::COMMAND => '3',
-// ),
-// ),
-// ),
-// array(
-// self::TYPE => '',
-// self::OPERATOR => 'ID',
-// self::COMMAND => "\x00\x50c\x63",
-// ),
-// );
-//
-// $this->assert->array($parts)->isEqualTo($reference);
-// $this->assert->integer($offset)->isEqualTo(83);
-// }
-
public function testGetCommandsText()
{
$content = "/R14 30 Tf 0.999016 0 0 1 137.4
@@ -137,10 +61,8 @@ public function testGetCommandsText()
q -124.774 124.127 5.64213 5.67154 930.307 4436.95 cm
BI";
- $document = new \Smalot\PdfParser\Document();
- $object = new \Smalot\PdfParser\PDFObject($document);
$offset = 0;
- $parts = $object->getCommandsText($content, $offset);
+ $parts = $this->getPdfObjectInstance(new Document())->getCommandsText($content, $offset);
$reference = [
[
self::TYPE => '/',
@@ -225,8 +147,8 @@ public function testGetCommandsText()
],
];
- $this->assert->array($parts)->isEqualTo($reference);
- $this->assert->integer($offset)->isEqualTo(172);
+ $this->assertEquals($parts, $reference);
+ $this->assertEquals(172, $offset);
}
public function testCleanContent()
@@ -269,12 +191,9 @@ public function testCleanContent()
q
0.03 841';
- $document = new \Smalot\PdfParser\Document();
- $object = new \Smalot\PdfParser\PDFObject($document);
- $cleaned = $object->cleanContent($content, '_');
+ $cleaned = $this->getPdfObjectInstance(new Document())->cleanContent($content, '_');
- $this->assert->string($cleaned)->length->isEqualTo(\strlen($content));
- $this->assert->string($cleaned)->isEqualTo($expected);
+ $this->assertEquals($cleaned, $expected);
}
public function testGetSectionText()
@@ -298,11 +217,17 @@ public function testGetSectionText()
q
0.03 841';
- $document = new \Smalot\PdfParser\Document();
- $object = new \Smalot\PdfParser\PDFObject($document);
- $sections = $object->getSectionsText($content);
+ $sections = $this->getPdfObjectInstance(new Document())->getSectionsText($content);
+
+ $this->assertEquals(
+ ['/TT0 1 Tf
+0.0007 Tc 0.0018 Tw 0 Ts 100 Tz 0 Tr 24 0 0 24 51.3 639.26025 Tm
+(Mod BT atio[ns] au \(14\) septembre 2009 ET 2010)Tj
+EMC
+(ABC) Tj
-// $this->assert->string($cleaned)->length->isEqualTo(strlen($content));
-// $this->assert->string($cleaned)->isEqualTo($expected);
+[ (a)-4.5(b) 6(c)8.8 ( fsdfsdfsdf[ sd) ] TD ', '/TT1 1.5 Tf (BT )Tj '],
+ $sections
+ );
}
}
diff --git a/tests/Integration/PageTest.php b/tests/Integration/PageTest.php
new file mode 100644
index 00000000..7293e6c8
--- /dev/null
+++ b/tests/Integration/PageTest.php
@@ -0,0 +1,462 @@
+
+ * @date 2020-06-01
+ *
+ * @author Sébastien MALOT
+ * @date 2017-01-03
+ *
+ * @license LGPLv3
+ * @url
+ *
+ * PdfParser is a pdf library written in PHP, extraction oriented.
+ * Copyright (C) 2017 - Sébastien MALOT
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.
+ * If not, see .
+ */
+
+namespace Tests\Smalot\PdfParser\Integration;
+
+use Smalot\PdfParser\Font;
+use Test\Smalot\PdfParser\TestCase;
+
+class PageTest extends TestCase
+{
+ public function testGetFonts()
+ {
+ // Document with text.
+ $filename = $this->rootDir.'/samples/Document1_pdfcreator_nocompressed.pdf';
+ $parser = $this->getParserInstance();
+ $document = $parser->parseFile($filename);
+ $pages = $document->getPages();
+ $page = $pages[0];
+
+ // the first to load data.
+ $fonts = $page->getFonts();
+ $this->assertTrue(0 < \count($fonts));
+ foreach ($fonts as $font) {
+ $this->assertTrue($font instanceof Font);
+ }
+ // the second to use cache.
+ $fonts = $page->getFonts();
+ $this->assertTrue(0 < \count($fonts));
+
+ // ------------------------------------------------------
+ // Document without text.
+ $filename = $this->rootDir.'/samples/Document3_pdfcreator_nocompressed.pdf';
+ $document = $parser->parseFile($filename);
+ $pages = $document->getPages();
+ $page = $pages[0];
+
+ // the first to load data.
+ $fonts = $page->getFonts();
+ $this->assertEquals(0, \count($fonts));
+ // the second to use cache.
+ $fonts = $page->getFonts();
+ $this->assertEquals(0, \count($fonts));
+ }
+
+ public function testGetFont()
+ {
+ // Document with text.
+ $filename = $this->rootDir.'/samples/Document1_pdfcreator_nocompressed.pdf';
+ $parser = $this->getParserInstance();
+ $document = $parser->parseFile($filename);
+ $pages = $document->getPages();
+ $page = $pages[0];
+
+ // the first to load data.
+ $font = $page->getFont('R7');
+ $this->assertTrue($font instanceof Font);
+
+ $font = $page->getFont('ABC7');
+ $this->assertTrue($font instanceof Font);
+ }
+
+ public function testGetText()
+ {
+ // Document with text.
+ $filename = $this->rootDir.'/samples/Document1_pdfcreator_nocompressed.pdf';
+ $parser = $this->getParserInstance();
+ $document = $parser->parseFile($filename);
+ $pages = $document->getPages();
+ $page = $pages[0];
+ $text = $page->getText();
+
+ $this->assertTrue(150 < \strlen($text));
+ $this->assertContains('Document title', $text);
+ $this->assertContains('Lorem ipsum', $text);
+
+ $this->assertContains('Calibri', $text);
+ $this->assertContains('Arial', $text);
+ $this->assertContains('Times', $text);
+ $this->assertContains('Courier New', $text);
+ $this->assertContains('Verdana', $text);
+ }
+
+ public function testExtractRawData()
+ {
+ // Document with text.
+ $filename = $this->rootDir.'/samples/Document1_pdfcreator_nocompressed.pdf';
+ $parser = $this->getParserInstance();
+ $document = $parser->parseFile($filename);
+ $pages = $document->getPages();
+ $page = $pages[0];
+ $extractedRawData = $page->extractRawData();
+ $tmItem = $extractedRawData[1];
+
+ $this->assertcount(172, $extractedRawData);
+ $this->assertCount(3, $tmItem);
+
+ $this->assertArrayHasKey('t', $tmItem);
+ $this->assertArrayHasKey('o', $tmItem);
+ $this->assertArrayHasKey('c', $tmItem);
+
+ $this->assertContains('Tm', $tmItem['o']);
+ $this->assertContains('0.999429 0 0 1 201.96 720.68', $tmItem['c']);
+ }
+
+ public function testExtractDecodedRawData()
+ {
+ // Document with text.
+ $filename = $this->rootDir.'/samples/Document1_pdfcreator_nocompressed.pdf';
+ $parser = $this->getParserInstance();
+ $document = $parser->parseFile($filename);
+ $pages = $document->getPages();
+ $page = $pages[0];
+ $extractedDecodedRawData = $page->extractDecodedRawData();
+ $tmItem = $extractedDecodedRawData[1];
+ $this->assertCount(172, $extractedDecodedRawData);
+ $this->assertCount(3, $tmItem);
+
+ $this->assertArrayHasKey('t', $tmItem);
+ $this->assertArrayHasKey('o', $tmItem);
+ $this->assertArrayHasKey('c', $tmItem);
+
+ $this->assertContains('Tm', $tmItem['o']);
+ $this->assertContains('0.999429 0 0 1 201.96 720.68', $tmItem['c']);
+
+ $this->assertCount(3, $tmItem);
+ $this->assertArrayHasKey('t', $tmItem);
+ $this->assertArrayHasKey('o', $tmItem);
+ $this->assertArrayHasKey('c', $tmItem);
+
+ $tjItem = $extractedDecodedRawData[2];
+ $this->assertContains('TJ', $tjItem['o']);
+ $this->assertContains('(', $tjItem['c'][0]['t']);
+ $this->assertContains('D', $tjItem['c'][0]['c']);
+ $this->assertContains('n', $tjItem['c'][1]['t']);
+ $this->assertContains('0.325008', $tjItem['c'][1]['c']);
+ $this->assertContains('(', $tjItem['c'][2]['t']);
+ $this->assertContains('o', $tjItem['c'][2]['c']);
+ }
+
+ public function testGetDataCommands()
+ {
+ // Document with text.
+ $filename = $this->rootDir.'/samples/Document1_pdfcreator_nocompressed.pdf';
+ $parser = $this->getParserInstance();
+ $document = $parser->parseFile($filename);
+ $pages = $document->getPages();
+ $page = $pages[0];
+ $dataCommands = $page->getDataCommands();
+ $this->assertCount(166, $dataCommands);
+
+ $tmItem = $dataCommands[0];
+ $this->assertCount(3, $tmItem);
+ $this->assertArrayHasKey('t', $tmItem);
+ $this->assertArrayHasKey('o', $tmItem);
+ $this->assertArrayHasKey('c', $tmItem);
+
+ $this->assertContains('Tm', $tmItem['o']);
+ $this->assertContains('0.999429 0 0 1 201.96 720.68', $tmItem['c']);
+ $tjItem = $dataCommands[1];
+
+ $this->assertCount(3, $tjItem);
+ $this->assertArrayHasKey('t', $tjItem);
+ $this->assertArrayHasKey('o', $tjItem);
+ $this->assertArrayHasKey('c', $tjItem);
+
+ $this->assertContains('TJ', $tjItem['o']);
+ $this->assertContains('(', $tjItem['c'][0]['t']);
+ $this->assertContains('D', $tjItem['c'][0]['c']);
+ $this->assertContains('n', $tjItem['c'][1]['t']);
+ $this->assertContains('0.325008', $tjItem['c'][1]['c']);
+ $this->assertContains('(', $tjItem['c'][2]['t']);
+ $this->assertContains('o', $tjItem['c'][2]['c']);
+ }
+
+ public function testGetDataTm()
+ {
+ // Document with text.
+ $filename = $this->rootDir.'/samples/Document1_pdfcreator_nocompressed.pdf';
+ $parser = $this->getParserInstance();
+ $document = $parser->parseFile($filename);
+ $pages = $document->getPages();
+ $page = $pages[0];
+
+ $dataTm = $page->getDataTm();
+ $this->assertCount(81, $dataTm);
+
+ $item = $dataTm[0];
+ $this->assertCount(2, $item);
+ $this->assertCount(6, $item[0]);
+ $this->assertEquals(
+ [
+ '0.999429',
+ '0',
+ '0',
+ '1',
+ '201.96',
+ '720.68',
+ ],
+ $item[0]
+ );
+
+ $this->assertContains('Document title', $item[1]);
+ $item = $dataTm[2];
+ $this->assertEquals(
+ [
+ '0.999402',
+ '0',
+ '0',
+ '1',
+ '70.8',
+ '673.64',
+ ],
+ $item[0]
+ );
+
+ $this->assertContains('Calibri : Lorem ipsum dolor sit amet, consectetur a', $item[1]);
+
+ $item = $dataTm[80];
+ $this->assertEquals(
+ [
+ '0.999402',
+ '0',
+ '0',
+ '1',
+ '343.003',
+ '81.44',
+ ],
+ $item[0]
+ );
+ $this->assertContains('nenatis.', $item[1]);
+
+ // ------------------------------------------------------
+ // Document is a form
+ $filename = $this->rootDir.'/samples/SimpleInvoiceFilledExample1.pdf';
+ $document = $parser->parseFile($filename);
+ $pages = $document->getPages();
+ $page = $pages[0];
+ $dataTm = $page->getDataTm();
+ $item = $dataTm[2];
+ $this->assertCount(105, $dataTm);
+ $this->assertCount(2, $item);
+ $this->assertCount(6, $item[0]);
+ $this->assertEquals(
+ [
+ '1',
+ '0',
+ '0',
+ '1',
+ '167.3',
+ '894.58',
+ ],
+ $item[0]
+ );
+ $this->assertContains('MyName MyLastName', $item[1]);
+
+ $item = $dataTm[6];
+ $this->assertEquals(
+ [
+ '1',
+ '0',
+ '0',
+ '1',
+ '681.94',
+ '877.42',
+ ],
+ $item[0]
+ );
+ $this->assertContains('1/1/2020', $item[1]);
+
+ $item = $dataTm[8];
+ $this->assertEquals(
+ [
+ '1',
+ '0',
+ '0',
+ '1',
+ '174.86',
+ '827.14',
+ ],
+ $item[0]
+ );
+ $this->assertContains('Purchase 1', $item[1]);
+
+ // ------------------------------------------------------
+ // Document is another form of the same type
+ $filename = $this->rootDir.'/samples/SimpleInvoiceFilledExample2.pdf';
+ $document = $parser->parseFile($filename);
+ $pages = $document->getPages();
+ $page = $pages[0];
+ $dataTm = $page->getDataTm();
+
+ $item = $dataTm[2];
+ $this->assertCount(105, $dataTm);
+ $this->assertCount(2, $item);
+ $this->assertCount(6, $item[0]);
+ $this->assertEquals(
+ [
+ '1',
+ '0',
+ '0',
+ '1',
+ '167.3',
+ '894.58',
+ ],
+ $item[0]
+ );
+ $this->assertContains("Other'sName Other'sLastName", $item[1]);
+
+ $item = $dataTm[6];
+ $this->assertEquals(
+ [
+ '1',
+ '0',
+ '0',
+ '1',
+ '681.94',
+ '877.42',
+ ],
+ $item[0]
+ );
+ $this->assertContains('2/2/2020', $item[1]);
+
+ $item = $dataTm[8];
+ $this->assertEquals(
+ [
+ '1',
+ '0',
+ '0',
+ '1',
+ '174.86',
+ '827.14',
+ ],
+ $item[0]
+ );
+ $this->assertContains('Purchase 2', $item[1]);
+ }
+
+ public function testGetTextXY()
+ {
+ // Document with text.
+ $filename = $this->rootDir.'/samples/Document1_pdfcreator_nocompressed.pdf';
+ $parser = $this->getParserInstance();
+ $document = $parser->parseFile($filename);
+ $pages = $document->getPages();
+ $page = $pages[0];
+ $result = $page->getTextXY(201.96, 720.68);
+ $this->assertCount(1, $result);
+ $this->assertCount(2, $result[0]);
+ $this->assertEquals(
+ [
+ '0.999429',
+ '0',
+ '0',
+ '1',
+ '201.96',
+ '720.68',
+ ],
+ $result[0][0]
+ );
+ $this->assertContains('Document title', $result[0][1]);
+
+ $result = $page->getTextXY(201, 720);
+ $this->assertCount(0, $result);
+
+ $result = $page->getTextXY(201, 720, 1, 1);
+ $this->assertCount(1, $result);
+ $this->assertCount(2, $result[0]);
+ $this->assertEquals(
+ [
+ '0.999429',
+ '0',
+ '0',
+ '1',
+ '201.96',
+ '720.68',
+ ],
+ $result[0][0]
+ );
+ $this->assertContains('Document title', $result[0][1]);
+
+ // ------------------------------------------------------
+ // Document is a form
+ $filename = $this->rootDir.'/samples/SimpleInvoiceFilledExample1.pdf';
+ $document = $parser->parseFile($filename);
+ $pages = $document->getPages();
+ $page = $pages[0];
+ $result = $page->getTextXY(167, 894, 1, 1);
+ $this->assertEquals(
+ [
+ '1',
+ '0',
+ '0',
+ '1',
+ '167.3',
+ '894.58',
+ ],
+ $result[0][0]
+ );
+ $this->assertContains('MyName MyLastName', $result[0][1]);
+
+ $result = $page->getTextXY(681, 877, 1, 1);
+ $this->assertContains('1/1/2020', $result[0][1]);
+
+ $result = $page->getTextXY(174, 827, 1, 1);
+ $this->assertContains('Purchase 1', $result[0][1]);
+
+ // ------------------------------------------------------
+ // Document is another form of the same type
+ $filename = $this->rootDir.'/samples/SimpleInvoiceFilledExample2.pdf';
+ $document = $parser->parseFile($filename);
+ $pages = $document->getPages();
+ $page = $pages[0];
+ $result = $page->getTextXY(167, 894, 1, 1);
+ $this->assertEquals(
+ [
+ '1',
+ '0',
+ '0',
+ '1',
+ '167.3',
+ '894.58',
+ ],
+ $result[0][0]
+ );
+ $this->assertContains("Other'sName Other'sLastName", $result[0][1]);
+
+ $result = $page->getTextXY(681, 877, 1, 1);
+ $this->assertContains('2/2/2020', $result[0][1]);
+
+ $result = $page->getTextXY(174, 827, 1, 1);
+ $this->assertContains('Purchase 2', $result[0][1]);
+ }
+}
diff --git a/src/Smalot/PdfParser/Tests/Units/Parser.php b/tests/Integration/ParserTest.php
similarity index 65%
rename from src/Smalot/PdfParser/Tests/Units/Parser.php
rename to tests/Integration/ParserTest.php
index 5085b57d..7efb16a8 100644
--- a/src/Smalot/PdfParser/Tests/Units/Parser.php
+++ b/tests/Integration/ParserTest.php
@@ -1,8 +1,10 @@
+ * @date 2020-06-01
*
* @author Sébastien MALOT
* @date 2017-01-03
@@ -28,40 +30,44 @@
* If not, see .
*/
-namespace Smalot\PdfParser\Tests\Units;
+namespace Tests\Smalot\PdfParser\Integration;
use Exception;
-use mageekguy\atoum;
+use Smalot\PdfParser\Parser;
+use Test\Smalot\PdfParser\TestCase;
-/**
- * Class Parser
- */
-class Parser extends atoum\test
+class ParserTest extends TestCase
{
- /**
- * @throws \Exception
- */
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->fixture = new Parser();
+ }
+
public function testParseFile()
{
- $directory = getcwd().'/samples/bugs';
+ $directory = $this->rootDir.'/samples/bugs';
if (is_dir($directory)) {
$files = scandir($directory);
- $parser = new \Smalot\PdfParser\Parser();
foreach ($files as $file) {
if (preg_match('/^.*\.pdf$/i', $file)) {
try {
- $document = $parser->parseFile($directory.'/'.$file);
+ $document = $this->fixture->parseFile($directory.'/'.$file);
$pages = $document->getPages();
- $this->assert->integer(\count($pages))->isGreaterThan(0);
+ $this->assertTrue(0 < \count($pages));
foreach ($pages as $page) {
$content = $page->getText();
- $this->assert->string($content);
+ $this->assertTrue(0 < \strlen($content));
}
} catch (Exception $e) {
- if ('Secured pdf file are currently not supported.' !== $e->getMessage() && 0 != strpos($e->getMessage(), 'TCPDF_PARSER')) {
+ if (
+ 'Secured pdf file are currently not supported.' !== $e->getMessage()
+ && 0 != strpos($e->getMessage(), 'TCPDF_PARSER')
+ ) {
throw $e;
}
}