summaryrefslogtreecommitdiffstats
path: root/tests/InstallTest.php
diff options
context:
space:
mode:
authornashe <thomas@chauchefoin.fr>2017-07-16 17:18:50 +0200
committernashe <thomas@chauchefoin.fr>2017-07-16 17:18:50 +0200
commit40c0526f7465ba567ac984fe710d39c32803df46 (patch)
treeb6b5b20460a6799c0db3f33412376982c2ed6cf6 /tests/InstallTest.php
parent820f12e342a67f74a28bdb32857bba6b69ee94e9 (diff)
downloadplanet-40c0526f7465ba567ac984fe710d39c32803df46.tar
planet-40c0526f7465ba567ac984fe710d39c32803df46.tar.gz
planet-40c0526f7465ba567ac984fe710d39c32803df46.tar.bz2
planet-40c0526f7465ba567ac984fe710d39c32803df46.tar.xz
planet-40c0526f7465ba567ac984fe710d39c32803df46.zip
Add tests for the installer
Diffstat (limited to 'tests/InstallTest.php')
-rw-r--r--tests/InstallTest.php84
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/InstallTest.php b/tests/InstallTest.php
new file mode 100644
index 0000000..f37f28c
--- /dev/null
+++ b/tests/InstallTest.php
@@ -0,0 +1,84 @@
+<?php
+
+use PHPUnit\Framework\TestCase;
+use GuzzleHttp\Client;
+
+class InstallTest extends TestCase {
+
+ /** @var GuzzleHttp\Client */
+ protected $client = null;
+
+ public function setUp()
+ {
+ $this->client = new Client([
+ 'base_uri' => 'http://127.0.0.1:8081',
+ 'timeout' => 1,
+ ]);
+
+ $this->removeCustomFiles();
+ }
+
+ public function tearDown()
+ {
+ $this->removeCustomFiles();
+ }
+
+ protected function removeCustomFiles()
+ {
+ $toRemove = [
+ custom_path('config.yml'),
+ custom_path('people.opml'),
+ custom_path('people.opml.bak'),
+ custom_path('cache')
+ ];
+
+ foreach ($toRemove as $path) {
+ if (file_exists($path)) {
+ unlink($path);
+ }
+ }
+ }
+
+ public function test_index_page_tells_moonmoon_is_not_installed()
+ {
+ $res = $this->client->get('/index.php');
+ $this->assertEquals(200, $res->getStatusCode());
+ $this->assertContains('install moonmoon', (string) $res->getBody());
+ }
+
+ public function test_install_page_loads_without_error()
+ {
+ $res = $this->client->get('/install.php');
+ $this->assertEquals(200, $res->getStatusCode());
+ $this->assertContains('Administrator password', (string) $res->getBody());
+ }
+
+ /**
+ * Regression test, `people.opml` was created by requesting `/install.php`
+ * even if the site was not installed: `touch()` was called to see if
+ * the path was writable but the file was not removed.
+ */
+ public function test_get_install_page_should_not_create_custom_files()
+ {
+ $this->client->get('/install.php');
+ $this->assertFalse(file_exists(custom_path('people.opml')));
+ $this->assertFalse(file_exists(custom_path('config.yml')));
+ $this->assertFalse(file_exists(custom_path('inc/pwc.inc.php')));
+ }
+
+ public function test_install_button()
+ {
+ $data = [
+ 'url' => 'http://127.0.0.1:8081/',
+ 'title' => 'My website',
+ 'password' => 'admin',
+ 'locale' => 'en',
+ ];
+
+ $res = $this->client->request('POST', '/install.php', [
+ 'form_params' => $data
+ ]);
+ $this->assertEquals(200, $res->getStatusCode());
+ $this->assertContains('Your moonmoon is ready.', (string) $res->getBody());
+ }
+} \ No newline at end of file