initSpineComponent(); } public static function tearDownAfterClass(): void { restore_error_handler(); unlink(static::TEST_EPUB_COPY); } public function testComponents(): void { $data = self::$book->components(); $contents = file_get_contents(static::TEST_COMPONENTS); $check = json_decode($contents, true); $encoder = $this->provideEncodeReplace(); $check = str_replace($encoder[0], $encoder[1], $check); $this->assertEquals($check, $data); } public function testContents(): void { $data = self::$book->contents(); $contents = file_get_contents(static::TEST_CONTENTS); $check = json_decode($contents, true); $encoder = $this->provideEncodeReplace(); foreach (array_keys($check) as $idx) { $check[$idx] = $this->encodeItem($check[$idx], $encoder); } $this->assertEquals($check, $data); } /** * Summary of testComponent * @param string $component * @return void */ public function testComponent($component = 'text/titlepage.xhtml') { $data = self::$book->component($component); $check = 641; $this->assertEquals($check, strlen($data)); } /** * Summary of testGetComponentName * @param string $component * @param string $element * @return void */ public function testGetComponentName($component = 'text/titlepage.xhtml', $element = '../images/cover.jpg') { $data = self::$book->getComponentName($component, $element); $check = 'images~SLASH~cover.jpg'; $this->assertEquals($check, $data); } /** * Summary of testComponentContentType * @param string $component * @return void */ public function testComponentContentType($component = 'text/titlepage.xhtml') { $data = self::$book->componentContentType($component); $check = 'application/xhtml+xml'; $this->assertEquals($check, $data); } public function testContentsEpub3(): void { $epub = new EPub(__DIR__ . '/data/eng3.epub'); $epub->initSpineComponent(); $data = $epub->contents(); $contents = file_get_contents(static::TEST_CONTENTS); $check = json_decode($contents, true); $encoder = $this->provideEncodeReplace(); foreach (array_keys($check) as $idx) { $check[$idx] = $this->encodeItem($check[$idx], $encoder); } $this->assertEquals($check, $data); } /** * Summary of encodeItem * @param array $item * @param array $encoder * @return array */ protected function encodeItem($item, $encoder) { $item['src'] = str_replace($encoder[0], $encoder[1], $item['src']); if (!empty($item['children'])) { foreach (array_keys($item['children']) as $idx) { $item['children'][$idx] = $this->encodeItem($item['children'][$idx], $encoder); } } return $item; } /** * Summary of provideEncodeReplace * @return array */ public function provideEncodeReplace() { return EPub::$encodeNameReplace; } /** * Summary of provideDecodeReplace * @return array */ public function provideDecodeReplace() { return EPub::$decodeNameReplace; } }