1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
<?php
require_once 'GuzzleHarness.php';
class InstallTest extends GuzzleHarness
{
public function setUp() : void
{
parent::setUp();
removeCustomFiles();
}
public function tearDown() : void
{
parent::tearDown();
removeCustomFiles();
}
public function test_index_page_tells_moonmoon_is_not_installed()
{
$res = $this->client->get('/index.php');
$this->assertEquals(200, $res->getStatusCode());
$this->assertStringContainsString('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->assertStringContainsString('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(config_path('people.opml')));
$this->assertFalse(file_exists(config_path('config.yml')));
$this->assertFalse(file_exists(config_path('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->assertStringContainsString('Your moonmoon is ready.', (string) $res->getBody());
}
public function testMigratePre10SetupAuto()
{
$this->assertEquals(false, PlanetConfig::isInstalledPre10Version(), "Planet is not installed /old config");
$this->assertEquals(false, PlanetConfig::isInstalled(), "Planet is not installed /new config");
$config = new PlanetConfig();
file_put_contents(custom_path('config.yml'), $config->toYaml());
OpmlManager::save(new Opml(), custom_path('people.opml'));
$this->assertEquals(true, PlanetConfig::isInstalledPre10Version(), "Planet is installed /old config");
$this->assertEquals(false, PlanetConfig::isInstalled(), "Planet is not installed /new config");
// explicitly migrate
$this->assertEquals(true, PlanetConfig::migratePre10Version(), "Migration succeeded");
$this->assertEquals(true, PlanetConfig::isInstalled(), "Planet is installed /new config");
$this->assertFileExists(custom_path('config.yml.bak'), "Backup config is kept");
$this->assertFileExists(custom_path('people.opml.bak'), "Backup OPML is kept");
}
public function testMigratePre10SetupIndex()
{
$this->assertEquals(false, PlanetConfig::isInstalledPre10Version(), "Planet is not installed /old config");
$this->assertEquals(false, PlanetConfig::isInstalled(), "Planet is not installed /new config");
$config = new PlanetConfig();
file_put_contents(custom_path('config.yml'), $config->toYaml());
OpmlManager::save(new Opml(), custom_path('people.opml'));
$this->assertEquals(true, PlanetConfig::isInstalledPre10Version(), "Planet is installed /old config");
$this->assertEquals(false, PlanetConfig::isInstalled(), "Planet is not installed /new config");
// call through web interface
$this->client->get('/');
$this->assertEquals(true, PlanetConfig::isInstalled(), "Planet is installed /new config");
$this->assertFileExists(custom_path('config.yml.bak'), "Backup config is kept");
$this->assertFileExists(custom_path('people.opml.bak'), "Backup OPML is kept");
}
public function testFetchPublicOPML()
{
$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->assertStringContainsString('Your moonmoon is ready.', (string) $res->getBody());
$res = $this->client->get('/opml/');
$this->assertEquals(200, $res->getStatusCode());
$this->assertXmlStringEqualsXmlFile(config_path('people.opml'), (string) $res->getBody());
}
}
|