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