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 @@ - - - - - - - phpunit/Tool - phpunit/Include - phpunit/Settings - - - - phpunit/Install - phpunit/Admin - - - - phpunit/Admin - - - - - - - - - - - - - ./include - - ./include/thirdparty - - - - diff --git a/phpunit/Admin/AddonsTest.php b/phpunit/Admin/AddonsTest.php deleted file mode 100644 index c0ef169..0000000 --- a/phpunit/Admin/AddonsTest.php +++ /dev/null @@ -1,57 +0,0 @@ -admin_addons = new \gp\admin\Addons([]); - } - - - public function testAddonExample(){ - - $this->GetRequest('Admin/Addons'); - $this->GetRequest('Admin/Addons/Available'); - - - // make sure the example addon has been detected - $avail = $this->admin_addons->GetAvailAddons(); - $this->assertArrayHasKey('Example',$avail); - - - // install Example - $params = [ - 'cmd' => 'LocalInstall', - 'verified' => \gp\tool\Nonce::Create('post', true), - 'source' => 'Example', - ]; - $this->PostRequest('Admin/Addons',$params); - - - // make sure the example addon has been installed - \gp\tool::GetConfig(); - $installed = $this->admin_addons->GetDisplayInfo(); - $this->assertArrayHasKey('Example',$installed); - - - // uninstall - $params = [ - 'cmd' => 'confirm_uninstall', - 'verified' => \gp\tool\Nonce::Create('post', true), - 'addon' => 'Example', - ]; - $this->PostRequest('Admin/Addons',$params); - - \gp\tool::GetConfig(); - $installed = $this->admin_addons->GetDisplayInfo(); - $this->assertArrayNotHasKey('Example',$installed); - - } - - -} diff --git a/phpunit/Admin/ErrorTest.php b/phpunit/Admin/ErrorTest.php deleted file mode 100644 index 57ab690..0000000 --- a/phpunit/Admin/ErrorTest.php +++ /dev/null @@ -1,18 +0,0 @@ -expectException('\Exception'); - //\gp\tool\Output::InvalidMethod(); - - $response = $this->GetRequest('Admin/Errors'); - } - -} diff --git a/phpunit/Admin/ExportTest.php b/phpunit/Admin/ExportTest.php deleted file mode 100644 index fe66498..0000000 --- a/phpunit/Admin/ExportTest.php +++ /dev/null @@ -1,89 +0,0 @@ -GetRequest('Admin/Port'); - - - // generate an export - $params = [ - 'pca' => 'on', - 'media' => 'on', - 'themes' => 'on', - 'trash' => 'on', - 'compression' => 'zip', - 'verified' => \gp\tool\Nonce::Create('post', true), - 'cmd' => 'do_export', - ]; - - $this->PostRequest('Admin/Port',$params); - - $archive_path = $this->GetNewExport(); - $archive = new \gp\tool\Archive($archive_path); - $list = $archive->ListFiles(); - - - $expected_files = [ - 'gpexport/data/_pages', - 'gpexport/data/_extra', - 'gpexport/data/_site', - 'gpexport/data/_uploaded', - 'gpexport/Export.ini', - ]; - - foreach($expected_files as $expected){ - foreach($list as $file){ - if( strpos($file['name'],$expected) === false ){ - continue; - } - continue 2; - } - - echo 'Expected file not found in export. File = '.$expected; - print_r($list); - $this->fail('Expected file not found'); - } - - - // revert - $params = [ - 'archive' => basename($archive_path), - 'verified' => \gp\tool\Nonce::Create('post', true), - 'cmd' => 'revert_confirmed', - ]; - - $response = $this->PostRequest('Admin/Port',$params); - - if( strpos($response->GetBody(), $langmessage['Revert_Finished']) === false ){ - $this->fail('Revert failed'); - } - - } - - /** - * Get the newest export - * - */ - public function GetNewExport(){ - global $dataDir; - - $dir = $dataDir . '/data/_exports'; - $files = scandir($dir, SCANDIR_SORT_DESCENDING); - foreach($files as $file){ - if( $file != 'index.html' ){ - return $dir.'/'.$file; - } - } - - } - -} diff --git a/phpunit/Admin/ExtraTest.php b/phpunit/Admin/ExtraTest.php deleted file mode 100644 index 4e77616..0000000 --- a/phpunit/Admin/ExtraTest.php +++ /dev/null @@ -1,176 +0,0 @@ -admin_extra = new \gp\admin\Content\Extra([]); - } - - - public function testCreateExtra(){ - - - $this->GetRequest('Admin/Extra'); - - - $types = \gp\tool\Output\Sections::GetTypes(); - foreach($types as $type => $type_info){ - $this->AddType($type); - } - } - - public function testEditFooter(){ - - $this->GetRequest('Admin/Extra/Footer','cmd=EditExtra'); - - $text = '

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&param=([^"]+)#',$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 @@ -
foo
- -
foo
- -
foo
- -
foo
- -
foo
- - - -
- - \ No newline at end of file diff --git a/phpunit/Tool/HtmlFixtures/attributes.to.html b/phpunit/Tool/HtmlFixtures/attributes.to.html deleted file mode 100644 index cfaa2b4..0000000 --- a/phpunit/Tool/HtmlFixtures/attributes.to.html +++ /dev/null @@ -1,15 +0,0 @@ -
foo
- -
foo
- -
foo
- -
foo
- -
foo
- - - -
- - \ No newline at end of file diff --git a/phpunit/Tool/HtmlFixtures/basic.from.html b/phpunit/Tool/HtmlFixtures/basic.from.html deleted file mode 100644 index e50907c..0000000 --- a/phpunit/Tool/HtmlFixtures/basic.from.html +++ /dev/null @@ -1,4 +0,0 @@ -
- a div - alert -
\ No newline at end of file diff --git a/phpunit/Tool/HtmlFixtures/basic.to.html b/phpunit/Tool/HtmlFixtures/basic.to.html deleted file mode 100644 index 321e136..0000000 --- a/phpunit/Tool/HtmlFixtures/basic.to.html +++ /dev/null @@ -1,4 +0,0 @@ -
- a div - alert -
\ No newline at end of file diff --git a/phpunit/Tool/HtmlFixtures/comments.from.html b/phpunit/Tool/HtmlFixtures/comments.from.html deleted file mode 100644 index 3c9f689..0000000 --- a/phpunit/Tool/HtmlFixtures/comments.from.html +++ /dev/null @@ -1,13 +0,0 @@ - - -
filler html
- - - -
filler html
- - - -
filler html
- - diff --git a/phpunit/Tool/HtmlFixtures/comments.to.html b/phpunit/Tool/HtmlFixtures/comments.to.html deleted file mode 100644 index 3c9f689..0000000 --- a/phpunit/Tool/HtmlFixtures/comments.to.html +++ /dev/null @@ -1,13 +0,0 @@ - - -
filler html
- - - -
filler html
- - - -
filler html
- - diff --git a/phpunit/Tool/HtmlFixtures/invalid.from.html b/phpunit/Tool/HtmlFixtures/invalid.from.html deleted file mode 100644 index cdb6699..0000000 --- a/phpunit/Tool/HtmlFixtures/invalid.from.html +++ /dev/null @@ -1,6 +0,0 @@ - -
filler html
- -< and some text - -
filler html
- -< and some text - -
diff --git a/phpunit/Tool/HtmlFixtures/script.from.html b/phpunit/Tool/HtmlFixtures/script.from.html deleted file mode 100644 index 52702e7..0000000 --- a/phpunit/Tool/HtmlFixtures/script.from.html +++ /dev/null @@ -1,13 +0,0 @@ - -
- - -"; -var b = " - -
\ No newline at end of file diff --git a/phpunit/Tool/HtmlFixtures/script.to.html b/phpunit/Tool/HtmlFixtures/script.to.html deleted file mode 100644 index 37b5cd8..0000000 --- a/phpunit/Tool/HtmlFixtures/script.to.html +++ /dev/null @@ -1,13 +0,0 @@ - -
- - -"; -var b = " - -
\ No newline at end of file diff --git a/phpunit/Tool/HtmlFixtures/stripping.from.html b/phpunit/Tool/HtmlFixtures/stripping.from.html deleted file mode 100644 index 684dab5..0000000 --- a/phpunit/Tool/HtmlFixtures/stripping.from.html +++ /dev/null @@ -1,13 +0,0 @@ - -
filler html
- - - - - -
filler html
- -
filler html
- -
will be removed
- diff --git a/phpunit/Tool/HtmlFixtures/stripping.to.html b/phpunit/Tool/HtmlFixtures/stripping.to.html deleted file mode 100644 index f471fe4..0000000 --- a/phpunit/Tool/HtmlFixtures/stripping.to.html +++ /dev/null @@ -1,13 +0,0 @@ - -
filler html
- -
filler html
- -
filler html
- -
filler html
- -
filler html
- - - diff --git a/phpunit/Tool/HtmlFixtures/style.from.html b/phpunit/Tool/HtmlFixtures/style.from.html deleted file mode 100644 index 99f6a27..0000000 --- a/phpunit/Tool/HtmlFixtures/style.from.html +++ /dev/null @@ -1,8 +0,0 @@ - -
- -
\ No newline at end of file diff --git a/phpunit/Tool/HtmlFixtures/style.to.html b/phpunit/Tool/HtmlFixtures/style.to.html deleted file mode 100644 index 99f6a27..0000000 --- a/phpunit/Tool/HtmlFixtures/style.to.html +++ /dev/null @@ -1,8 +0,0 @@ - -
- -
\ No newline at end of file diff --git a/phpunit/Tool/HtmlTest.php b/phpunit/Tool/HtmlTest.php deleted file mode 100644 index 96111ab..0000000 --- a/phpunit/Tool/HtmlTest.php +++ /dev/null @@ -1,57 +0,0 @@ -dir = __DIR__ . '/HtmlFixtures'; - } - - /** - * Loop through all the files in the /HtmlFixtures directory - * Test each *.from.html file with *.to.html - * - */ - function testHTML(){ - - $files = scandir($this->dir); - - foreach($files as $file){ - - if( strpos($file,'.from.html') === false ){ - continue; - } - - $parts = explode('.',$file); - $name = array_shift($parts); - $this->CheckHtml($name); - - } - } - - - /** - * Compare the results of parsing a *.from.html file with the contents of a *.to.html file - * - */ - function CheckHtml($name){ - - $path_from = $this->dir.'/'.$name.'.from.html'; - $path_to = $this->dir.'/'.$name.'.to.html'; - - $from_html = file_get_contents($path_from); - $to_html = file_get_contents($path_to); - - $gp_html_output = new \gp\tool\Editing\HTML($from_html); - - self::AssertEquals( $to_html, $gp_html_output->result ); - } - - - -} \ No newline at end of file diff --git a/phpunit/bootstrap.php b/phpunit/bootstrap.php deleted file mode 100644 index 239cfc7..0000000 --- a/phpunit/bootstrap.php +++ /dev/null @@ -1,484 +0,0 @@ - false,'cookies' => true]); - - // create client for admin requests - self::$client_admin = new \GuzzleHttp\Client(['http_errors' => false,'cookies' => true]); - self::UseAdmin(); - - - self::Install(); - \gp\tool::GetLangFile(); - - self::LogIn(); - - $url = '/phpinfo.php'; - $response = self::GuzzleRequest('GET',$url); - $body = $response->getBody(); - self::$phpinfo = (string)$body; - - } - - - public static function StartServer(){ - global $dataDir; - - - $proc = ['php','-S','localhost:8081']; - - // doc root - $proc[] = '-t'; - $proc[] = $dataDir; // '.'; - - // error log - $proc[] = '-d'; - $proc[] = 'error_log='.$dataDir . '/data/request-errors.log'; - - // xdebug configuration to collect code coverage - //$proc[] = '-c'; - //$proc[] = __DIR__ . '/phpconfig.ini'; - - $proc[] = '-d'; - $proc[] = 'auto_prepend_file='.__DIR__ . '/ServerPrepend.php'; - - // xdebug profiling - /* - $profile_dir = sys_get_temp_dir().'/test-profiler'; - if( file_exists($profile_dir) ){ - \gp\tool\Files::RmAll($profile_dir); - } - mkdir($profile_dir); - - $proc[] = '-d'; - $proc[] = 'xdebug.profiler_enable=1'; - - $proc[] = '-d'; - $proc[] = 'xdebug.profiler_output_dir='.$profile_dir; - */ - - - - self::$process = new \Symfony\Component\Process\Process($proc); - self::$process->start(function($type,$buffer){ - self::$proc_output[] = ['type'=>$type,'buffer'=>(string)$buffer]; - }); - usleep(100000); //wait for server to get going - - - register_shutdown_function(function(){ - self::Console('Stopping server process'); - gptest_bootstrap::$process->stop(); - - usort(self::$tracking,function($a,$b){ - if( $a['time'] == $b['time'] ){ - return 0; - } - return ($a['time'] < $b['time']) ? 1 : -1; - }); - - self::Console('Slowest requests (the slowest will usually be because of scss compilation'); - self::$tracking = array_slice(self::$tracking,0,5); - - foreach(self::$tracking as $req){ - self::Console(' - '.$req['url'].' in '.$req['class'].' took '.$req['time']); - } - - }); - } - - - /** - * Switch current guzzle client to $client_admin - */ - public static function UseAdmin(){ - self::$client_current = self::$client_admin; - self::$is_admin = true; - } - - /** - * Switch current guzzle client to $client_user - */ - public static function UseAnon(){ - self::$client_current = self::$client_user; - self::$is_admin = false; - } - - /** - * Print process output - * - */ - public static function ProcessOutput($type,$url){ - - echo "\n\n----------------------------------------------------------------"; - self::Console('Begin Process Output: '.$type.' '.$url); - echo "\n"; - - if( !empty(self::$proc_output) ){ - self::Console('Proc Output'); - print_r(self::$proc_output); - } - echo "\nEnd Process Output\n----------------------------------------------------------------\n\n"; - } - - - /** - * Send a GET request to the test server - * - */ - public static function GetRequest( $slug, $query='', $nonce_action=false ){ - $url = \gp\tool::GetUrl( $slug, $query, false, $nonce_action); - return self::GuzzleRequest('GET',$url); - } - - - /** - * Send a POST request to the test server - * - */ - public static function PostRequest($slug, $params = []){ - - $url = \gp\tool::GetUrl($slug); - $options = ['form_params' => $params]; - - return self::GuzzleRequest('POST',$url,200,$options); - } - - /** - * Send a request to the test server and check the response - * - */ - public static function GuzzleRequest($type,$url,$expected_resonse = 200, $options = []){ - global $dataDir; - - $start = microtime(true); - $response = null; - $debug_file = $dataDir . '/data/response-' . self::$requests . '-anon-' . $type . '-' . str_replace('/','_',$url); - if( self::$is_admin ){ - $debug_file = $dataDir . '/data/response-' . self::$requests . '-admin-' . $type . '-' . str_replace('/','_',$url); - } - - $tracking = [ - 'url' => $url, - 'is_admin' => self::$is_admin, - 'class' => get_called_class(), - ]; - - - try{ - self::$proc_output = []; - $options['headers'] = ['X-REQ-ID' => self::$requests,'Connection'=>'close']; - $url = 'http://localhost:8081' . $url; - $response = self::$client_current->request($type, $url, $options); - $body = $response->getBody(); - $status = $response->getStatusCode(); - - - file_put_contents($debug_file, $body); - self::$requests++; - - self::$process->getOutput(); # makes symfony/process populate our self::$proc_output - - - if( $expected_resonse !== $status ){ - self::ProcessOutput($type,$url); - self::Console('PHPINFO()'); - echo (string)self::$phpinfo; - } - self::assertEquals($expected_resonse, $status); - - - // make sure the response doesn't have
- if( self::$is_admin === false ){ - self::assertNotStrpos($body,'gp_admin_html'); - } - - self::ServerErrors($type,$url); - - }catch( \Exception $e ){ - self::ServerErrors($type,$url); - self::Fail('Exception fetching url '.$url.$e->getMessage()); - } - - $tracking['time'] = microtime(true) - $start; - self::$tracking[] = $tracking; - - return $response; - } - - - /** - * Output Error log - * - */ - public static function ServerErrors($type,$url){ - global $dataDir; - - $error_log = $dataDir . '/data/request-errors.log'; - if( !file_exists($error_log) ){ - return; - } - - $content = file_get_contents($error_log); - if( empty($content) ){ - return; - } - - echo "\n\n----------------------------------------------------------------"; - self::Console('Error Log for '.$type.' '.$url); - echo "\n"; - - echo $content; - echo "\n\nEnd Error Log\n----------------------------------------------------------------\n\n"; - - $fp = fopen($error_log, "r+"); - ftruncate($fp, 0); - fclose($fp); - - self::assertEmpty($content,'php error log was not empty'); - } - - - /** - * Log In - * - */ - public static function LogIn(){ - - // load login page to set cookies - $response = self::GetRequest('Admin'); - - $params = []; - $params['cmd'] = 'login'; - $params['username'] = self::user_name; - $params['password'] = self::user_pass; - $params['login_nonce'] = \gp\tool\Nonce::Create('login_nonce',true,300); - $response = self::PostRequest('Admin',$params); - } - - - - /** - * Create an install folder in the temporary directory - * - */ - public static function PrepInstall(){ - global $dataDir, $languages, $config; - - - - // get a clean temporary install folder - $dataDir = sys_get_temp_dir().'/typesetter-test'; - $old_dir = sys_get_temp_dir().'/typesetter-test-old'; - if( file_exists($dataDir) ){ - rename($dataDir,$old_dir); - } - mkdir($dataDir); - mkdir($dataDir.'/data'); - - - - - // create symlinks of include, addons, and themes - $symlinks = ['include','addons','themes','gpconfig.php','index.php','vendor']; - foreach($symlinks as $name){ - - $path = $dataDir.'/'.$name; - $target = $_SERVER['PWD'].'/'.$name; - - if( !file_exists($target) ){ - self::Console('symlink target does not exist: '. $target); - continue; - } - - if( file_exists($path) ){ - unlink($path); - } - - symlink( $target, $path); - } - - - // create a phpinfo.php file - $file = $dataDir.'/phpinfo.php'; - $content = ' $val){ - self::assertGreaterThanOrEqual( $val, $installer->statuses[$i]['can_install'], 'Unexpected status ('.$i.') '.pre($installer->statuses[$i]) ); - } - - - - // test rendering of the install template - $response = self::GetRequest(''); - - //ob_start(); - //includeFile('install/install.php'); - //$installer->Form_Entry(); - //$content = ob_get_clean(); - //self::assertNotEmpty($content); - - - - //attempt to install - $params = []; - $params['site_title'] = 'unit tests'; - $params['email'] = self::user_email; - $params['username'] = self::user_name; - $params['password'] = self::user_pass; - $params['password1'] = self::user_pass; - $params['cmd'] = 'Install'; - $response = self::PostRequest('',$params); - - - - //double check - $installed = \gp\tool::Installed(); - self::AssertTrue($installed,'Not installed'); - - - - \gp\tool::GetConfig(); - } - - public static function assertStrpos( $haystack, $needle , $msg = 'String not found' ){ - - if( strpos($haystack, $needle) === false ){ - self::fail($msg); - } - - } - - public static function assertNotStrpos( $haystack, $needle , $msg = 'String found' ){ - - if( strpos($haystack, $needle) !== false ){ - self::fail($msg); - } - - } - -} diff --git a/phpunit/index.html b/phpunit/index.html deleted file mode 100644 index 8b13789..0000000 --- a/phpunit/index.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/phpunit/phpconfig.ini b/phpunit/phpconfig.ini deleted file mode 100644 index 4fddb7d..0000000 --- a/phpunit/phpconfig.ini +++ /dev/null @@ -1,6 +0,0 @@ - -#xdebug.remote_enable = On -#xdebug.remote_autostart = On - -#auto_prepend_file = 'ServerPrepend.php' -#auto_append_file = 'ServerAppend.php'