aboutsummaryrefslogtreecommitdiff
path: root/tests/PathTest.php
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2018-09-02 18:58:32 -0400
committerPaul Duncan <pabs@pablotron.org>2018-09-03 09:54:47 -0400
commite4850cba6fd67a6d4d9d8c969281e57447c17fd9 (patch)
tree29fb04954bdabde80a2208d6fa88c575cc7ed802 /tests/PathTest.php
parentd70e1b519d27e5b0090412c566bee79d57f7838e (diff)
downloadzipstream-php-e4850cba6fd67a6d4d9d8c969281e57447c17fd9.tar.bz2
zipstream-php-e4850cba6fd67a6d4d9d8c969281e57447c17fd9.zip
add tests/ and composer test script
Diffstat (limited to 'tests/PathTest.php')
-rw-r--r--tests/PathTest.php83
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/PathTest.php b/tests/PathTest.php
new file mode 100644
index 0000000..a71be8d
--- /dev/null
+++ b/tests/PathTest.php
@@ -0,0 +1,83 @@
+<?php
+declare(strict_types = 1);
+
+namespace Pablotron\ZipStream\Tests;
+
+use \PHPUnit\Framework\TestCase;
+use \Pablotron\ZipStream\ZipStream;
+
+final class PathTest extends BaseTestCase {
+ public function testAddEmptyPath() : void {
+ $this->expectException(\Pablotron\ZipStream\PathError::class);
+
+ $this->with_temp_zip(function(ZipStream &$zip) {
+ $zip->add_file('', 'empty test');
+ });
+ }
+
+ public function testAddLongPath() : void {
+ $this->expectException(\Pablotron\ZipStream\PathError::class);
+
+ $this->with_temp_zip(function(ZipStream &$zip) {
+ $long_path = str_repeat('x', 65535);
+ $zip->add_file($long_path, 'long path test');
+ });
+ }
+
+ public function testAddPathWithLeadingSlash() : void {
+ $this->expectException(\Pablotron\ZipStream\PathError::class);
+
+ $this->with_temp_zip(function(ZipStream &$zip) {
+ $zip->add_file('/foo', 'leading slash path test');
+ });
+ }
+
+ public function testAddPathWithTrailingSlash() : void {
+ $this->expectException(\Pablotron\ZipStream\PathError::class);
+
+ $this->with_temp_zip(function(ZipStream &$zip) {
+ $zip->add_file('foo/', 'trailing slash path test');
+ });
+ }
+
+ public function testAddPathWithDoubleSlashes() : void {
+ $this->expectException(\Pablotron\ZipStream\PathError::class);
+
+ $this->with_temp_zip(function(ZipStream &$zip) {
+ $zip->add_file('foo//bar', 'double slash path test');
+ });
+ }
+
+ public function testAddPathWithBackslashes() : void {
+ $this->expectException(\Pablotron\ZipStream\PathError::class);
+
+ $this->with_temp_zip(function(ZipStream &$zip) {
+ $zip->add_file('foo\\bar', 'backslash path test');
+ });
+ }
+
+ public function testLeadingRelativePath() : void {
+ $this->expectException(\Pablotron\ZipStream\PathError::class);
+
+ $this->with_temp_zip(function(ZipStream &$zip) {
+ $zip->add_file('../bar', 'leading relative path test');
+ });
+ }
+
+ public function testMiddleRelativePath() : void {
+ $this->expectException(\Pablotron\ZipStream\PathError::class);
+
+ $this->with_temp_zip(function(ZipStream &$zip) {
+ $zip->add_file('foo/../bar', 'middle relative path test');
+ });
+ }
+
+ public function testTrailingRelativePath() : void {
+ $this->expectException(\Pablotron\ZipStream\PathError::class);
+
+ $this->with_temp_zip(function(ZipStream &$zip) {
+ $zip->add_file('foo/../bar', 'trailing relative path test');
+ });
+ }
+
+};