1+ <?php
2+
3+ namespace Common \Tests \Adapter \Zip ;
4+
5+ use PhpOffice \Common \Adapter \Zip \ZipArchiveAdapter ;
6+ use PhpOffice \Common \Tests \TestHelperZip ;
7+
8+
9+ class ZipArchiveAdapterTest extends \PHPUnit_Framework_TestCase
10+ {
11+ protected $ zipTest ;
12+
13+ public function setUp ()
14+ {
15+ parent ::setUp ();
16+
17+ $ pathResources = PHPOFFICE_COMMON_TESTS_BASE_DIR .DIRECTORY_SEPARATOR .'resources ' .DIRECTORY_SEPARATOR .'files ' .DIRECTORY_SEPARATOR ;
18+ $ this ->zipTest = tempnam ($ pathResources , 'PhpOfficeCommon ' );
19+ copy ($ pathResources .'Sample_01_Simple.pptx ' , $ this ->zipTest );
20+ }
21+
22+ public function tearDown ()
23+ {
24+ parent ::tearDown ();
25+
26+ unlink ($ this ->zipTest );
27+ }
28+
29+ public function testOpen ()
30+ {
31+ $ object = new ZipArchiveAdapter ();
32+ $ this ->assertInstanceOf ('PhpOffice \\Common \\Adapter \\Zip \\ZipInterface ' , $ object ->open ($ this ->zipTest ));
33+ }
34+
35+ public function testClose ()
36+ {
37+ $ object = new ZipArchiveAdapter ();
38+ $ object ->open ($ this ->zipTest );
39+ $ this ->assertInstanceOf ('PhpOffice \\Common \\Adapter \\Zip \\ZipInterface ' , $ object ->close ());
40+ }
41+
42+ public function testAddFromString ()
43+ {
44+ $ expectedPath = 'file.test ' ;
45+ $ expectedContent = 'Content ' ;
46+
47+ $ object = new ZipArchiveAdapter ();
48+ $ object ->open ($ this ->zipTest );
49+ $ object ->addFromString ($ expectedPath , $ expectedContent );
50+ $ object ->close ();
51+
52+ $ this ->assertTrue (TestHelperZip::assertFileExists ($ this ->zipTest , $ expectedPath ));
53+ $ this ->assertTrue (TestHelperZip::assertFileContent ($ this ->zipTest , $ expectedPath , $ expectedContent ));
54+ }
55+ }
0 commit comments