diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 83b3e1d..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,28 +0,0 @@
-language: php
-
-jobs:
- include:
- - php: 5.6
- - php: 7.0
- - php: 7.1
- - php: 7.2
- - php: 7.3
- - php: 7.4
- - php: 7.2
- env: gp_data_type=.json
-
-
-# phpunit 8 will result in an error
-# https://www.reddit.com/r/PHPhelp/comments/apipqs/travis_specifying_phpunit_version/
-before_script:
- - composer init -n
- - composer require phpunit/phpunit "<8 >=4"
- - composer require symfony/process
- - composer require guzzlehttp/guzzle
- - composer require phpunit/php-code-coverage "<7" # for phpunit compat
- #- phpenv config-add phpunit/phpconfig.ini
-
-script:
- - vendor/bin/phpunit
- - php phpunit/ServerCombineCoverage.php
- - bash <(curl -s https://codecov.io/bash) -s ./x_coverage # Submit coverage report to https://codecov.io
diff --git a/codecov.yml b/codecov.yml
deleted file mode 100644
index 69cb760..0000000
--- a/codecov.yml
+++ /dev/null
@@ -1 +0,0 @@
-comment: false
diff --git a/phpunit.xml b/phpunit.xml
deleted file mode 100644
index cef2522..0000000
--- a/phpunit.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-
-
New Text
'; - - $params = [ - 'cmd' => 'SaveText', - 'verified' => \gp\tool\Nonce::Create('post', true), - 'gpcontent' => $text, - ]; - $this->PostRequest('Admin/Extra/Footer',$params); - - // make sure the new text shows in the preview - $response = $this->GetRequest('Admin/Extra/Footer','cmd=PreviewText'); - $body = $response->getBody(); - $this->assertStrpos( $body, $text ); - - - // make sure the draft exits - $this->admin_extra->GetAreas(); - $area_info = $this->admin_extra->ExtraExists('Footer'); - $this->assertFileExists($area_info['draft_path']); - - - // publish draft ... make sure the draft file no longer exists - $params = [ - 'cmd' => 'PublishDraft', - 'verified' => \gp\tool\Nonce::Create('post', true), - ]; - $this->PostRequest('Admin/Extra/Footer',$params); - $this->assertFileNotExists($area_info['draft_path']); - - // make sure the new text still shows - $response = $this->GetRequest('Admin/Extra/Footer','cmd=PreviewText'); - $body = $response->getBody(); - $this->assertStrpos( $body, $text ); - - } - - - /** - * Add an extra area of $type - * @param string $type - */ - public function AddType($type){ - - $area_count = count($this->admin_extra->areas); - $name = 'new-'.$type; - - $params = [ - 'cmd' => 'NewSection', - 'verified' => \gp\tool\Nonce::Create('post', true), - 'new_title' => $name, - 'type' => $type, - ]; - $this->PostRequest('Admin/Extra',$params); - - $this->admin_extra->GetAreas(); - $this->assertEquals( count($this->admin_extra->areas), $area_count + 1 , 'Extra area not added'); - - - // preview - $this->GetRequest('Admin/Extra/' . $name,'cmd=PreviewText'); - - - // delete - $params = [ - 'cmd' => 'DeleteArea', - 'verified' => \gp\tool\Nonce::Create('post', true), - ]; - $this->PostRequest('Admin/Extra/' . rawurlencode($name),$params); - - $this->admin_extra->GetAreas(); - $this->assertEquals( count($this->admin_extra->areas), $area_count , 'Extra area not deleted'); - - } - - public function testVisibility(){ - - $content = \gp\tool\Output\Extra::GetExtra('Header'); - - - // assert the homepage does not contain extra content - $response = $this->GetRequest(''); - $body = $response->GetBody(); - - $this->assertNotStrpos($body,$content); - - - // add footer extra to bottom of page - // get container query from theme editor - // look for url like http://localhost/index.php/Admin_Theme_Content/Edit/default?cmd=SelectContent¶m=QWZ0ZXJDb250ZW50Og_0%7C - $response = $this->GetRequest('Admin_Theme_Content/Edit/default','cmd=in_ifrm'); - $body = $response->GetBody(); - - preg_match('#cmd=SelectContent¶m=([^"]+)#',$body,$match); - - $param = rawurldecode($match[1]); - - - // open dialog - // /Admin_Theme_Content/Edit/default?cmd=SelectContent¶m=QWZ0ZXJDb250ZW50Og_0%7C - $response = $this->GetRequest('Admin_Theme_Content/Edit/default','cmd=SelectContent¶m='.$param); - $body = $response->GetBody(); - $count = preg_match_all('#data-cmd="tabs"#',$body); - $this->assertEquals( $count, 4 , 'Tab count didnt match expected'); - - - // add Header - // /Admin_Theme_Content/Edit/default?cmd=addcontent&where=QWZ0ZXJDb250ZW50Og_0%7C&insert=Extra%3AHeader - preg_match('#href="([^"]*)\?([^"]*cmd=addcontent[^"]*insert[^"]*Header[^"]*)"#',$body,$match); - $page = rawurldecode($match[1]); - $query = rawurldecode($match[2]); - $response = $this->GetRequest($page,$query); - - - // confirm the homepage contains the extra content - $this->UseAnon(); - $response = $this->GetRequest(''); - $body = $response->GetBody(); - - $this->assertStrpos($body,$content,'Extra:Header content not found in body'); - - - // change visibility - // /Admin/Extra/Header?cmd=EditVisibility - $this->UseAdmin(); - $response = $this->GetRequest('Admin/Extra/Header','EditVisibility'); - - $params = [ - 'cmd' => 'SaveVisibilityExtra', - 'verified' => \gp\tool\Nonce::Create('post', true), - 'visibility_type' => 1, - ]; - $this->PostRequest('Admin/Extra/Header',$params); - - - // confirm the homepage does not contain the extra content - $this->UseAnon(); - $response = $this->GetRequest(''); - $body = $response->GetBody(); - - $this->assertNotStrpos($body,$content,'Extra:Header content was found in body'); - - } - - -} diff --git a/phpunit/Admin/LayoutTest.php b/phpunit/Admin/LayoutTest.php deleted file mode 100644 index 4bcff60..0000000 --- a/phpunit/Admin/LayoutTest.php +++ /dev/null @@ -1,83 +0,0 @@ -admin_layout = new \gp\admin\Layout([]); - } - - - public function testLayout(){ - - - $this->GetRequest('Admin_Theme_Content'); - $this->GetRequest('Admin_Theme_Content/Available'); - - $themes = [ - ['Bootswatch4_Scss','cerulean'], - ['Bootswatch_Scss','Cerulian'], - ['Bootswatch_Flatly','1_Starter_Template'], - ]; - - foreach($themes as $theme){ - $this->InstallLayout($theme); - } - - } - - - public function InstallLayout($theme){ - global $gpLayouts; - - \gp\tool::GetPagesPHP(); - $layouts_before = $gpLayouts; - $count_before = count($gpLayouts); - $theme_str = $theme[0].'(local)/'. $theme[1]; - - - // install preview - // http://localhost/gpeasy/dev/index.php/Admin_Theme_Content/Available?cmd=preview&theme=Bootswatch_Scss%28local%29%2FCerulian - $this->GetRequest('Admin_Theme_Content/Available','cmd=preview&theme='.rawurlencode($theme_str)); - - $params = [ - 'theme' => $theme_str, - 'label' => $theme[0].'/'.$theme[1], - 'cmd' => 'addlayout', - 'verified' => \gp\tool\Nonce::Create('post', true), - ]; - - $this->PostRequest('Admin_Theme_Content/Available',$params); - - // confirm we have a new layout in the configuration - \gp\tool::GetPagesPHP(); - $this->AssertEquals( $count_before+1, count($gpLayouts) ); - - $installed = array_diff_key($gpLayouts, $layouts_before); - $layout_key = key($installed); - - - // delete the layout - // http://localhost/gpeasy/dev/index.php/Admin_Theme_Content?cmd=deletelayout&layout=v9duzd9 - $params = [ - 'layout' => $layout_key, - 'cmd' => 'deletelayout', - 'verified' => \gp\tool\Nonce::Create('post', true), - ]; - - $this->PostRequest('Admin_Theme_Content',$params); - - // confirm we have a new layout in the configuration - \gp\tool::GetPagesPHP(); - $this->assertArrayNotHasKey($layout_key,$gpLayouts); - - - } - - -} diff --git a/phpunit/Admin/PermissionsTest.php b/phpunit/Admin/PermissionsTest.php deleted file mode 100644 index ecdc2b9..0000000 --- a/phpunit/Admin/PermissionsTest.php +++ /dev/null @@ -1,68 +0,0 @@ -CheckEditing('all'); - - - // load form - $this->GetRequest('Admin/Permissions','index=a'); - - // adding index=a shouldn't change the permissions - $params = [ - 'verified' => \gp\tool\Nonce::Create('post', true), - 'users' => [static::user_name => static::user_name], - 'cmd' => 'SaveFilePermissions', - 'index' => 'a', - ]; - - $this->PostRequest('/Admin/Permissions',$params); - $this->CheckEditing('all'); - - // removing index=a - $params = [ - 'verified' => \gp\tool\Nonce::Create('post', true), - 'users' => [], - 'cmd' => 'SaveFilePermissions', - 'index' => 'a', - ]; - $expected = array_diff( array_values( $gp_index) , ['a'] ); - $expected = ','.implode(',',$expected).','; - - $this->PostRequest('/Admin/Permissions',$params); - $this->CheckEditing($expected); - - - // re-add index=a - $params = [ - 'verified' => \gp\tool\Nonce::Create('post', true), - 'users' => [static::user_name => static::user_name], - 'cmd' => 'SaveFilePermissions', - 'index' => 'a', - ]; - $expected = array_values( $gp_index); - $expected = ','.implode(',',$expected).','; - - $this->PostRequest('/Admin/Permissions',$params); - $this->CheckEditing($expected); - - } - - - public function CheckEditing($editing_value){ - - $users = \gp\tool\Files::Get('_site/users'); - $this->assertEquals( count($users), 1, 'More than one user found'); - $this->assertArrayHasKey(static::user_name, $users,'Default user not found'); - $this->assertEquals( $users[static::user_name]['editing'], $editing_value, 'Expected editing value of '.$editing_value.' != '.$users[static::user_name]['editing'] ); - - } - -} diff --git a/phpunit/Admin/PreferencesTest.php b/phpunit/Admin/PreferencesTest.php deleted file mode 100644 index cf2b197..0000000 --- a/phpunit/Admin/PreferencesTest.php +++ /dev/null @@ -1,92 +0,0 @@ - password_hash - $params = [ - 'oldpassword' => self::user_pass, - 'password' => 'new-password', - 'password1' => 'new-password', - 'algo' => 'password_hash', - ]; - $user_info_1 = $this->GetUserInfo(); - $this->ChangePreferences( $params ); - $user_info_2 = $this->GetUserInfo(); - $this->assertEquals($user_info_2['passhash'], 'password_hash'); - $this->assertNotEquals($user_info_1['password'], $user_info_2['password']); - - - // password_hash -> sha512 - $params = [ - 'oldpassword' => 'new-password', - 'password' => 'new-password2', - 'password1' => 'new-password2', - 'algo' => 'sha512', - ]; - $this->ChangePreferences( $params ); - $user_info_3 = $this->GetUserInfo(); - $this->assertEquals($user_info_3['passhash'], 'sha512'); - $this->assertNotEquals($user_info_2['password'], $user_info_3['password']); - - - // sha512 -> password_hash - $params = [ - 'oldpassword' => 'new-password2', - 'password' => self::user_pass, - 'password1' => self::user_pass, - 'algo' => 'password_hash', - ]; - $this->ChangePreferences( $params ); - $user_info_4 = $this->GetUserInfo(); - $this->assertEquals($user_info_4['passhash'], 'password_hash'); - $this->assertNotEquals($user_info_3['password'], $user_info_4['password']); - - - // sha512 -> password_hash - $params = [ - 'email' => 'test2@typesettercms.com', - ]; - $this->ChangePreferences( $params ); - $user_info_5 = $this->GetUserInfo(); - $this->assertEquals($user_info_5['email'], 'test2@typesettercms.com'); - - } - - - /** - * Helper function for changing password from old to new - * - */ - public function ChangePreferences( $params ){ - - $params += [ - 'verified' => \gp\tool\Nonce::Create('post', true), - 'email' => self::user_email, - 'oldpassword' => self::user_pass, - 'password' => self::user_pass, - 'password1' => self::user_pass, - 'algo' => 'password_hash', - 'cmd' => 'changeprefs', - ]; - - $this->PostRequest('Admin/Preferences',$params); - } - - public function GetUserInfo(){ - $users = \gp\tool\Files::Get('_site/users'); - $this->assertArrayHasKey(static::user_name, $users); - - return $users[static::user_name]; - } - - - -} diff --git a/phpunit/Admin/StatusTest.php b/phpunit/Admin/StatusTest.php deleted file mode 100644 index 3d8cce4..0000000 --- a/phpunit/Admin/StatusTest.php +++ /dev/null @@ -1,20 +0,0 @@ -CheckDataDir(); - - $this->AssertGreaterThan(0,$admin_status->GetValue('passed_count')); - $this->AssertEquals(0,$admin_status->GetValue('failed_count')); - - } - -} diff --git a/phpunit/Admin/UploadTest.php b/phpunit/Admin/UploadTest.php deleted file mode 100644 index 2447185..0000000 --- a/phpunit/Admin/UploadTest.php +++ /dev/null @@ -1,87 +0,0 @@ -UploadRequest('Admin/Uploaded',$file); - - // confirm the uploaded file exists - $upload = $dataDir.'/data/_uploaded/image/stars.png'; - $thumb = $dataDir.'/data/_uploaded/image/thumbnails/image/stars.png.jpg'; - $this->assertFileExists($upload); - $this->assertFileExists($thumb); - - // delete the file - $params = [ - 'file_cmd' => 'delete', - 'show' => 'inline', - 'file' => 'stars.png', - 'verified' => \gp\tool\Nonce::Create('post', true), - ]; - - $this->PostRequest('Admin/Uploaded/image',$params); - $this->assertFileNotExists($upload); - $this->assertFileNotExists($thumb); - } - - - public function testInvalidUpload(){ - global $dataDir; - - $file = $dataDir . '/include/main.php'; - $upload = $dataDir.'/data/_uploaded/image/main.php'; - $this->UploadRequest('Admin/Uploaded',$file); - $this->assertFileNotExists($upload); - - } - - - /** - * Send a POST request to the test server - * - */ - public static function UploadRequest($slug, $file){ - - $url = \gp\tool::GetUrl($slug); - - $options = [ - 'multipart' => [ - [ - 'name' => 'userfiles[]', - 'contents' => file_get_contents($file), - 'filename' => basename($file) - ], - [ - 'name' => 'MAX_FILE_SIZE', - 'contents' => 2097152, - ], - [ - 'name' => 'file_cmd', - 'contents' => 'inline_upload', - ], - [ - 'name' => 'dir', - 'contents' => '/image', - ], - [ - 'name' => 'verified', - 'contents' => \gp\tool\Nonce::Create('post', true), - ], - [ - 'name' => 'output', - 'contents' => 'gallery', - ], - - ], - ]; - - - return self::GuzzleRequest('POST',$url,200,$options); - } -} diff --git a/phpunit/Admin/UsersTest.php b/phpunit/Admin/UsersTest.php deleted file mode 100644 index cc7b19c..0000000 --- a/phpunit/Admin/UsersTest.php +++ /dev/null @@ -1,98 +0,0 @@ -GetRequest('Admin/Users'); - - $this->GetRequest('/Admin/Users','cmd=newuserform'); - - $users = \gp\tool\Files::Get('_site/users'); - $this->assertEquals( count($users), 1, 'More than one user found'); - - // create the new user - $params = [ - 'verified' => \gp\tool\Nonce::Create('post', true), - 'username' => 'newuser', - 'password' => 'newpass', - 'password1' => 'newpass', - 'algo' => 'password_hash', - 'email' => 'test2@typesettercms.com', - 'grant_all' => 'all', - 'editing_all' => 'all', - 'cmd' => 'CreateNewUser', - ]; - - $this->PostRequest('/Admin/Users',$params); - - $users = \gp\tool\Files::Get('_site/users'); - $user_info = $users['newuser']; - $this->assertEquals( count($users), 2); - $this->assertEquals( $user_info['granted'], 'all'); - $this->assertEquals( $user_info['editing'], 'all'); - $this->assertEquals( $user_info['email'], 'test2@typesettercms.com'); - - - - // edit user details - $params = [ - 'verified' => \gp\tool\Nonce::Create('post', true), - 'username' => 'newuser', - 'email' => 'test3@typesettercms.com', - 'grant_all' => '', - 'editing_all' => '', - 'cmd' => 'SaveChanges', - ]; - - $this->GetRequest('/Admin/Users','cmd=details&username=newuser'); - $this->PostRequest('/Admin/Users',$params); - - $users = \gp\tool\Files::Get('_site/users'); - $user_info = $users['newuser']; - $this->assertEquals( $user_info['granted'], ''); - $this->assertEquals( $user_info['editing'], ''); - $this->assertEquals( $user_info['email'], 'test3@typesettercms.com'); - - - // change password - $params = [ - 'verified' => \gp\tool\Nonce::Create('post', true), - 'username' => 'newuser', - 'password' => 'resetpass', - 'password1' => 'resetpass', - 'algo' => 'password_hash', - 'cmd' => 'resetpass', - ]; - - $this->GetRequest('/Admin/Users','cmd=changepass&username=newuser'); - $this->PostRequest('/Admin/Users',$params); - - $users = \gp\tool\Files::Get('_site/users'); - $user_info2 = $users['newuser']; - $this->assertNotEquals( $user_info2['password'],$user_info['password'],'Password reset failed'); - - - - // delete user - $params = [ - 'cmd' => 'RemoveUser', - 'username' => 'newuser', - 'verified' => \gp\tool\Nonce::Create('post', true), - ]; - - $this->PostRequest('/Admin/Users',$params); - - $users = \gp\tool\Files::Get('_site/users'); - $this->assertEquals( count($users), 1,'Failed removing user'); - $this->assertArrayHasKey(static::user_name, $users); - - } - -} diff --git a/phpunit/Include/LanguagesTest.php b/phpunit/Include/LanguagesTest.php deleted file mode 100644 index 4dd9e66..0000000 --- a/phpunit/Include/LanguagesTest.php +++ /dev/null @@ -1,27 +0,0 @@ - $lang){ - $langmessage = array(); - \gp\tool::GetLangFile('main.inc',$code); - $keys = array_keys($langmessage); - - - $diff = array_diff($keys_en,$keys); - self::assertEmpty($diff,'Keys missing in '.$lang.' ('.$code.') language file: '.pre($diff)); - - } - - } - -} diff --git a/phpunit/Install/UpdateTest.php b/phpunit/Install/UpdateTest.php deleted file mode 100644 index 173bca8..0000000 --- a/phpunit/Install/UpdateTest.php +++ /dev/null @@ -1,142 +0,0 @@ -UpdateOutputTest(); - $this->UpdateFilesystem(); - $this->UpdatePackageInfo(); - $this->DownloadSource(); - $this->UnpackAndSort(); - $this->ReplaceDirs(); - - } - - /* - static function AssertTrue($condition, $msg = '' ){ - global $page; - - if( $condition !== true && $page->update_msgs ){ - echo "\n --".implode("\n --",$page->update_msgs); - } - parent::assertTrue($condition,$msg); - } - */ - - - /** - * Very rough integration test of the updater - * Passes if no errors are thrown - * Also defines $page for subsequent tests - * - */ - function UpdateOutputTest(){ - global $page; - - $url = '/include/install/update.php'; - $response = static::GuzzleRequest('GET',$url); - - - ob_start(); - $page = new \gp\admin\Update(); - //\gp\tool\Output::HeadContent(); - //includeFile('install/update_template.php'); - ob_get_clean(); - - } - - - /** - * Filesystem method detection - * - */ - function UpdateFilesystem(){ - global $page; - - $filesystem_method = $page->DetectFileSystem(); - self::AssertEquals($filesystem_method,'gp_filesystem_direct'); - - - $this->FileSystem = \gp\tool\FileSystem::set_method('gp_filesystem_direct'); - } - - - /** - * Getting package info from gpeasy - * - */ - function UpdatePackageInfo(){ - global $page; - - $success = $page->DoRemoteCheck2(); - self::AssertTrue($success,'DoRemoteCheck2 Failed'); - - } - - - /** - * Make sure we can get the new source from gpeasy - * - */ - function DownloadSource(){ - global $page; - - $success = $page->DownloadSource(); - self::AssertTrue($success,'Download Source Failed'); - - } - - - /** - * Make sure the unzip and file replacement works - * - */ - function UnpackAndSort(){ - global $page; - - $success = $page->UnpackAndSort($page->core_package['file']); - - self::AssertTrue($success,'UnpackAndSort Failed'); - } - - - /** - * Make sure we can replace the directories - * - */ - function ReplaceDirs(){ - global $page; - - - $extra_dirs = array(); - $success = $this->FileSystem->ReplaceDirs( $page->replace_dirs, $extra_dirs ); - print_r($page->replace_dirs); - self::AssertTrue($success,'ReplaceDirs Failed'); - - if( !$success ){ - return; - } - - - //remove what we just installed - $remove = array_keys($page->replace_dirs); - $this->FileSystem->CleanUpFolders($remove, $not_deleted); - - - //reverse it - $replace_dirs = $extra_dirs; - $extra_dirs = array(); - $success = $this->FileSystem->ReplaceDirs( $replace_dirs, $extra_dirs ); - self::AssertTrue($success,'ReplaceDirs Failed (2)'); - - } - - -} diff --git a/phpunit/ServerCombineCoverage.php b/phpunit/ServerCombineCoverage.php deleted file mode 100644 index 45dfefd..0000000 --- a/phpunit/ServerCombineCoverage.php +++ /dev/null @@ -1,42 +0,0 @@ -filter()->addDirectoryToWhitelist($include_dir); - $cov_obj->filter()->removeDirectoryFromWhitelist($include_dir.'/thirdparty'); - - - $cov_dir = dirname(__DIR__).'/x_coverage'; - $files = scandir($cov_dir); - $file_count = 0; - - foreach($files as $file){ - - if( $file === '.' || $file === '..' ){ - continue; - } - - if( strpos($file,'request-') !== 0 ){ - echo "\n - invalid coverage file: ".$file; - continue; - } - - echo "\n - coverage file: ".$file; - - $file = $cov_dir.'/'.$file; - $data = json_decode( file_get_contents($file),true ); - $cov_obj->append($data, $file ); - $file_count++; - } - - echo "\n - ".$file_count.' coverage files combined in '.$cov_dir; - echo "\n"; - - $cov_file = $cov_dir.'/requests.clover'; - $writer = new \SebastianBergmann\CodeCoverage\Report\Clover; - $writer->process($cov_obj, $cov_file); -} diff --git a/phpunit/ServerPrepend.php b/phpunit/ServerPrepend.php deleted file mode 100644 index aa49e44..0000000 --- a/phpunit/ServerPrepend.php +++ /dev/null @@ -1,29 +0,0 @@ -UseAnon(); - - $url = \gp\tool::GetUrl( 'a-missing-page','',false); - self::GuzzleRequest('GET',$url,404); - - } - - public function testRedir(){ - - $this->UseAnon(); - - $options = ['allow_redirects'=>false]; - $url = \gp\tool::GetUrl( 'Child_Pag','',false); - $response = self::GuzzleRequest('GET', $url, 302, $options); - $location = $response->getHeader('Location'); - - $this->AssertEquals($location[0],'/index.php/Child_Page'); - - } - -} diff --git a/phpunit/Tool/ArchiveTest.php b/phpunit/Tool/ArchiveTest.php deleted file mode 100644 index 3255813..0000000 --- a/phpunit/Tool/ArchiveTest.php +++ /dev/null @@ -1,222 +0,0 @@ - 'PharData', - 'tgz' => 'PharData', - 'tar' => 'PharData', - 'zip' => 'ZipArchive', - 'tar.bz' => 'PharData', - 'tar.gz' => 'PharData', - ]; - - private $files = [ - 'index.html' => '', - 'foo/text.txt' => 'lorem ipsum', - 'foo/index.html' => '', - '/foo/bar' => 'foo bar', - 'foo/unicode/index.html' => '', - - // unicode isn't supported by pharData until php 5.4.29/5.5.13/5.6.0 - //'foo/unicode/Kødpålæg.tst' => 'Die style.css hatte ich an dieser Stelle zuvor nicht überarbeitet.', - ]; - - /** - * Create the files and folders - * - */ - function setUp(){ - global $dataDir; - - // HHVM doesn't support writing with PHAR - // https://github.com/facebook/hhvm/issues/4899 - if( defined('HHVM_VERSION') ){ - $this->types = ['zip'=>'ZipArchive']; - } - - - $this->dir = $dataDir.'/data/test-'.rand(1,10000000); - - foreach($this->files as $name => $content){ - $full = $this->dir.'/'.$name; - \gp\tool\Files::Save($full,$content); - } - } - - - /** - * Test creation - * - */ - function testCreate(){ - - foreach($this->types as $type => $expected_class){ - - if( !class_exists($expected_class) ){ - $this->markTestIncomplete('missing archive class '.$expected_class); - continue; - } - - - $archive = $this->FromFiles($type); - //$list = $archive->ListFiles(); - self::AssertEquals( count($this->files), $archive->Count() ); - } - - } - - - /** - * Test archive creation from string - * - */ - function testCreateString(){ - - foreach($this->types as $type => $expected_class){ - - if( !class_exists($expected_class) ){ - $this->markTestIncomplete('missing archive class '.$expected_class); - continue; - } - - $archive = $this->FromString($type); - self::AssertEquals( count($this->files), $archive->Count() ); - } - } - - - /** - * Extract from a tar archive - * - */ - function testExtract(){ - - foreach($this->types as $type => $expected_class){ - - if( !class_exists($expected_class) ){ - $this->markTestIncomplete('missing archive class '.$expected_class); - continue; - } - - $archive = $this->FromString($type); - - foreach($this->files as $name => $content){ - $extracted = $archive->getFromName($name); - self::AssertEquals($content, $extracted ); - } - } - } - - - /** - * Test ListFiles() - * - */ - function testListFiles(){ - - foreach($this->types as $type => $expected_class){ - - if( !class_exists($expected_class) ){ - $this->markTestIncomplete('missing archive class '.$expected_class); - continue; - } - - $archive = $this->FromString($type); - $list = $archive->ListFiles(); - self::AssertEquals( count($list), count($this->files) ); - } - } - - - /** - * Test GetRoot() - * - */ - function testGetRoot(){ - - foreach($this->types as $type => $expected_class){ - - if( !class_exists($expected_class) ){ - $this->markTestIncomplete('missing archive class '.$expected_class); - continue; - } - - $archive = $this->FromString($type); - $root = $archive->GetRoot('text.txt'); - self::AssertEquals( 'foo', $root ); - } - } - - - /** - * Create an archive, add a file using AddFromString() - * - */ - function FromString($type){ - - $path = $this->ArchivePath($type); - - try{ - $archive = new \gp\tool\Archive($path); - foreach($this->files as $name => $content){ - $archive->addFromString($name, $content); - } - }catch( Exception $e){ - self::AssertTrue( false, 'FromString('.$type.') Failed with message: '.$e->getMessage() ); - return; - } - - $archive->Compress(); - self::AssertFileExists( $path ); - - - //return a readable archive - $path2 = $this->ArchivePath($type); - copy($path,$path2); - - return new \gp\tool\Archive($path2); - } - - - /** - * Create archive from files - * - */ - function FromFiles($type){ - - $path = $this->ArchivePath($type); - $expected_class = $this->types[$type]; - - try{ - $archive = new \gp\tool\Archive($path); - - }catch( Exception $e){ - self::AssertTrue( false, 'FromFiles('.$type.') Failed with message: '.$e->getMessage() ); - return; - } - - self::assertInstanceOf($expected_class,$archive->GetObject(),'Archive object is not '.$this->types[$type].' for type '.$type); - - $archive->Add($this->dir); - - $archive->Compress(); - self::AssertFileExists( $path ); - - return new \gp\tool\Archive($path); //return a readable archive - } - - - - function ArchivePath($type){ - global $dataDir; - return $dataDir . '/data/archive-'.rand(0,100000).'.'.$type; - } - - -} diff --git a/phpunit/Tool/HtmlFixtures/attributes.from.html b/phpunit/Tool/HtmlFixtures/attributes.from.html deleted file mode 100644 index e4f1734..0000000 --- a/phpunit/Tool/HtmlFixtures/attributes.from.html +++ /dev/null @@ -1,15 +0,0 @@ -