aboutsummaryrefslogtreecommitdiffstats
path: root/library/epub-meta/test
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2017-11-22 15:43:48 -0800
committerzotlabs <mike@macgirvin.com>2017-11-22 15:43:48 -0800
commit9936670f44b53e391d997fd024faa329b8a0c803 (patch)
treea88c45c92843703049a91cf7b4ab4e374b52de97 /library/epub-meta/test
parent6ac3fc4e0724a881ed3b26fa8d0912f38512d2ca (diff)
parentb4f8f4df7bc5cc8a74240506cd536224cb31e114 (diff)
downloadvolse-hubzilla-9936670f44b53e391d997fd024faa329b8a0c803.tar.gz
volse-hubzilla-9936670f44b53e391d997fd024faa329b8a0c803.tar.bz2
volse-hubzilla-9936670f44b53e391d997fd024faa329b8a0c803.zip
Merge branch 'dev' of https://github.com/redmatrix/hubzilla into dev_merge
Diffstat (limited to 'library/epub-meta/test')
-rw-r--r--library/epub-meta/test/test.epubbin0 -> 768780 bytes
-rw-r--r--library/epub-meta/test/test.jpgbin0 -> 821 bytes
-rw-r--r--library/epub-meta/test/test.phpunit.php190
3 files changed, 190 insertions, 0 deletions
diff --git a/library/epub-meta/test/test.epub b/library/epub-meta/test/test.epub
new file mode 100644
index 000000000..85d60aece
--- /dev/null
+++ b/library/epub-meta/test/test.epub
Binary files differ
diff --git a/library/epub-meta/test/test.jpg b/library/epub-meta/test/test.jpg
new file mode 100644
index 000000000..4ca4a685c
--- /dev/null
+++ b/library/epub-meta/test/test.jpg
Binary files differ
diff --git a/library/epub-meta/test/test.phpunit.php b/library/epub-meta/test/test.phpunit.php
new file mode 100644
index 000000000..88a9aa914
--- /dev/null
+++ b/library/epub-meta/test/test.phpunit.php
@@ -0,0 +1,190 @@
+<?php
+
+require '../epub.php';
+
+
+class EPubTest extends PHPUnit_Framework_TestCase {
+
+ protected $epub;
+
+ protected function setUp(){
+ // sometime I might have accidentally broken the test file
+ if(filesize('test.epub') != 768780){
+ die('test.epub has wrong size, make sure it\'s unmodified');
+ }
+
+ // we work on a copy to test saving
+ if(!copy('test.epub','test.copy.epub')){
+ die('failed to create copy of the test book');
+ }
+
+ $this->epub = new EPub('test.copy.epub');
+ }
+
+ protected function tearDown(){
+ unlink('test.copy.epub');
+ }
+
+ public function testAuthors(){
+ // read curent value
+ $this->assertEquals(
+ $this->epub->Authors(),
+ array('Shakespeare, William' => 'William Shakespeare')
+ );
+
+ // remove value with string
+ $this->assertEquals(
+ $this->epub->Authors(''),
+ array()
+ );
+
+ // set single value by String
+
+ $this->assertEquals(
+ $this->epub->Authors('John Doe'),
+ array('John Doe' => 'John Doe')
+ );
+
+ // set single value by indexed array
+ $this->assertEquals(
+ $this->epub->Authors(array('John Doe')),
+ array('John Doe' => 'John Doe')
+ );
+
+ // remove value with array
+ $this->assertEquals(
+ $this->epub->Authors(array()),
+ array()
+ );
+
+ // set single value by associative array
+ $this->assertEquals(
+ $this->epub->Authors(array('Doe, John' => 'John Doe')),
+ array('Doe, John' => 'John Doe')
+ );
+
+ // set multi value by string
+ $this->assertEquals(
+ $this->epub->Authors('John Doe, Jane Smith'),
+ array('John Doe' => 'John Doe', 'Jane Smith' => 'Jane Smith')
+ );
+
+ // set multi value by indexed array
+ $this->assertEquals(
+ $this->epub->Authors(array('John Doe', 'Jane Smith')),
+ array('John Doe' => 'John Doe', 'Jane Smith' => 'Jane Smith')
+ );
+
+ // set multi value by associative array
+ $this->assertEquals(
+ $this->epub->Authors(array('Doe, John' => 'John Doe', 'Smith, Jane' => 'Jane Smith')),
+ array('Doe, John' => 'John Doe', 'Smith, Jane' => 'Jane Smith')
+ );
+
+ // check escaping
+ $this->assertEquals(
+ $this->epub->Authors(array('Doe, John&nbsp;' => 'John Doe&nbsp;')),
+ array('Doe, John&nbsp;' => 'John Doe&nbsp;')
+ );
+ }
+
+ public function testTitle(){
+ // get current value
+ $this->assertEquals(
+ $this->epub->Title(),
+ 'Romeo and Juliet'
+ );
+
+ // delete current value
+ $this->assertEquals(
+ $this->epub->Title(''),
+ ''
+ );
+
+ // get current value
+ $this->assertEquals(
+ $this->epub->Title(),
+ ''
+ );
+
+ // set new value
+ $this->assertEquals(
+ $this->epub->Title('Foo Bar'),
+ 'Foo Bar'
+ );
+
+ // check escaping
+ $this->assertEquals(
+ $this->epub->Title('Foo&nbsp;Bar'),
+ 'Foo&nbsp;Bar'
+ );
+ }
+
+ public function testSubject(){
+ // get current values
+ $this->assertEquals(
+ $this->epub->Subjects(),
+ array('Fiction','Drama','Romance')
+ );
+
+ // delete current values with String
+ $this->assertEquals(
+ $this->epub->Subjects(''),
+ array()
+ );
+
+ // set new values with String
+ $this->assertEquals(
+ $this->epub->Subjects('Fiction, Drama, Romance'),
+ array('Fiction','Drama','Romance')
+ );
+
+ // delete current values with Array
+ $this->assertEquals(
+ $this->epub->Subjects(array()),
+ array()
+ );
+
+ // set new values with array
+ $this->assertEquals(
+ $this->epub->Subjects(array('Fiction','Drama','Romance')),
+ array('Fiction','Drama','Romance')
+ );
+
+ // check escaping
+ $this->assertEquals(
+ $this->epub->Subjects(array('Fiction','Drama&nbsp;','Romance')),
+ array('Fiction','Drama&nbsp;','Romance')
+ );
+ }
+
+
+ public function testCover(){
+ // read current cover
+ $cover = $this->epub->Cover();
+ $this->assertEquals($cover['mime'],'image/png');
+ $this->assertEquals($cover['found'],'OPS/images/cover.png');
+ $this->assertEquals(strlen($cover['data']), 657911);
+
+ // delete cover
+ $cover = $this->epub->Cover('');
+ $this->assertEquals($cover['mime'],'image/gif');
+ $this->assertEquals($cover['found'],false);
+ $this->assertEquals(strlen($cover['data']), 42);
+
+ // set new cover (will return a not-found as it's not yet saved)
+ $cover = $this->epub->Cover('test.jpg','image/jpeg');
+ $this->assertEquals($cover['mime'],'image/jpeg');
+ $this->assertEquals($cover['found'],'OPS/php-epub-meta-cover.img');
+ $this->assertEquals(strlen($cover['data']), 0);
+
+ // save
+ $this->epub->save();
+
+ // read now changed cover
+ $cover = $this->epub->Cover();
+ $this->assertEquals($cover['mime'],'image/jpeg');
+ $this->assertEquals($cover['found'],'OPS/php-epub-meta-cover.img');
+ $this->assertEquals(strlen($cover['data']), filesize('test.jpg'));
+ }
+}