Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Commit

Permalink
Merge branch 'release/1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabea David committed Feb 3, 2017
2 parents b0fa382 + ac7376b commit 28d02dd
Show file tree
Hide file tree
Showing 67 changed files with 7,576 additions and 4,719 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -8,4 +8,4 @@ insert_final_newline = true

[{*.php,*.json}]
indent_style = space
indent_size = 4
indent_size = 2
12 changes: 11 additions & 1 deletion .gitignore
@@ -1,2 +1,12 @@
# Composer
vendor
.DS_Store

# Binaries
composer.phar

# Tests
phpunit.xml

# Directories etc.
ProcessWire
Tests/processwire.zip
2 changes: 1 addition & 1 deletion README.md
@@ -1,7 +1,7 @@
# wireshell
**ProcessWire command-line companion**

Version 1.0.0, compatibility: ProcessWire 3.x
Version 1.0.1, compatibility: ProcessWire 3.x

A command-line interface for CMS/CMF [ProcessWire](https://processwire.com) based on the Symfony Console component.
Can be easily extended through ProcessWire's ability of being bootstrapped into other applications, its great [API](https://processwire.com/api/) and
Expand Down
48 changes: 48 additions & 0 deletions Tests/BaseTestCase.php
@@ -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']);
}

}
126 changes: 126 additions & 0 deletions Tests/Commands/Common/NewCommandTest.php
@@ -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);
}
}
58 changes: 58 additions & 0 deletions Tests/Commands/Common/StatusCommandTest.php
@@ -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);
}
}
10 changes: 7 additions & 3 deletions app/wireshell.php
Expand Up @@ -29,7 +29,9 @@
use Wireshell\Commands\Common\UpgradeCommand;
use Wireshell\Commands\Common\StatusCommand;
use Wireshell\Commands\Common\ServeCommand;
use Wireshell\Commands\Backup\BackupCommand;
use Wireshell\Commands\Common\CheatCommand;
use Wireshell\Commands\Common\DebugCommand;
use Wireshell\Commands\Backup\BackupDatabaseCommand;
use Wireshell\Commands\Backup\BackupImagesCommand;
use Wireshell\Commands\Page\PageCreateCommand;
use Wireshell\Commands\Page\PageListCommand;
Expand All @@ -44,7 +46,7 @@
require __DIR__.'/../vendor/autoload.php';
}

$app = new Application('wireshell - An extendable ProcessWire CLI', '1.0.0');
$app = new Application('wireshell - An extendable ProcessWire CLI', '1.0.1');

$app->add(new UserCreateCommand());
$app->add(new UserUpdateCommand());
Expand Down Expand Up @@ -73,7 +75,9 @@
$app->add(new UpgradeCommand(new \Symfony\Component\Filesystem\Filesystem()));
$app->add(new StatusCommand());
$app->add(new ServeCommand());
$app->add(new BackupCommand());
$app->add(new CheatCommand());
$app->add(new DebugCommand());
$app->add(new BackupDatabaseCommand());
$app->add(new BackupImagesCommand());
$app->add(new PageCreateCommand());
$app->add(new PageListCommand());
Expand Down
13 changes: 13 additions & 0 deletions autoload.php
@@ -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;
10 changes: 7 additions & 3 deletions composer.json
Expand Up @@ -13,7 +13,7 @@
"homepage": "http://harikt.com"
},
{
"name": "Bea Dav",
"name": "Bea David",
"homepage": "http://justonestep.de/"
},
{
Expand All @@ -33,10 +33,14 @@
"php": ">=5.4.0",
"symfony/console": "~2.0",
"rah/danpu": "~2.6",
"guzzlehttp/guzzle": "~4.0",
"guzzlehttp/guzzle": "~6.2",
"monolog/monolog": "~1.12",
"guzzlehttp/progress-subscriber": "~1.1",
"symfony/filesystem": "~2.5",
"raulfraile/distill": "~0.9,!=0.9.3,!=0.9.4"
},
"require-dev": {
"phpunit/phpunit": "5.6.*",
"ofbeaton/console-tester": "^1.1",
"whatthejeff/nyancat-phpunit-resultprinter": "~1.2"
}
}

0 comments on commit 28d02dd

Please sign in to comment.