diff options
-rw-r--r-- | .gitignore | 9 | ||||
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | app/classes/PlanetConfig.php | 76 | ||||
-rw-r--r-- | app/helpers.php | 41 | ||||
-rw-r--r-- | phpcs.xml | 4 | ||||
-rw-r--r-- | phpunit.xml | 4 | ||||
-rwxr-xr-x | public/admin/administration.php (renamed from admin/administration.php) | 2 | ||||
-rw-r--r-- | public/admin/changepassword.php (renamed from admin/changepassword.php) | 0 | ||||
-rwxr-xr-x | public/admin/default.css (renamed from admin/default.css) | 0 | ||||
-rw-r--r-- | public/admin/img/button-add.png (renamed from admin/img/button-add.png) | bin | 244 -> 244 bytes | |||
-rw-r--r-- | public/admin/img/button-delete.png (renamed from admin/img/button-delete.png) | bin | 201 -> 201 bytes | |||
-rw-r--r-- | public/admin/img/button-h.png (renamed from admin/img/button-h.png) | bin | 212 -> 212 bytes | |||
-rw-r--r-- | public/admin/img/button.png (renamed from admin/img/button.png) | bin | 212 -> 212 bytes | |||
-rw-r--r-- | public/admin/img/h3.png (renamed from admin/img/h3.png) | bin | 212 -> 212 bytes | |||
-rw-r--r-- | public/admin/img/moonmoon.png (renamed from admin/img/moonmoon.png) | bin | 564 -> 564 bytes | |||
-rw-r--r-- | public/admin/img/nav-admin.png (renamed from admin/img/nav-admin.png) | bin | 1519 -> 1519 bytes | |||
-rw-r--r-- | public/admin/img/nav-feed.png (renamed from admin/img/nav-feed.png) | bin | 1090 -> 1090 bytes | |||
-rw-r--r-- | public/admin/inc/auth.inc.php (renamed from admin/inc/auth.inc.php) | 6 | ||||
-rwxr-xr-x | public/admin/index.php (renamed from admin/index.php) | 2 | ||||
-rwxr-xr-x | public/admin/login.php (renamed from admin/login.php) | 4 | ||||
-rw-r--r-- | public/admin/logout.php (renamed from admin/logout.php) | 2 | ||||
-rw-r--r-- | public/admin/purgecache.php (renamed from admin/purgecache.php) | 4 | ||||
-rwxr-xr-x | public/admin/subscriptions.php (renamed from admin/subscriptions.php) | 2 | ||||
-rwxr-xr-x | public/admin/template.php (renamed from admin/template.php) | 0 | ||||
-rw-r--r-- | public/atom.php | 4 | ||||
-rw-r--r-- | public/cron.php (renamed from cron.php) | 2 | ||||
-rw-r--r-- | public/custom/img/feed.png (renamed from custom/img/feed.png) | bin | 484 -> 484 bytes | |||
-rw-r--r-- | public/custom/img/moonmoon.png (renamed from custom/img/moonmoon.png) | bin | 73408 -> 73408 bytes | |||
-rw-r--r-- | public/custom/img/moonmoon@128w.png (renamed from custom/img/moonmoon@128w.png) | bin | 8671 -> 8671 bytes | |||
-rw-r--r-- | public/custom/img/moonmoon@256w.png (renamed from custom/img/moonmoon@256w.png) | bin | 24255 -> 24255 bytes | |||
-rw-r--r-- | public/custom/img/opml.png (renamed from custom/img/opml.png) | bin | 31542 -> 31542 bytes | |||
-rw-r--r-- | public/custom/style/dark.css (renamed from custom/style/dark.css) | 0 | ||||
-rw-r--r-- | public/custom/style/default.css (renamed from custom/style/default.css) | 0 | ||||
-rw-r--r-- | public/custom/style/green.css (renamed from custom/style/green.css) | 0 | ||||
-rw-r--r-- | public/custom/style/light.css (renamed from custom/style/light.css) | 0 | ||||
-rw-r--r-- | public/custom/style/mobile.css (renamed from custom/style/mobile.css) | 0 | ||||
-rw-r--r-- | public/feed/index.php (renamed from atom.php) | 8 | ||||
-rwxr-xr-x | public/index.php (renamed from index.php) | 8 | ||||
-rwxr-xr-x | public/install.php (renamed from install.php) | 28 | ||||
-rw-r--r-- | public/postload.php (renamed from postload.php) | 4 | ||||
-rw-r--r-- | tests/InstallTest.php | 47 |
41 files changed, 203 insertions, 66 deletions
@@ -1,15 +1,16 @@ +.DS_Store +.idea +.phpunit.* /cache /custom/config.yml /custom/people.opml /custom/people.opml.bak +/custom/config /admin/inc/pwd.inc.php /vendor/ /tests/_output/* /nbproject/private/ -/.idea/ tmp/ - -.phpunit.result.cache - +public/tests @@ -3,11 +3,13 @@ VENDOR=./vendor/bin/ PHPUNIT=php -dxdebug.enabled=1 -dxdebug.mode=coverage ./vendor/bin/phpunit --coverage-text test: - { php -S 127.0.0.1:8081 >& /dev/null & }; \ + rm -f public/tests && ln -s ../tests public/tests + { php -S 127.0.0.1:8081 -t public/ >& /dev/null & }; \ PID=$$!; \ $(PHPUNIT); \ RES=$$?; \ kill $$PID; \ + rm public/tests exit $$RES fmt: @@ -24,9 +26,13 @@ stan: report: $(VENDOR)phpmd \ - admin,app,custom,docs,tests,atom.php,cron.php,index.php,install.php,postload.php \ + app,custom,docs,tests,public \ html \ cleancode,codesize,controversial,design,naming,unusedcode > tmp/report.html serve: - php -S localhost:5555 -t . + php -S localhost:5555 -t public/ + +clean: + rm -fr ./cache/* + rm -fr ./custom/config/*
\ No newline at end of file diff --git a/app/classes/PlanetConfig.php b/app/classes/PlanetConfig.php index b8233e0..6094956 100644 --- a/app/classes/PlanetConfig.php +++ b/app/classes/PlanetConfig.php @@ -41,23 +41,31 @@ class PlanetConfig public static function load(string $dir) { $config = new PlanetConfig; - $configFile = realpath($dir . '/../custom/config.yml'); - if (self::isInstalled()) { - $conf = Spyc::YAMLLoad($configFile); - - // this is a check to upgrade older config file without l10n - if (!isset($conf['locale'])) { - $resetPlanetConfig = new PlanetConfig($conf); - file_put_contents($configFile, $resetPlanetConfig->toYaml()); - $conf = Spyc::YAMLLoad($configFile); + if (!self::isInstalled()) { + if (!self::isInstalledPre10Version()) { + return $config; + } - return $resetPlanetConfig; + if (!self::migratePre10Version()) { + error_log('Failed to migrate configuration.'); + return $config; } + } - $config = new PlanetConfig($conf); + $configFile = realpath(config_path('config.yml')); + $conf = Spyc::YAMLLoad($configFile); + + // this is a check to upgrade older config file without l10n + if (!isset($conf['locale'])) { + $resetPlanetConfig = new PlanetConfig($conf); + file_put_contents($configFile, $resetPlanetConfig->toYaml()); + $conf = Spyc::YAMLLoad($configFile); + return $resetPlanetConfig; } + $config = new PlanetConfig($conf); + return $config; } @@ -68,11 +76,55 @@ class PlanetConfig */ public static function isInstalled() : bool { + return file_exists(config_path('config.yml')) && + file_exists(config_path('people.opml')); + } + + /** + * Or is it a pre-10 version installed? + * (that is, config is stored in custom/config.yml instead of custom/config/config.yml) + */ + public static function isInstalledPre10Version(): bool + { return file_exists(custom_path('config.yml')) && file_exists(custom_path('people.opml')); } /** + * Migrate config files from old to new location. + * Purge cache. + * + * @return bool true if succeeded, false otherwise + */ + public static function migratePre10Version() : bool + { + if (!is_dir(config_path())) { + if (!mkdir(config_path(), 0777, true)) { + return false; + } + } + + return self::migrate_file('config.yml') && + self::migrate_file('people.opml'); + } + + public static function migrate_file($file) : bool + { + $source = custom_path($file); + $dest = config_path($file); + if (!copy($source, $source . '.bak')) { + error_log("Failed to make a backup of ${source}"); + return false; + } + if (!rename($source, $dest)) { + error_log("Failed to move ${source} to ${dest}"); + return false; + } + + return true; + } + + /** * Merge the configuration of the user in the default one. * * @param array $default @@ -115,7 +167,7 @@ class PlanetConfig public function getOpmlFile() { if (is_null($this->opmlFile)) { - $this->opmlFile = realpath(__DIR__ . '/../../custom/people.opml'); + $this->opmlFile = realpath(config_path('people.opml')); } return $this->opmlFile; } diff --git a/app/helpers.php b/app/helpers.php index a7e68ae..24f9d38 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -18,8 +18,9 @@ register_polyfills(); * * @param string $file Append this filename to the returned path. * @return string + * @deprecated */ -function custom_path($file = '') +function custom_path($file = '') : string { return __DIR__.'/../custom' . (!empty($file) ? '/'.$file : ''); } @@ -29,8 +30,9 @@ function custom_path($file = '') * * @param string $file Append this filename to the returned path. * @return string + * @deprecated */ -function views_path($file = '') +function views_path($file = '') : string { return custom_path('views/' . $file); } @@ -40,13 +42,38 @@ function views_path($file = '') * * @param string $file Append this filename to the returned path. * @return string + * @deprecated */ -function admin_path($file = '') +function admin_path($file = '') : string { return __DIR__.'/../admin' . (!empty($file) ? '/'.$file : ''); } /** + * Path to the _config_ directory. + * + * @param string $file Append this filename to the returned path + * @param string $site Append this site as a sub-directory before the file + * @return string + */ +function config_path($file = '', $site = '') : string +{ + $path = __DIR__ . '/../custom/config'; + if (!empty($site)) { + $path .= '/' . $site; + } + if (!empty($file)) { + $path .= '/' . $file; + } + return $path; +} + +function cache_path($site = '') : string +{ + return __DIR__ . '/../cache'; +} + +/** * Shortcut to Simplel10n::getString(). * * @param string $str @@ -64,10 +91,16 @@ function _g($str, $comment = '') function removeCustomFiles() { $toRemove = [ + config_path('config.yml'), + config_path('people.opml'), + config_path('people.opml.bak'), + cache_path('cache'), + + // legacy location custom_path('config.yml'), + custom_path('config.yml.bak'), custom_path('people.opml'), custom_path('people.opml.bak'), - custom_path('cache') ]; foreach ($toRemove as $path) { @@ -5,7 +5,9 @@ <file>.</file> <arg value="np"/> <arg name="colors"/> - <arg name="extensions" value="php,inc"/> + <arg name="extensions" value="php"/> <arg name="encoding" value="utf8"/> + <exclude-pattern>cache/</exclude-pattern> + <exclude-pattern>tmp/</exclude-pattern> <exclude-pattern>vendor/</exclude-pattern> </ruleset>
\ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index 8d463d4..2a0713a 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -17,7 +17,9 @@ <coverage processUncoveredFiles="false"> <include> - <directory suffix=".php">.</directory> + <directory suffix=".php">app</directory> + <directory suffix=".php">public</directory> + <directory suffix=".php">custom/views</directory> </include> <exclude> <directory>vendor</directory> diff --git a/admin/administration.php b/public/admin/administration.php index e6236fd..09b5f85 100755 --- a/admin/administration.php +++ b/public/admin/administration.php @@ -1,6 +1,6 @@ <?php -require_once __DIR__ . '/../app/app.php'; +require_once __DIR__ . '/../../app/app.php'; require_once __DIR__ . '/inc/auth.inc.php'; diff --git a/admin/changepassword.php b/public/admin/changepassword.php index c1e61ff..c1e61ff 100644 --- a/admin/changepassword.php +++ b/public/admin/changepassword.php diff --git a/admin/default.css b/public/admin/default.css index fcba3f4..fcba3f4 100755 --- a/admin/default.css +++ b/public/admin/default.css diff --git a/admin/img/button-add.png b/public/admin/img/button-add.png Binary files differindex 859364a..859364a 100644 --- a/admin/img/button-add.png +++ b/public/admin/img/button-add.png diff --git a/admin/img/button-delete.png b/public/admin/img/button-delete.png Binary files differindex 7bfebc2..7bfebc2 100644 --- a/admin/img/button-delete.png +++ b/public/admin/img/button-delete.png diff --git a/admin/img/button-h.png b/public/admin/img/button-h.png Binary files differindex 0a43a6a..0a43a6a 100644 --- a/admin/img/button-h.png +++ b/public/admin/img/button-h.png diff --git a/admin/img/button.png b/public/admin/img/button.png Binary files differindex fad6ccc..fad6ccc 100644 --- a/admin/img/button.png +++ b/public/admin/img/button.png diff --git a/admin/img/h3.png b/public/admin/img/h3.png Binary files differindex 0c86748..0c86748 100644 --- a/admin/img/h3.png +++ b/public/admin/img/h3.png diff --git a/admin/img/moonmoon.png b/public/admin/img/moonmoon.png Binary files differindex 26cc8f4..26cc8f4 100644 --- a/admin/img/moonmoon.png +++ b/public/admin/img/moonmoon.png diff --git a/admin/img/nav-admin.png b/public/admin/img/nav-admin.png Binary files differindex 3077a54..3077a54 100644 --- a/admin/img/nav-admin.png +++ b/public/admin/img/nav-admin.png diff --git a/admin/img/nav-feed.png b/public/admin/img/nav-feed.png Binary files differindex 00c896b..00c896b 100644 --- a/admin/img/nav-feed.png +++ b/public/admin/img/nav-feed.png diff --git a/admin/inc/auth.inc.php b/public/admin/inc/auth.inc.php index 0305b13..32615e7 100644 --- a/admin/inc/auth.inc.php +++ b/public/admin/inc/auth.inc.php @@ -1,10 +1,6 @@ <?php -include dirname(__FILE__).'/pwd.inc.php'; - -if (!class_exists('Planet')) { - require __DIR__.'/../../vendor/autoload.php'; -} +include config_path('pwd.inc.php'); if (!Planet::authenticateUser($_COOKIE['auth'] ?? '', $password)) { setcookie('auth', '', time() - 3600); diff --git a/admin/index.php b/public/admin/index.php index 76ebb25..37939ea 100755 --- a/admin/index.php +++ b/public/admin/index.php @@ -1,6 +1,6 @@ <?php -require_once __DIR__ . '/../app/app.php'; +require_once __DIR__ . '/../../app/app.php'; require_once __DIR__ . '/inc/auth.inc.php'; if (!$PlanetConfig::isInstalled()) { diff --git a/admin/login.php b/public/admin/login.php index 2f3d977..418bbe6 100755 --- a/admin/login.php +++ b/public/admin/login.php @@ -1,6 +1,6 @@ <?php -require_once __DIR__ . '/../app/app.php'; +require_once __DIR__ . '/../../app/app.php'; if (isset($_POST['password'])) { session_regenerate_id(); @@ -10,7 +10,7 @@ if (isset($_POST['password'])) { // check if old moonmoon was installed and convert stored password // from md5 to current hash function $md5_pwd = md5($_POST['password']); - $passfile = dirname(__FILE__) . '/inc/pwd.inc.php'; + $passfile = config_path('pwd.inc.php'); include($passfile); if ($md5_pwd == $password) { diff --git a/admin/logout.php b/public/admin/logout.php index 88c60b3..25a3e4c 100644 --- a/admin/logout.php +++ b/public/admin/logout.php @@ -1,6 +1,6 @@ <?php -require_once __DIR__ . '/../app/app.php'; +require_once __DIR__ . '/../../app/app.php'; setcookie('auth', '', time() - 3600); session_destroy(); diff --git a/admin/purgecache.php b/public/admin/purgecache.php index b020758..d47f9a7 100644 --- a/admin/purgecache.php +++ b/public/admin/purgecache.php @@ -1,10 +1,10 @@ <?php -require_once __DIR__.'/../app/app.php'; +require_once __DIR__.'/../../app/app.php'; require_once __DIR__.'/inc/auth.inc.php'; if (isset($_POST['purge'])) { - $dir = __DIR__.'/../cache/'; + $dir = __DIR__.'/../../cache/'; $dh = opendir($dir); diff --git a/admin/subscriptions.php b/public/admin/subscriptions.php index 2e07f17..418e354 100755 --- a/admin/subscriptions.php +++ b/public/admin/subscriptions.php @@ -1,6 +1,6 @@ <?php -require_once __DIR__ . '/../app/app.php'; +require_once __DIR__ . '/../../app/app.php'; require_once __DIR__ . '/inc/auth.inc.php'; function removeSlashes(&$item, $key) diff --git a/admin/template.php b/public/admin/template.php index 964c639..964c639 100755 --- a/admin/template.php +++ b/public/admin/template.php diff --git a/public/atom.php b/public/atom.php new file mode 100644 index 0000000..26abeb6 --- /dev/null +++ b/public/atom.php @@ -0,0 +1,4 @@ +<?php +header('Status: 301 Moved Permanently', false, 301); +header('Location: feed/'); +exit; diff --git a/cron.php b/public/cron.php index 688bebe..ef5cdaa 100644 --- a/cron.php +++ b/public/cron.php @@ -1,5 +1,5 @@ <?php -include_once(__DIR__.'/app/app.php'); +require_once '../app/app.php'; //Load OPML if (0 < $Planet->loadOpml($PlanetConfig->getOpmlFile())) { diff --git a/custom/img/feed.png b/public/custom/img/feed.png Binary files differindex f8cd243..f8cd243 100644 --- a/custom/img/feed.png +++ b/public/custom/img/feed.png diff --git a/custom/img/moonmoon.png b/public/custom/img/moonmoon.png Binary files differindex 10f9736..10f9736 100644 --- a/custom/img/moonmoon.png +++ b/public/custom/img/moonmoon.png diff --git a/custom/img/moonmoon@128w.png b/public/custom/img/moonmoon@128w.png Binary files differindex 2a164aa..2a164aa 100644 --- a/custom/img/moonmoon@128w.png +++ b/public/custom/img/moonmoon@128w.png diff --git a/custom/img/moonmoon@256w.png b/public/custom/img/moonmoon@256w.png Binary files differindex b52c4bb..b52c4bb 100644 --- a/custom/img/moonmoon@256w.png +++ b/public/custom/img/moonmoon@256w.png diff --git a/custom/img/opml.png b/public/custom/img/opml.png Binary files differindex 7a9d86f..7a9d86f 100644 --- a/custom/img/opml.png +++ b/public/custom/img/opml.png diff --git a/custom/style/dark.css b/public/custom/style/dark.css index 1ee004b..1ee004b 100644 --- a/custom/style/dark.css +++ b/public/custom/style/dark.css diff --git a/custom/style/default.css b/public/custom/style/default.css index 12268ef..12268ef 100644 --- a/custom/style/default.css +++ b/public/custom/style/default.css diff --git a/custom/style/green.css b/public/custom/style/green.css index d665bd8..d665bd8 100644 --- a/custom/style/green.css +++ b/public/custom/style/green.css diff --git a/custom/style/light.css b/public/custom/style/light.css index 60826e4..60826e4 100644 --- a/custom/style/light.css +++ b/public/custom/style/light.css diff --git a/custom/style/mobile.css b/public/custom/style/mobile.css index 38b3cd2..38b3cd2 100644 --- a/custom/style/mobile.css +++ b/public/custom/style/mobile.css diff --git a/atom.php b/public/feed/index.php index ddeebc0..90ce907 100644 --- a/atom.php +++ b/public/feed/index.php @@ -1,8 +1,10 @@ <?php -include_once(__DIR__.'/app/app.php'); -include_once(__DIR__.'/app/classes/Cache.php'); +require_once '../../app/app.php'; +require_once '../../app/classes/Cache.php'; if ($Planet->loadOpml($PlanetConfig->getOpmlFile()) == 0) { + header('Content-Type: text/xml; charset=utf-8'); + header('HTTP/1.1 404 Not Found'); exit; } @@ -18,7 +20,7 @@ echo '<?xml version="1.0" encoding="UTF-8" ?>'; <title><?=htmlspecialchars($PlanetConfig->getName())?></title> <subtitle><?=htmlspecialchars($PlanetConfig->getName())?></subtitle> <id><?=$PlanetConfig->getUrl()?></id> - <link rel="self" type="application/atom+xml" href="<?=$PlanetConfig->getUrl()?>atom.php" /> + <link rel="self" type="application/atom+xml" href="<?=$PlanetConfig->getUrl()?>feed/" /> <link rel="alternate" type="text/html" href="<?=$PlanetConfig->getUrl()?>" /> <updated><?=gmdate('Y-m-d\TH:i:s\Z')?></updated> <author><name><?=htmlspecialchars($PlanetConfig->getName())?></name></author> diff --git a/index.php b/public/index.php index 0d149bd..0a0de38 100755 --- a/index.php +++ b/public/index.php @@ -1,6 +1,6 @@ <?php -include_once(__DIR__.'/app/app.php'); -include_once(__DIR__.'/app/classes/Cache.php'); +require_once '../app/app.php'; +require_once '../app/classes/Cache.php'; if (!$PlanetConfig::isInstalled()) { die('<p>' . _g('You might want to <a href="install.php">install moonmoon</a>.') . '</p>'); @@ -18,7 +18,7 @@ if ($pageRole == 'atom10') { * Remove this check in a more distant future. */ header('Status: 301 Moved Permanently', false, 301); - header('Location: atom.php'); + header('Location: feed/'); exit; } @@ -29,7 +29,7 @@ Cache::setStore($PlanetConfig->getCacheDir() . '/'); if (!OutputCache::Start('html', $pageRole, $cache_duration)) { $items = $Planet->getFeedsItems(); $last_modified = (count($items)) ? $items[0]->get_date() : ''; - include_once(__DIR__.'/custom/views/'.$pageTheme.'/'.$pageRole.'.tpl.php'); + include_once '../custom/views/'.$pageTheme.'/'.$pageRole.'.tpl.php'; OutputCache::End(); } diff --git a/install.php b/public/install.php index 5aaaef9..09cbe63 100755 --- a/install.php +++ b/public/install.php @@ -1,9 +1,8 @@ <?php - -require_once __DIR__ . '/app/app.php'; +require_once '../app/app.php'; // This is an helper function returning an html table row to avoid code duplication -function installStatus($str, $msg, $result) +function installStatus(string $str, string $msg, bool $result) : string { $class = ($result) ? 'ok' : 'fail'; return '<tr><td>' . $str . '</td><td class="' . $class . '">' . $msg . '</td></tr>'; @@ -28,13 +27,13 @@ if ($PlanetConfig::isInstalled()) { ]); $CreatePlanetConfig = new PlanetConfig($config); - $save['config'] = file_put_contents(custom_path('config.yml'), $CreatePlanetConfig->toYaml()); + $save['config'] = file_put_contents(config_path('config.yml'), $CreatePlanetConfig->toYaml()); - OpmlManager::save(new Opml(), custom_path('people.opml')); + OpmlManager::save(new Opml(), config_path('people.opml')); //Save password $save['password'] = file_put_contents( - admin_path('inc/pwd.inc.php'), + config_path('pwd.inc.php'), sprintf('<?php $login="admin"; $password="%s"; ?>', hash('sha256', $_POST['password'])) ); @@ -73,23 +72,22 @@ if ($PlanetConfig::isInstalled()) { // Writable file requirements $tests = array( - '/custom', - '/custom/people.opml', - '/admin/inc/pwd.inc.php', - '/cache', + config_path('config.yml'), + config_path('people.opml'), + config_path('pwd.inc.php'), + cache_path('test_cache'), ); // We now test that all required files and directories are writable. - foreach ($tests as $v) { - $filename = __DIR__ . $v; + foreach ($tests as $filename) { if (touch($filename)) { - $strInstall .= installStatus("<code>$v</code> is writable", 'OK', true); + $strInstall .= installStatus("<code>$filename</code> is writable", 'OK', true); if (is_file($filename)) { unlink($filename); } } else { - $strInstall .= installStatus("<code>$v</code> is writable", 'FAIL', false); - $strRecommendation .= "<li>Make <code>$v</code> writable with CHMOD</li>"; + $strInstall .= installStatus("<code>$filename</code> is writable", 'FAIL', false); + $strRecommendation .= "<li>Make <code>$filename</code> writable with CHMOD</li>"; } } diff --git a/postload.php b/public/postload.php index 0dff886..69d6571 100644 --- a/postload.php +++ b/public/postload.php @@ -1,6 +1,6 @@ <?php -require_once __DIR__.'/app/app.php'; +require_once '../app/app.php'; if (!$PlanetConfig::isInstalled()) { die(); @@ -20,7 +20,7 @@ foreach ($xml->xpath('/opml/body/outline[@xmlUrl]') as $element) { $Planet->download(1); header('Content-type: image/png'); - readfile(custom_path('img/feed.png')); + readfile(__DIR__ . '/custom/img/feed.png'); die(); } } diff --git a/tests/InstallTest.php b/tests/InstallTest.php index b230d74..5433c56 100644 --- a/tests/InstallTest.php +++ b/tests/InstallTest.php @@ -39,9 +39,9 @@ class InstallTest extends GuzzleHarness 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'))); + $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() @@ -59,4 +59,45 @@ class InstallTest extends GuzzleHarness $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"); + } } |