This repository has been archived by the owner on Apr 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
67 changed files
with
7,576 additions
and
4,719 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ insert_final_newline = true | |
|
||
[{*.php,*.json}] | ||
indent_style = space | ||
indent_size = 4 | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
# Composer | ||
vendor | ||
.DS_Store | ||
|
||
# Binaries | ||
composer.phar | ||
|
||
# Tests | ||
phpunit.xml | ||
|
||
# Directories etc. | ||
ProcessWire | ||
Tests/processwire.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php namespace Wireshell\Tests; | ||
|
||
use GuzzleHttp\Client; | ||
use \PHPUnit_Framework_TestCase as TestCase; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
|
||
abstract class BaseTestCase extends TestCase { | ||
|
||
const INSTALLATION_FOLDER = 'ProcessWire'; | ||
const INSTALLATION_ARCHIVE = 'Tests/processwire.zip'; | ||
|
||
/** | ||
* @var Filesystem | ||
*/ | ||
public $fs; | ||
|
||
/** | ||
* @var Application | ||
*/ | ||
public $app; | ||
|
||
public $tester; | ||
public $command; | ||
|
||
public function __construct() { | ||
$this->fs = new Filesystem(); | ||
$this->app = new Application(); | ||
$this->app->setAutoExit(false); | ||
} | ||
|
||
public function checkInstallation() { | ||
if ($this->fs->exists(self::INSTALLATION_FOLDER)) $this->fs->remove(self::INSTALLATION_FOLDER); | ||
|
||
// if installation exists and zip file is older than 24h remove it | ||
if ($this->fs->exists(self::INSTALLATION_ARCHIVE) && (time() - filemtime(self::INSTALLATION_ARCHIVE)) > 86400) { | ||
$this->fs->remove(self::INSTALLATION_ARCHIVE); | ||
} | ||
|
||
if (!$this->fs->exists(self::INSTALLATION_ARCHIVE)) $this->downloadArchive(); | ||
} | ||
|
||
public function downloadArchive() { | ||
$client = new Client(); | ||
$client->request('GET', 'https://github.com/processwire/processwire/archive/master.zip', ['sink' => 'Tests/processwire.zip']); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?php namespace Wireshell\Tests\Commands\Common; | ||
|
||
use Symfony\Component\Console\Tester\CommandTester; | ||
use Symfony\Component\Console\Question\Question; | ||
use Ofbeaton\Console\Tester\QuestionTester; | ||
use Ofbeaton\Console\Tester\UnhandledQuestionException; | ||
use Wireshell\Tests\BaseTestCase as Base; | ||
use Wireshell\Commands\Common\NewCommand; | ||
|
||
class NewCommandTest extends Base { | ||
use QuestionTester; | ||
|
||
/** | ||
* @field array default config values | ||
*/ | ||
protected $defaults = array( | ||
'--timezone' => 'Europe\Berlin', | ||
'--httpHosts' => 'pwtest.dev', | ||
'--username' => 'admin', | ||
'--userpass' => 'password', | ||
'--useremail' => 'test@wireshell.pw' | ||
); | ||
|
||
/** | ||
* @before | ||
*/ | ||
public function setupCommand() { | ||
$this->app->add(new NewCommand()); | ||
$this->command = $this->app->find('new'); | ||
$this->tester = new CommandTester($this->command); | ||
|
||
$credentials = array( | ||
'--dbUser' => $GLOBALS['DB_USER'], | ||
'--dbPass' => $GLOBALS['DB_PASSWD'], | ||
'--dbName' => $GLOBALS['DB_DBNAME'] | ||
); | ||
|
||
$this->extends = array( | ||
'command' => $this->command->getName(), | ||
'directory' => Base::INSTALLATION_FOLDER, | ||
); | ||
|
||
$this->defaults = array_merge($this->defaults, $credentials, $this->extends); | ||
} | ||
|
||
public function testDownload() { | ||
$this->checkInstallation(); | ||
$options = array('--no-install' => true, '--src' => Base::INSTALLATION_ARCHIVE); | ||
$this->tester->execute(array_merge($this->defaults, $options)); | ||
|
||
$this->assertDirectoryExists(Base::INSTALLATION_FOLDER); | ||
$this->assertDirectoryExists(Base::INSTALLATION_FOLDER . '/wire'); | ||
$this->assertDirectoryNotExists(Base::INSTALLATION_FOLDER . '/site'); | ||
} | ||
|
||
/** | ||
* @depends testDownload | ||
* @expectedException RuntimeException | ||
* @expectedExceptionMessageRegExp /(Database connection information did not work)./ | ||
*/ | ||
public function testInstallWrongPassword() { | ||
// check ProcessWire has not been installed yet | ||
if ($this->fs->exists(Base::INSTALLATION_FOLDER . '/site/config.php')) return; | ||
|
||
// return the input you want to answer the question with | ||
$this->mockQuestionHelper($this->command, function($text, $order, Question $question) { | ||
if (strpos($text, 'database user name') !== false) return 'whatever'; | ||
if (strpos($text, 'database password') !== false) return 'wrong'; | ||
|
||
throw new UnhandledQuestionException(); | ||
}); | ||
|
||
$options = array( | ||
'--src' => Base::INSTALLATION_ARCHIVE, | ||
'--dbPass' => 'wrong' | ||
); | ||
|
||
$this->tester->execute(array_merge($this->defaults, $options)); | ||
} | ||
|
||
/** | ||
* @depends testDownload | ||
* @expectedExceptionMessageRegExp /(enter a valid email address)/ | ||
*/ | ||
public function testInstallInvalidEmailAddress() { | ||
// check ProcessWire has not been installed yet | ||
if ($this->fs->exists(Base::INSTALLATION_FOLDER . '/site/config.php')) return; | ||
|
||
// return the input you want to answer the question with | ||
$this->mockQuestionHelper($this->command, function($text, $order, Question $question) { | ||
if (strpos($text, 'admin email address') !== false) return 'whatever'; | ||
|
||
throw new UnhandledQuestionException(); | ||
}); | ||
|
||
$options = array( | ||
'--src' => Base::INSTALLATION_ARCHIVE, | ||
'--useremail' => 'invalid' | ||
); | ||
|
||
$this->tester->execute(array_merge($this->defaults, $options)); | ||
} | ||
|
||
/** | ||
* @depends testDownload | ||
*/ | ||
public function testInstall() { | ||
// check ProcessWire has not been installed yet | ||
if ($this->fs->exists(Base::INSTALLATION_FOLDER . '/site/config.php')) return; | ||
|
||
$this->tester->execute($this->defaults); | ||
$output = $this->tester->getDisplay(); | ||
|
||
$this->assertDirectoryExists(Base::INSTALLATION_FOLDER . '/site'); | ||
$this->assertFileExists(Base::INSTALLATION_FOLDER . '/site/config.php'); | ||
$this->assertContains('Congratulations, ProcessWire has been successfully installed.', $output); | ||
} | ||
|
||
/** | ||
* @depends testInstall | ||
* @expectedExceptionMessageRegExp /(There is already a \')(.*)(\' project)/ | ||
*/ | ||
public function testIsInstalled() { | ||
$this->tester->execute($this->defaults); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php namespace Wireshell\Tests\Commands\Common; | ||
|
||
use Symfony\Component\Console\Tester\CommandTester; | ||
use Wireshell\Tests\BaseTestCase as Base; | ||
use Wireshell\Commands\Common\StatusCommand; | ||
|
||
class StatusCommandTest extends Base { | ||
|
||
/** | ||
* @before | ||
*/ | ||
public function setupCommand() { | ||
$this->app->add(new StatusCommand()); | ||
$this->command = $this->app->find('status'); | ||
$this->tester = new CommandTester($this->command); | ||
} | ||
|
||
public function testNotEmptyOutput() { | ||
$this->tester->execute(array( | ||
'command' => $this->command->getName() | ||
)); | ||
|
||
$output = $this->tester->getDisplay(); | ||
$this->assertContains('Version', $output); | ||
$this->assertContains('ProcessWire', $output); | ||
$this->assertContains('*****', $output); | ||
} | ||
|
||
public function testImageDiagnostic() { | ||
$this->tester->execute(array( | ||
'command' => $this->command->getName(), | ||
'--image' => true | ||
)); | ||
|
||
$output = $this->tester->getDisplay(); | ||
$this->assertContains('Image Diagnostics', $output); | ||
} | ||
|
||
public function testPhpDiagnostic() { | ||
$this->tester->execute(array( | ||
'command' => $this->command->getName(), | ||
'--php' => true | ||
)); | ||
|
||
$output = $this->tester->getDisplay(); | ||
$this->assertContains('PHP Diagnostics', $output); | ||
} | ||
|
||
public function testDisplayPass() { | ||
$this->tester->execute(array( | ||
'command' => $this->command->getName(), | ||
'--pass' => true | ||
)); | ||
|
||
$output = $this->tester->getDisplay(); | ||
$this->assertNotContains('*****', $output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
require_once 'vendor/autoload.php'; | ||
|
||
if (file_exists(__DIR__.'/../../autoload.php')) { | ||
$loader = require __DIR__.'/../../autoload.php'; | ||
} else { | ||
$loader = require __DIR__.'/vendor/autoload.php'; | ||
} | ||
|
||
$loader->setPsr4('Wireshell\\Tests\\', __DIR__ . '/Tests'); | ||
|
||
return $loader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.