mirror of
				https://github.com/gtbu/Typesetter-5.3-p8.git
				synced 2025-11-03 22:38:27 +01:00 
			
		
		
		
	removed old phpunit
phpunit was only for testing
This commit is contained in:
		
							parent
							
								
									8ec460c113
								
							
						
					
					
						commit
						2b21aaa6f9
					
				
					 38 changed files with 0 additions and 2066 deletions
				
			
		
							
								
								
									
										28
									
								
								.travis.yml
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								.travis.yml
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +0,0 @@
 | 
			
		|||
comment: false
 | 
			
		||||
							
								
								
									
										45
									
								
								phpunit.xml
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								phpunit.xml
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -1,45 +0,0 @@
 | 
			
		|||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<phpunit
 | 
			
		||||
    processIsolation	= "false"
 | 
			
		||||
    stopOnFailure		= "true"
 | 
			
		||||
    stopOnError			= "true"
 | 
			
		||||
    stopOnIncomplete	= "true"
 | 
			
		||||
    stopOnSkipped		= "false"
 | 
			
		||||
    bootstrap			= "phpunit/bootstrap.php"
 | 
			
		||||
	verbose				= "true"
 | 
			
		||||
    >
 | 
			
		||||
 | 
			
		||||
    <testsuites>
 | 
			
		||||
 | 
			
		||||
        <testsuite name="Tools">
 | 
			
		||||
            <directory>phpunit/Tool</directory>
 | 
			
		||||
			<directory>phpunit/Include</directory>
 | 
			
		||||
			<directory>phpunit/Settings</directory>
 | 
			
		||||
        </testsuite>
 | 
			
		||||
 | 
			
		||||
        <testsuite name="Installation">
 | 
			
		||||
            <directory>phpunit/Install</directory>
 | 
			
		||||
            <directory>phpunit/Admin</directory>
 | 
			
		||||
        </testsuite>
 | 
			
		||||
 | 
			
		||||
        <testsuite name="Admin">
 | 
			
		||||
            <directory>phpunit/Admin</directory>
 | 
			
		||||
        </testsuite>
 | 
			
		||||
 | 
			
		||||
    </testsuites>
 | 
			
		||||
 | 
			
		||||
	<logging>
 | 
			
		||||
	    <log type="testdox-text" target="php://stdout"/>
 | 
			
		||||
		<log type="coverage-clover" target="x_coverage/unit-tests.clover"/>
 | 
			
		||||
	</logging>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	<filter>
 | 
			
		||||
        <whitelist>
 | 
			
		||||
            <directory suffix=".php">./include</directory>
 | 
			
		||||
			<exclude>
 | 
			
		||||
			      <directory suffix=".php">./include/thirdparty</directory>
 | 
			
		||||
		  	</exclude>
 | 
			
		||||
        </whitelist>
 | 
			
		||||
    </filter>
 | 
			
		||||
</phpunit>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,57 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace phpunit\Admin;
 | 
			
		||||
 | 
			
		||||
class AddonsTest extends \gptest_bootstrap{
 | 
			
		||||
 | 
			
		||||
	private $admin_addons;
 | 
			
		||||
 | 
			
		||||
	public function setUp(){
 | 
			
		||||
		parent::setUp();
 | 
			
		||||
 | 
			
		||||
		$this->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);
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,18 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace phpunit\Admin;
 | 
			
		||||
 | 
			
