diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ApplicationUtilsTest.php | 47 | ||||
-rw-r--r-- | tests/Updater/UpdaterTest.php | 45 | ||||
-rw-r--r-- | tests/config/ConfigJsonTest.php | 2 |
3 files changed, 86 insertions, 8 deletions
diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php index ad86e21c..ebdc365c 100644 --- a/tests/ApplicationUtilsTest.php +++ b/tests/ApplicationUtilsTest.php | |||
@@ -17,7 +17,7 @@ class FakeApplicationUtils extends ApplicationUtils | |||
17 | /** | 17 | /** |
18 | * Toggle HTTP requests, allow overriding the version code | 18 | * Toggle HTTP requests, allow overriding the version code |
19 | */ | 19 | */ |
20 | public static function getLatestGitVersionCode($url, $timeout=0) | 20 | public static function getVersion($url, $timeout=0) |
21 | { | 21 | { |
22 | return self::$VERSION_CODE; | 22 | return self::$VERSION_CODE; |
23 | } | 23 | } |
@@ -45,17 +45,27 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase | |||
45 | } | 45 | } |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Remove test version file if it exists | ||
49 | */ | ||
50 | public function tearDown() | ||
51 | { | ||
52 | if (is_file('sandbox/version.php')) { | ||
53 | unlink('sandbox/version.php'); | ||
54 | } | ||
55 | } | ||
56 | |||
57 | /** | ||
48 | * Retrieve the latest version code available on Git | 58 | * Retrieve the latest version code available on Git |
49 | * | 59 | * |
50 | * Expected format: Semantic Versioning - major.minor.patch | 60 | * Expected format: Semantic Versioning - major.minor.patch |
51 | */ | 61 | */ |
52 | public function testGetLatestGitVersionCode() | 62 | public function testGetVersionCode() |
53 | { | 63 | { |
54 | $testTimeout = 10; | 64 | $testTimeout = 10; |
55 | 65 | ||
56 | $this->assertEquals( | 66 | $this->assertEquals( |
57 | '0.5.4', | 67 | '0.5.4', |
58 | ApplicationUtils::getLatestGitVersionCode( | 68 | ApplicationUtils::getVersion( |
59 | 'https://raw.githubusercontent.com/shaarli/Shaarli/' | 69 | 'https://raw.githubusercontent.com/shaarli/Shaarli/' |
60 | .'v0.5.4/shaarli_version.php', | 70 | .'v0.5.4/shaarli_version.php', |
61 | $testTimeout | 71 | $testTimeout |
@@ -63,7 +73,7 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase | |||
63 | ); | 73 | ); |
64 | $this->assertRegExp( | 74 | $this->assertRegExp( |
65 | self::$versionPattern, | 75 | self::$versionPattern, |
66 | ApplicationUtils::getLatestGitVersionCode( | 76 | ApplicationUtils::getVersion( |
67 | 'https://raw.githubusercontent.com/shaarli/Shaarli/' | 77 | 'https://raw.githubusercontent.com/shaarli/Shaarli/' |
68 | .'master/shaarli_version.php', | 78 | .'master/shaarli_version.php', |
69 | $testTimeout | 79 | $testTimeout |
@@ -72,14 +82,26 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase | |||
72 | } | 82 | } |
73 | 83 | ||
74 | /** | 84 | /** |
75 | * Attempt to retrieve the latest version from an invalid URL | 85 | * Attempt to retrieve the latest version from an invalid File |
86 | */ | ||
87 | public function testGetVersionCodeFromFile() | ||
88 | { | ||
89 | file_put_contents('sandbox/version.php', '<?php /* 1.2.3 */ ?>'. PHP_EOL); | ||
90 | $this->assertEquals( | ||
91 | '1.2.3', | ||
92 | ApplicationUtils::getVersion('sandbox/version.php', 1) | ||
93 | ); | ||
94 | } | ||
95 | |||
96 | /** | ||
97 | * Attempt to retrieve the latest version from an invalid File | ||
76 | */ | 98 | */ |
77 | public function testGetLatestGitVersionCodeInvalidUrl() | 99 | public function testGetVersionCodeInvalidFile() |
78 | { | 100 | { |
79 | $oldlog = ini_get('error_log'); | 101 | $oldlog = ini_get('error_log'); |
80 | ini_set('error_log', '/dev/null'); | 102 | ini_set('error_log', '/dev/null'); |
81 | $this->assertFalse( | 103 | $this->assertFalse( |
82 | ApplicationUtils::getLatestGitVersionCode('htttp://null.io', 1) | 104 | ApplicationUtils::getVersion('idontexist', 1) |
83 | ); | 105 | ); |
84 | ini_set('error_log', $oldlog); | 106 | ini_set('error_log', $oldlog); |
85 | } | 107 | } |
@@ -332,4 +354,15 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase | |||
332 | ApplicationUtils::checkResourcePermissions($conf) | 354 | ApplicationUtils::checkResourcePermissions($conf) |
333 | ); | 355 | ); |
334 | } | 356 | } |
357 | |||
358 | /** | ||
359 | * Check update with 'dev' as curent version (master branch). | ||
360 | * It should always return false. | ||
361 | */ | ||
362 | public function testCheckUpdateDev() | ||
363 | { | ||
364 | $this->assertFalse( | ||
365 | ApplicationUtils::checkUpdate('dev', self::$testUpdateFile, 100, true, true) | ||
366 | ); | ||
367 | } | ||
335 | } | 368 | } |
diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index b522d616..11b6444a 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php | |||
@@ -615,4 +615,49 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; | |||
615 | $this->assertTrue($updater->updateMethodPiwikUrl()); | 615 | $this->assertTrue($updater->updateMethodPiwikUrl()); |
616 | $this->assertEquals($url, $this->conf->get('plugins.PIWIK_URL')); | 616 | $this->assertEquals($url, $this->conf->get('plugins.PIWIK_URL')); |
617 | } | 617 | } |
618 | |||
619 | /** | ||
620 | * Test updateMethodAtomDefault with show_atom set to false | ||
621 | * => update to true. | ||
622 | */ | ||
623 | public function testUpdateMethodAtomDefault() | ||
624 | { | ||
625 | $sandboxConf = 'sandbox/config'; | ||
626 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | ||
627 | $this->conf = new ConfigManager($sandboxConf); | ||
628 | $this->conf->set('feed.show_atom', false); | ||
629 | $updater = new Updater([], [], $this->conf, true); | ||
630 | $this->assertTrue($updater->updateMethodAtomDefault()); | ||
631 | $this->assertTrue($this->conf->get('feed.show_atom')); | ||
632 | // reload from file | ||
633 | $this->conf = new ConfigManager($sandboxConf); | ||
634 | $this->assertTrue($this->conf->get('feed.show_atom')); | ||
635 | } | ||
636 | /** | ||
637 | * Test updateMethodAtomDefault with show_atom not set. | ||
638 | * => nothing to do | ||
639 | */ | ||
640 | public function testUpdateMethodAtomDefaultNoExist() | ||
641 | { | ||
642 | $sandboxConf = 'sandbox/config'; | ||
643 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | ||
644 | $this->conf = new ConfigManager($sandboxConf); | ||
645 | $updater = new Updater([], [], $this->conf, true); | ||
646 | $this->assertTrue($updater->updateMethodAtomDefault()); | ||
647 | $this->assertTrue($this->conf->get('feed.show_atom')); | ||
648 | } | ||
649 | /** | ||
650 | * Test updateMethodAtomDefault with show_atom set to true. | ||
651 | * => nothing to do | ||
652 | */ | ||
653 | public function testUpdateMethodAtomDefaultAlreadyTrue() | ||
654 | { | ||
655 | $sandboxConf = 'sandbox/config'; | ||
656 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | ||
657 | $this->conf = new ConfigManager($sandboxConf); | ||
658 | $this->conf->set('feed.show_atom', true); | ||
659 | $updater = new Updater([], [], $this->conf, true); | ||
660 | $this->assertTrue($updater->updateMethodAtomDefault()); | ||
661 | $this->assertTrue($this->conf->get('feed.show_atom')); | ||
662 | } | ||
618 | } | 663 | } |
diff --git a/tests/config/ConfigJsonTest.php b/tests/config/ConfigJsonTest.php index 3527f83d..d237bc80 100644 --- a/tests/config/ConfigJsonTest.php +++ b/tests/config/ConfigJsonTest.php | |||
@@ -40,7 +40,7 @@ class ConfigJsonTest extends \PHPUnit_Framework_TestCase | |||
40 | * Read a non existent config file -> empty array. | 40 | * Read a non existent config file -> empty array. |
41 | * | 41 | * |
42 | * @expectedException \Exception | 42 | * @expectedException \Exception |
43 | * @expectedExceptionMessage An error occurred while parsing JSON file: error code #4 | 43 | * @expectedExceptionMessageRegExp /An error occurred while parsing JSON configuration file \([\w\/\.]+\): error code #4/ |
44 | */ | 44 | */ |
45 | public function testReadInvalidJson() | 45 | public function testReadInvalidJson() |
46 | { | 46 | { |