aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ApplicationUtilsTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ApplicationUtilsTest.php')
-rw-r--r--tests/ApplicationUtilsTest.php55
1 files changed, 46 insertions, 9 deletions
diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php
index 4a0975bf..ff4c9e17 100644
--- a/tests/ApplicationUtilsTest.php
+++ b/tests/ApplicationUtilsTest.php
@@ -1,9 +1,10 @@
1<?php 1<?php
2use Shaarli\Config\ConfigManager;
3
2/** 4/**
3 * ApplicationUtils' tests 5 * ApplicationUtils' tests
4 */ 6 */
5 7
6require_once 'application/config/ConfigManager.php';
7require_once 'application/ApplicationUtils.php'; 8require_once 'application/ApplicationUtils.php';
8 9
9/** 10/**
@@ -16,7 +17,7 @@ class FakeApplicationUtils extends ApplicationUtils
16 /** 17 /**
17 * Toggle HTTP requests, allow overriding the version code 18 * Toggle HTTP requests, allow overriding the version code
18 */ 19 */
19 public static function getLatestGitVersionCode($url, $timeout=0) 20 public static function getVersion($url, $timeout=0)
20 { 21 {
21 return self::$VERSION_CODE; 22 return self::$VERSION_CODE;
22 } 23 }
@@ -44,17 +45,27 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
44 } 45 }
45 46
46 /** 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 /**
47 * Retrieve the latest version code available on Git 58 * Retrieve the latest version code available on Git
48 * 59 *
49 * Expected format: Semantic Versioning - major.minor.patch 60 * Expected format: Semantic Versioning - major.minor.patch
50 */ 61 */
51 public function testGetLatestGitVersionCode() 62 public function testGetVersionCode()
52 { 63 {
53 $testTimeout = 10; 64 $testTimeout = 10;
54 65
55 $this->assertEquals( 66 $this->assertEquals(
56 '0.5.4', 67 '0.5.4',
57 ApplicationUtils::getLatestGitVersionCode( 68 ApplicationUtils::getVersion(
58 'https://raw.githubusercontent.com/shaarli/Shaarli/' 69 'https://raw.githubusercontent.com/shaarli/Shaarli/'
59 .'v0.5.4/shaarli_version.php', 70 .'v0.5.4/shaarli_version.php',
60 $testTimeout 71 $testTimeout
@@ -62,23 +73,35 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
62 ); 73 );
63 $this->assertRegExp( 74 $this->assertRegExp(
64 self::$versionPattern, 75 self::$versionPattern,
65 ApplicationUtils::getLatestGitVersionCode( 76 ApplicationUtils::getVersion(
66 'https://raw.githubusercontent.com/shaarli/Shaarli/' 77 'https://raw.githubusercontent.com/shaarli/Shaarli/'
67 .'stable/shaarli_version.php', 78 .'latest/shaarli_version.php',
68 $testTimeout 79 $testTimeout
69 ) 80 )
70 ); 81 );
71 } 82 }
72 83
73 /** 84 /**
74 * Attempt to retrieve the latest version from an invalid URL 85 * Attempt to retrieve the latest version from an invalid File
75 */ 86 */
76 public function testGetLatestGitVersionCodeInvalidUrl() 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
98 */
99 public function testGetVersionCodeInvalidFile()
77 { 100 {
78 $oldlog = ini_get('error_log'); 101 $oldlog = ini_get('error_log');
79 ini_set('error_log', '/dev/null'); 102 ini_set('error_log', '/dev/null');
80 $this->assertFalse( 103 $this->assertFalse(
81 ApplicationUtils::getLatestGitVersionCode('htttp://null.io', 1) 104 ApplicationUtils::getVersion('idontexist', 1)
82 ); 105 );
83 ini_set('error_log', $oldlog); 106 ini_set('error_log', $oldlog);
84 } 107 }
@@ -289,6 +312,7 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
289 $conf->set('resource.page_cache', 'pagecache'); 312 $conf->set('resource.page_cache', 'pagecache');
290 $conf->set('resource.raintpl_tmp', 'tmp'); 313 $conf->set('resource.raintpl_tmp', 'tmp');
291 $conf->set('resource.raintpl_tpl', 'tpl'); 314 $conf->set('resource.raintpl_tpl', 'tpl');
315 $conf->set('resource.theme', 'default');
292 $conf->set('resource.update_check', 'data/lastupdatecheck.txt'); 316 $conf->set('resource.update_check', 'data/lastupdatecheck.txt');
293 317
294 $this->assertEquals( 318 $this->assertEquals(
@@ -312,10 +336,12 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
312 $conf->set('resource.page_cache', 'null/pagecache'); 336 $conf->set('resource.page_cache', 'null/pagecache');
313 $conf->set('resource.raintpl_tmp', 'null/tmp'); 337 $conf->set('resource.raintpl_tmp', 'null/tmp');
314 $conf->set('resource.raintpl_tpl', 'null/tpl'); 338 $conf->set('resource.raintpl_tpl', 'null/tpl');
339 $conf->set('resource.raintpl_theme', 'null/tpl/default');
315 $conf->set('resource.update_check', 'null/data/lastupdatecheck.txt'); 340 $conf->set('resource.update_check', 'null/data/lastupdatecheck.txt');
316 $this->assertEquals( 341 $this->assertEquals(
317 array( 342 array(
318 '"null/tpl" directory is not readable', 343 '"null/tpl" directory is not readable',
344 '"null/tpl/default" directory is not readable',
319 '"null/cache" directory is not readable', 345 '"null/cache" directory is not readable',
320 '"null/cache" directory is not writable', 346 '"null/cache" directory is not writable',
321 '"null/data" directory is not readable', 347 '"null/data" directory is not readable',
@@ -328,4 +354,15 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
328 ApplicationUtils::checkResourcePermissions($conf) 354 ApplicationUtils::checkResourcePermissions($conf)
329 ); 355 );
330 } 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 }
331} 368}