		||||
class ErrorTest extends \gptest_bootstrap{
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	public function testError(){
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		// create an exception
 | 
			
		||||
		//$this->expectException('\Exception');
 | 
			
		||||
		//\gp\tool\Output::InvalidMethod();
 | 
			
		||||
 | 
			
		||||
		$response = $this->GetRequest('Admin/Errors');
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,89 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class phpunit_Export extends gptest_bootstrap{
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Test the export and import admin functionality
 | 
			
		||||
	 *
 | 
			
		||||
	 */
 | 
			
		||||
	public function testExport(){
 | 
			
		||||
		global $wbMessageBuffer, $langmessage;
 | 
			
		||||
 | 
			
		||||
		// load
 | 
			
		||||
		$this->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;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,176 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace phpunit\Admin;
 | 
			
		||||
 | 
			
		||||
class ExtraTest extends \gptest_bootstrap{
 | 
			
		||||
 | 
			
		||||
	private $admin_extra;
 | 
			
		||||
 | 
			
		||||
	public function setUp(){
 | 
			
		||||
		parent::setUp();
 | 
			
		||||
 | 
			
		||||
		$this->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 = '<p>New Text</p>';
 | 
			
		||||
 | 
			
		||||
		$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');
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,83 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace phpunit\Admin;
 | 
			
		||||
 | 
			
		||||
class LayoutTest extends \gptest_bootstrap{
 | 
			
		||||
 | 
			
		||||
	private $admin_layout;
 | 
			
		||||
 | 
			
		||||
	public function setUp(){
 | 
			
		||||
		parent::setUp();
 | 
			
		||||
 | 
			
		||||
		$this->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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,68 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace phpunit\Admin;
 | 
			
		||||
 | 
			
		||||
class PermissionsTest extends \gptest_bootstrap{
 | 
			
		||||
 | 
			
		||||
	public function testFilePermissions(){
 | 
			
		||||
		global $gp_index;
 | 
			
		||||
 | 
			
		||||
		\gp\tool::GetPagesPHP();
 | 
			
		||||
 | 
			
		||||
		$this->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'] );
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,92 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace phpunit\Admin;
 | 
			
		||||
 | 
			
		||||
class PreferencesTest extends \gptest_bootstrap{
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Test changing the admin user's password
 | 
			
		||||
	 *
 | 
			
		||||
	 */
 | 
			
		||||
	public function testChangePassword(){
 | 
			
		||||
 | 
			
		||||
		// password_hash -> 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];
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,20 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class phpunit_StatusTest extends gptest_bootstrap{
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Test the admin/status health check
 | 
			
		||||
	 *
 | 
			
		||||
	 */
 | 
			
		||||
	public function testStatus(){
 | 
			
		||||
 | 
			
		||||
		$admin_status = new \gp\admin\Tools\Status();
 | 
			
		||||
		$admin_status->CheckDataDir();
 | 
			
		||||
 | 
			
		||||
		$this->AssertGreaterThan(0,$admin_status->GetValue('passed_count'));
 | 
			
		||||
		$this->AssertEquals(0,$admin_status->GetValue('failed_count'));
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,87 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace phpunit\Admin;
 | 
			
		||||
 | 
			
		||||
class UploadTest extends \gptest_bootstrap{
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	public function testUpload(){
 | 
			
		||||
		global $dataDir;
 | 
			
		||||
 | 
			
		||||
		$file = $dataDir . '/include/imgs/stars.png';
 | 
			
		||||
		$this->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);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,98 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace phpunit\Admin;
 | 
			
		||||
 | 
			
		||||
class UsersTest extends \gptest_bootstrap{
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Test add and deleting users
 | 
			
		||||
	 *
 | 
			
		||||
	 */
 | 
			
		||||
	public function testNewUser(){
 | 
			
		||||
 | 
			
		||||
		$this->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);
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,27 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class phpunit_Languages extends gptest_bootstrap{
 | 
			
		||||
 | 
			
		||||
	function testKeys(){
 | 
			
		||||
		global $langmessage, $languages;
 | 
			
		||||
 | 
			
		||||
		//get en language
 | 
			
		||||
		\gp\tool::GetLangFile('main.inc','en');
 | 
			
		||||
		$keys_en = array_keys($langmessage);
 | 
			
		||||
 | 
			
		||||
		//compare keys in other languages
 | 
			
		||||
		foreach($languages as $code => $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));
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,142 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class phpunit_Update extends gptest_bootstrap{
 | 
			
		||||
 | 
			
		||||
	private $FileSystem;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 *
 | 
			
		||||
	 */
 | 
			
		||||
	function testUpdate(){
 | 
			
		||||
 | 
			
		||||
		$this->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)');
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,42 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
require dirname(__DIR__) . '/vendor/autoload.php';
 | 
			
		||||
 | 
			
		||||
if( class_exists('\SebastianBergmann\CodeCoverage\CodeCoverage') ){
 | 
			
		||||
 | 
			
		||||
	$include_dir	= dirname(__DIR__).'/include';
 | 
			
		||||
	$cov_obj		= new \SebastianBergmann\CodeCoverage\CodeCoverage();
 | 
			
		||||
	$cov_obj->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);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,29 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Start xdebug code coverage
 | 
			
		||||
 * Register autoload for merging coverage with php-code-coverage
 | 
			
		||||
 * https://stackoverflow.com/questions/10167775/aggregating-code-coverage-from-several-executions-of-phpunit
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
defined('gp_unit_testing') or define('gp_unit_testing',true);
 | 
			
		||||
defined('gpdebug') or define('gpdebug',true); // sets error_reporting(ALL)
 | 
			
		||||
 | 
			
		||||
if( function_exists('xdebug_start_code_coverage') ){
 | 
			
		||||
	xdebug_start_code_coverage();
 | 
			
		||||
 | 
			
		||||
	function SaveXdebugCoverage(){
 | 
			
		||||
		$cov_dir	= dirname(__DIR__).'/x_coverage';
 | 
			
		||||
		$name		= str_replace('/','-','request-'.$_SERVER['HTTP_X_REQ_ID'].'-'.$_SERVER['REQUEST_METHOD'].'-'.$_SERVER['REQUEST_URI']);
 | 
			
		||||
		$cov_file	= $cov_dir.'/'.$name.'.json';
 | 
			
		||||
		$data		= xdebug_get_code_coverage();
 | 
			
		||||
		file_put_contents( $cov_file, json_encode($data,JSON_PRETTY_PRINT));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	register_shutdown_function('SaveXdebugCoverage');
 | 
			
		||||
	ob_start(function($buffer){
 | 
			
		||||
		SaveXdebugCoverage();
 | 
			
		||||
		return $buffer;
 | 
			
		||||
	});
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,21 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
if( !class_exists('\PHPUnit_Framework_BaseTestListener') ){
 | 
			
		||||
	if( class_exists('\PHPUnit\Framework\TestListener') ){
 | 
			
		||||
    	class_alias('\PHPUnit\Framework\TestListener', '\PHPUnit_Framework_BaseTestListener');
 | 
			
		||||
	}else{
 | 
			
		||||
		throw new \Exception('\PHPUnit\Framework\TestListener class doesnt exist');
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ServerSetup extends PHPUnit_Framework_BaseTestListener{
 | 
			
		||||
 | 
			
		||||
    public function startTestSuite($suite){
 | 
			
		||||
		echo pre('start test suite');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function endTestSuite($suite){
 | 
			
		||||
		echo pre('end test suite');
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,29 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace phpunit\Admin;
 | 
			
		||||
 | 
			
		||||
class MissingTest extends \gptest_bootstrap{
 | 
			
		||||
 | 
			
		||||
	public function test404(){
 | 
			
		||||
 | 
			
		||||
		$this->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');
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,222 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Test the gp\tool\Archive class
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
class phpunit_Archive extends gptest_bootstrap{
 | 
			
		||||
 | 
			
		||||
	private $dir;
 | 
			
		||||
	private $types		= [
 | 
			
		||||
							'tbz'							=> 'PharData',
 | 
			
		||||
							'tgz'							=> 'PharData',
 | 
			
		||||
							'tar'							=> 'PharData',
 | 
			
		||||
							'zip'							=> 'ZipArchive',
 | 
			
		||||
							'tar.bz'						=> 'PharData',
 | 
			
		||||
							'tar.gz'						=> 'PharData',
 | 
			
		||||
						];
 | 
			
		||||
 | 
			
		||||
	private $files		= [
 | 
			
		||||
							'index.html'					=> '<html><body></body></html>',
 | 
			
		||||
							'foo/text.txt'					=> 'lorem ipsum',
 | 
			
		||||
							'foo/index.html'				=> '<html><body></body></html>',
 | 
			
		||||
							'/foo/bar'						=> 'foo bar',
 | 
			
		||||
							'foo/unicode/index.html' 		=> '<html><body></body></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;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,15 +0,0 @@
 | 
			
		|||
<div class=test>foo</div>
 | 
			
		||||
 | 
			
		||||
<div class='te"st'>foo</div>
 | 
			
		||||
 | 
			
		||||
<div class="te" st">foo</div>
 | 
			
		||||
 | 
			
		||||
<div class='te' st'>foo</div>
 | 
			
		||||
 | 
			
		||||
<div id="id" attr= >foo</div>
 | 
			
		||||
 | 
			
		||||
<input type="text" disabled />
 | 
			
		||||
 | 
			
		||||
<div style="display: block; background: url('this.jpg') repeat scroll 0% 0% transparent;"> </div>
 | 
			
		||||
 | 
			
		||||
<img alt="" src="/img/path" />
 | 
			
		||||
| 
						 | 
				
			
			@ -1,15 +0,0 @@
 | 
			
		|||
<div class="test">foo</div>
 | 
			
		||||
 | 
			
		||||
<div class="te"st">foo</div>
 | 
			
		||||
 | 
			
		||||
<div class="te" st">foo</div>
 | 
			
		||||
 | 
			
		||||
<div class="te' st">foo</div>
 | 
			
		||||
 | 
			
		||||
<div id="id" attr>foo</div>
 | 
			
		||||
 | 
			
		||||
<input type="text" disabled />
 | 
			
		||||
 | 
			
		||||
<div style="display: block; background: url('this.jpg') repeat scroll 0% 0% transparent;"> </div>
 | 
			
		||||
 | 
			
		||||
<img alt="" src="/img/path" />
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +0,0 @@
 | 
			
		|||
<div class="test">
 | 
			
		||||
	<B>a div</B>
 | 
			
		||||
	<a href="#" onclick="javascript:alert('this')">alert</a>
 | 
			
		||||
</div>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +0,0 @@
 | 
			
		|||
<div class="test">
 | 
			
		||||
	<b>a div</b>
 | 
			
		||||
	<a href="#" onclick="javascript:alert('this')">alert</a>
 | 
			
		||||
</div>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,13 +0,0 @@
 | 
			
		|||
<!-- comment -->
 | 
			
		||||
 | 
			
		||||
<div class="test">filler html</div>
 | 
			
		||||
 | 
			
		||||
<!-- <div> commented html </div> -->
 | 
			
		||||
 | 
			
		||||
<div class="test">filler html</div>
 | 
			
		||||
 | 
			
		||||
<!------- <div attr="blah"> commented html </div> ------->
 | 
			
		||||
 | 
			
		||||
<div class="test">filler html</div>
 | 
			
		||||
 | 
			
		||||
<!--div  commented --->
 | 
			
		||||
| 
						 | 
				
			
			@ -1,13 +0,0 @@
 | 
			
		|||
<!-- comment -->
 | 
			
		||||
 | 
			
		||||
<div class="test">filler html</div>
 | 
			
		||||
 | 
			
		||||
<!-- <div> commented html </div> -->
 | 
			
		||||
 | 
			
		||||
<div class="test">filler html</div>
 | 
			
		||||
 | 
			
		||||
<!------- <div attr="blah"> commented html </div> ------->
 | 
			
		||||
 | 
			
		||||
<div class="test">filler html</div>
 | 
			
		||||
 | 
			
		||||
<!--div  commented --->
 | 
			
		||||
| 
						 | 
				
			
			@ -1,6 +0,0 @@
 | 
			
		|||
 | 
			
		||||
<div>filler html</div>
 | 
			
		||||
 | 
			
		||||
< and some text
 | 
			
		||||
 | 
			
		||||
<div
 | 
			
		||||
| 
						 | 
				
			
			@ -1,6 +0,0 @@
 | 
			
		|||
 | 
			
		||||
<div>filler html</div>
 | 
			
		||||
 | 
			
		||||
< and some text
 | 
			
		||||
 | 
			
		||||
<div>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,13 +0,0 @@
 | 
			
		|||
 | 
			
		||||
<div class="script-wrap">
 | 
			
		||||
<script> </script>
 | 
			
		||||
 | 
			
		||||
<script>var a = "</script>";
 | 
			
		||||
var b = "<script>";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//this is a quote
 | 
			
		||||
 | 
			
		||||
</SCript>
 | 
			
		||||
 | 
			
		||||
</div>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,13 +0,0 @@
 | 
			
		|||
 | 
			
		||||
<div class="script-wrap">
 | 
			
		||||
<script> </script>
 | 
			
		||||
 | 
			
		||||
<script>var a = "</script>";
 | 
			
		||||
var b = "<script>";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//this is a quote
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
</div>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,13 +0,0 @@
 | 
			
		|||
 | 
			
		||||
<div class="editable_area filetype-text" id="someid" >filler html</div>
 | 
			
		||||
 | 
			
		||||
<div class="foo ExtraEditLink" id="someid">filler html</div>
 | 
			
		||||
 | 
			
		||||
<div class="ExtraEditLink" id="someid">filler html</div>
 | 
			
		||||
 | 
			
		||||
<div class="foo ExtraEditLnks" id="someid">filler html</div>
 | 
			
		||||
 | 
			
		||||
<div class="ExtraEditLnks" id="someid">filler html</div>
 | 
			
		||||
 | 
			
		||||
<div class="gp_nosave">will be removed</div>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1,13 +0,0 @@
 | 
			
		|||
 | 
			
		||||
<div>filler html</div>
 | 
			
		||||
 | 
			
		||||
<div>filler html</div>
 | 
			
		||||
 | 
			
		||||
<div>filler html</div>
 | 
			
		||||
 | 
			
		||||
<div>filler html</div>
 | 
			
		||||
 | 
			
		||||
<div>filler html</div>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1,8 +0,0 @@
 | 
			
		|||
 | 
			
		||||
<div class="style-wrap">
 | 
			
		||||
<style type="text/css">
 | 
			
		||||
.test:after{
 | 
			
		||||
	content:'</div><div>';
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
</div>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,8 +0,0 @@
 | 
			
		|||
 | 
			
		||||
<div class="style-wrap">
 | 
			
		||||
<style type="text/css">
 | 
			
		||||
.test:after{
 | 
			
		||||
	content:'</div><div>';
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
</div>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,57 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Test the \gp\tool\Editing\HTML
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
class phpunit_HTML extends gptest_bootstrap{
 | 
			
		||||
 | 
			
		||||
	private $dir;
 | 
			
		||||
 | 
			
		||||
	function setUp(){
 | 
			
		||||
		$this->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 );
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,484 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
echo "\n************************************************************************************";
 | 
			
		||||
echo "\nBegin gpEasy Tests\n\n";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
defined('gpdebug') or define('gpdebug',true);
 | 
			
		||||
defined('is_running') or define('is_running',true);
 | 
			
		||||
defined('gp_unit_testing') or define('gp_unit_testing',true);
 | 
			
		||||
defined('gp_nonce_algo') or define('gp_nonce_algo','sha512');
 | 
			
		||||
error_reporting(E_ALL); // 32767
 | 
			
		||||
 | 
			
		||||
if (!class_exists('\PHPUnit_Framework_TestCase') && class_exists('\PHPUnit\Framework\TestCase'))
 | 
			
		||||
    class_alias('\PHPUnit\Framework\TestCase', '\PHPUnit_Framework_TestCase');
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class gptest_bootstrap extends \PHPUnit_Framework_TestCase{
 | 
			
		||||
 | 
			
		||||
	protected static $process;
 | 
			
		||||
	protected static $client_user;			// guzzle client for making anonymous user requests
 | 
			
		||||
	protected static $client_admin;			// guzzle client for making admin user requests
 | 
			
		||||
	protected static $client_current;
 | 
			
		||||
	protected static $is_admin		= false;
 | 
			
		||||
	protected static $requests		= 0;
 | 
			
		||||
	protected static $proc_output	= [];
 | 
			
		||||
	protected static $phpinfo;
 | 
			
		||||
	protected static $tracking		= [];
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	const user_name		= 'phpunit_username';
 | 
			
		||||
	const user_pass		= 'phpunit-test-password';
 | 
			
		||||
	const user_email	= 'test@typesettercms.com';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	static function log($msg){
 | 
			
		||||
		static $fp;
 | 
			
		||||
 | 
			
		||||
		if( !$fp ){
 | 
			
		||||
			$log	= __DIR__ . '/phpunit.log';
 | 
			
		||||
			$fp		= fopen($log, 'a');
 | 
			
		||||
		}
 | 
			
		||||
		fwrite($fp, "\n".print_r($msg, TRUE));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function setUp(){
 | 
			
		||||
		self::UseAdmin();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Use php's built-in web server
 | 
			
		||||
	 * https://medium.com/@peter.lafferty/start-phps-built-in-web-server-from-phpunit-9571f38c5045
 | 
			
		||||
	 *
 | 
			
		||||
	 */
 | 
			
		||||
	public static function setUpBeforeClass(){
 | 
			
		||||
 | 
			
		||||
		if( function_exists('showError') ){
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		self::Console('Start server, set phpinfo...');
 | 
			
		||||
 | 
			
		||||
		self::PrepInstall();
 | 
			
		||||
		self::StartServer();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		// create client for user requests
 | 
			
		||||
		self::$client_user			= new \GuzzleHttp\Client(['http_errors' => 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 <div id="gp_admin_html">
 | 
			
		||||
			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	= '<?php phpinfo();';
 | 
			
		||||
		file_put_contents($file,$content);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		include('include/common.php');
 | 
			
		||||
		spl_autoload_register( array('\\gp\\tool','Autoload') );
 | 
			
		||||
		require dirname(__DIR__) . '/vendor/autoload.php';
 | 
			
		||||
		includeFile('tool/functions.php');
 | 
			
		||||
 | 
			
		||||
		self::Console('datadir = '.$dataDir);
 | 
			
		||||
		self::Console('gp_data_type = '.gp_data_type);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		// delete old installation
 | 
			
		||||
		\gp\tool\Files::RmAll($old_dir);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		// reset coverage folder
 | 
			
		||||
		$cov_dir	= dirname(__DIR__).'/x_coverage';
 | 
			
		||||
		if( file_exists($cov_dir) ){
 | 
			
		||||
			self::Console('resetting coverage folder: '.$cov_dir);
 | 
			
		||||
			\gp\tool\Files::RmAll($cov_dir);
 | 
			
		||||
		}
 | 
			
		||||
		mkdir($cov_dir);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Output a string to the console
 | 
			
		||||
	 *
 | 
			
		||||
	 */
 | 
			
		||||
	public static function Console($msg){
 | 
			
		||||
		echo "\n";
 | 
			
		||||
		echo "\e[0;32m";
 | 
			
		||||
		echo $msg;
 | 
			
		||||
		echo "\e[0m";
 | 
			
		||||
		echo "\n";
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/*
 | 
			
		||||
	 * Create an installation
 | 
			
		||||
	 *
 | 
			
		||||
	 */
 | 
			
		||||
	public static function Install(){
 | 
			
		||||
		global $config;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		//make sure it's not installed
 | 
			
		||||
		$installed = \gp\tool::Installed();
 | 
			
		||||
		self::AssertFalse($installed,'Cannot test installation (Already Installed)');
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		// test install checks
 | 
			
		||||
		// one of the checks actually fails
 | 
			
		||||
		$values			= [1,1,-1,1,1,1];
 | 
			
		||||
		$installer		= new \gp\install\Installer();
 | 
			
		||||
		foreach($values as $i => $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);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +0,0 @@
 | 
			
		|||
 | 
			
		||||
| 
						 | 
				
			
			@ -1,6 +0,0 @@
 | 
			
		|||
 | 
			
		||||
#xdebug.remote_enable = On
 | 
			
		||||
#xdebug.remote_autostart = On
 | 
			
		||||
 | 
			
		||||
#auto_prepend_file = 'ServerPrepend.php'
 | 
			
		||||
#auto_append_file = 'ServerAppend.php'
 | 
			
		||||
		Loading…
	
		Reference in a new issue