Skip to content

Commit 6d52151

Browse files
committed
docs: This is not the commit message you are looking for
1 parent 13356ae commit 6d52151

File tree

82 files changed

+16130
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+16130
-0
lines changed

.editorconfig

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
5+
root = true
6+
7+
8+
[*]
9+
charset = utf-8
10+
end_of_line = lf
11+
indent_size = 2
12+
indent_style = space
13+
14+
[*.{php,inc,module,json}]
15+
indent_style = space
16+
trim_trailing_whitespace = false
17+
insert_final_newline = true
18+
19+
20+
[*.js]
21+
indent_style = space
22+
trim_trailing_whitespace = false
23+
insert_final_newline = true
24+
25+
26+
[*.{css,less,scss}]
27+
indent_style = space
28+
trim_trailing_whitespace = false
29+
insert_final_newline = true

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Composer
2+
vendor
3+
4+
# Binaries
5+
composer.phar
6+
7+
# Node modules
8+
node_modules
9+
10+
# Tests
11+
phpunit.xml
12+
13+
# Directories etc.
14+
ProcessWire
15+
Tests/processwire.zip
16+

LICENCE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) <year> <copyright holders>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

Tests/BaseTestCase.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php namespace Wirecli\Tests;
2+
3+
use GuzzleHttp\Client;
4+
use \PHPUnit\Framework\TestCase as TestCase;
5+
use Symfony\Component\Console\Application;
6+
use Symfony\Component\Filesystem\Filesystem;
7+
8+
abstract class BaseTestCase extends TestCase {
9+
10+
const INSTALLATION_FOLDER = 'ProcessWire';
11+
const INSTALLATION_ARCHIVE = 'Tests/processwire.zip';
12+
13+
/**
14+
* @var Filesystem
15+
*/
16+
public $fs;
17+
18+
/**
19+
* @var Application
20+
*/
21+
public $app = null;
22+
23+
public $tester = null;
24+
public $command = null;
25+
26+
public function __construct($name = null, array $data = [], $dataName = '') {
27+
parent::__construct($name, $data, $dataName);
28+
$this->fs = new Filesystem();
29+
$this->app = new Application();
30+
$this->app->setAutoExit(false);
31+
}
32+
33+
public function checkInstallation() {
34+
if ($this->fs->exists(self::INSTALLATION_FOLDER)) $this->fs->remove(self::INSTALLATION_FOLDER);
35+
36+
// if installation exists and zip file is older than 24h remove it
37+
if ($this->fs->exists(self::INSTALLATION_ARCHIVE) && (time() - filemtime(self::INSTALLATION_ARCHIVE)) > 86400) {
38+
$this->fs->remove(self::INSTALLATION_ARCHIVE);
39+
}
40+
41+
if (!$this->fs->exists(self::INSTALLATION_ARCHIVE)) $this->downloadArchive();
42+
}
43+
44+
public function downloadArchive() {
45+
$client = new Client();
46+
$client->request('GET', 'https://github.com/processwire/processwire/archive/master.zip', ['sink' => 'Tests/processwire.zip']);
47+
}
48+
49+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php namespace Wirecli\Tests\Commands\Common;
2+
3+
use Symfony\Component\Console\Tester\CommandTester;
4+
use Symfony\Component\Console\Question\Question;
5+
use Symfony\Component\Console\Input\InputInterface;
6+
use Symfony\Component\Console\Output\OutputInterface;
7+
use Symfony\Component\Console\Question\ConfirmationQuestion;
8+
use Ofbeaton\Console\Tester\UnhandledQuestionException;
9+
use Wirecli\Tests\BaseTestCase as Base;
10+
use Wirecli\Commands\Common\NewCommand;
11+
12+
class NewCommandTest extends Base {
13+
/**
14+
* @field array default config values
15+
*/
16+
protected $defaults = array(
17+
'--timezone' => 'Europe\Berlin',
18+
'--httpHosts' => 'wirecli.sek',
19+
'--username' => 'admin',
20+
'--userpass' => 'password',
21+
'--useremail' => '[email protected]'
22+
);
23+
24+
/**
25+
* @before
26+
*/
27+
public function setupCommand() {
28+
$this->app->add(new NewCommand());
29+
$this->command = $this->app->find('new');
30+
$this->tester = new CommandTester($this->command);
31+
32+
$credentials = array(
33+
'--dbUser' => $GLOBALS['DB_USER'],
34+
'--dbPass' => $GLOBALS['DB_PASSWD'],
35+
'--dbName' => $GLOBALS['DB_DBNAME']
36+
);
37+
38+
$this->extends = array(
39+
'command' => $this->command->getName(),
40+
'directory' => Base::INSTALLATION_FOLDER,
41+
);
42+
43+
$this->defaults = array_merge($this->defaults, $credentials, $this->extends);
44+
}
45+
46+
public function testDownload() {
47+
$this->checkInstallation();
48+
$options = array('--no-install' => true, '--src' => Base::INSTALLATION_ARCHIVE);
49+
$this->tester->execute(array_merge($this->defaults, $options));
50+
51+
$this->assertDirectoryExists(Base::INSTALLATION_FOLDER);
52+
$this->assertDirectoryExists(Base::INSTALLATION_FOLDER . '/wire');
53+
$this->assertDirectoryNotExists(Base::INSTALLATION_FOLDER . '/site');
54+
}
55+
56+
/**
57+
* @depends testDownload
58+
* @expectedException RuntimeException
59+
* @expectedExceptionMessageRegExp /(Database connection information did not work)./
60+
*/
61+
public function testInstallWrongPassword() {
62+
// check ProcessWire has not been installed yet
63+
if ($this->fs->exists(Base::INSTALLATION_FOLDER . '/site/config.php')) return;
64+
65+
// return the input you want to answer the question with
66+
$this->mockQuestionHelper($this->command, function($text, $order, Question $question) {
67+
if (strpos($text, 'database user name') !== false) return 'whatever';
68+
if (strpos($text, 'database password') !== false) return 'wrong';
69+
70+
throw new UnhandledQuestionException();
71+
});
72+
73+
$options = array(
74+
'--src' => Base::INSTALLATION_ARCHIVE,
75+
'--dbPass' => 'wrong'
76+
);
77+
78+
$this->tester->execute(array_merge($this->defaults, $options));
79+
}
80+
81+
/**
82+
* @depends testDownload
83+
* @expectedExceptionMessageRegExp /(enter a valid email address)/
84+
*/
85+
public function testInstallInvalidEmailAddress() {
86+
// check ProcessWire has not been installed yet
87+
if ($this->fs->exists(Base::INSTALLATION_FOLDER . '/site/config.php')) return;
88+
89+
// return the input you want to answer the question with
90+
$this->mockQuestionHelper($this->command, function($text, $order, Question $question) {
91+
if (strpos($text, 'admin email address') !== false) return 'whatever';
92+
93+
throw new UnhandledQuestionException();
94+
});
95+
96+
$options = array(
97+
'--src' => Base::INSTALLATION_ARCHIVE,
98+
'--useremail' => 'invalid'
99+
);
100+
101+
$this->tester->execute(array_merge($this->defaults, $options));
102+
}
103+
104+
/**
105+
* @depends testDownload
106+
*/
107+
public function testInstall() {
108+
// check ProcessWire has not been installed yet
109+
if ($this->fs->exists(Base::INSTALLATION_FOLDER . '/site/config.php')) return;
110+
111+
$this->tester->execute($this->defaults);
112+
$output = $this->tester->getDisplay();
113+
114+
$this->assertDirectoryExists(Base::INSTALLATION_FOLDER . '/site');
115+
$this->assertFileExists(Base::INSTALLATION_FOLDER . '/site/config.php');
116+
$this->assertContains('Congratulations, ProcessWire has been successfully installed.', $output);
117+
}
118+
119+
/**
120+
* @depends testInstall
121+
* @expectedExceptionMessageRegExp /(There is already a \')(.*)(\' project)/
122+
*/
123+
public function testIsInstalled() {
124+
$this->tester->execute($this->defaults);
125+
}
126+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php namespace Wirecli\Tests\Commands\Common;
2+
3+
use Symfony\Component\Console\Tester\CommandTester;
4+
use Wirecli\Tests\BaseTestCase as Base;
5+
use Wirecli\Commands\Common\StatusCommand;
6+
7+
class StatusCommandTest extends Base {
8+
9+
/**
10+
* @before
11+
*/
12+
public function setupCommand() {
13+
$this->app->add(new StatusCommand());
14+
$this->command = $this->app->find('status');
15+
$this->tester = new CommandTester($this->command);
16+
}
17+
18+
public function testNotEmptyOutput() {
19+
$this->tester->execute(array(
20+
'command' => $this->command->getName()
21+
));
22+
23+
$output = $this->tester->getDisplay();
24+
$this->assertContains('Version', $output);
25+
$this->assertContains('ProcessWire', $output);
26+
$this->assertContains('*****', $output);
27+
}
28+
29+
public function testImageDiagnostic() {
30+
$this->tester->execute(array(
31+
'command' => $this->command->getName(),
32+
'--image' => true
33+
));
34+
35+
$output = $this->tester->getDisplay();
36+
$this->assertContains('Image Diagnostics', $output);
37+
}
38+
39+
public function testPhpDiagnostic() {
40+
$this->tester->execute(array(
41+
'command' => $this->command->getName(),
42+
'--php' => true
43+
));
44+
45+
$output = $this->tester->getDisplay();
46+
$this->assertContains('PHP Diagnostics', $output);
47+
}
48+
49+
public function testDisplayPass() {
50+
$this->tester->execute(array(
51+
'command' => $this->command->getName(),
52+
'--pass' => true
53+
));
54+
55+
$output = $this->tester->getDisplay();
56+
$this->assertNotContains('*****', $output);
57+
}
58+
}

0 commit comments

Comments
 (0)