Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Test update checker.
James Coleca1b6046f313
diff --git a/app/Handlers/Events/VersionCheckEventHandler.php b/app/Handlers/Events/VersionCheckEventHandler.phpindex 18d101c1cf..612af9f13b 100644--- a/app/Handlers/Events/VersionCheckEventHandler.php+++ b/app/Handlers/Events/VersionCheckEventHandler.php@@ -72,6 +72,8 @@ class VersionCheckEventHandlerreturn;}+ // actually check for update and inform the user.+}}\ No newline at end of filediff --git a/app/Http/Controllers/Admin/UpdateController.php b/app/Http/Controllers/Admin/UpdateController.phpindex df69858a75..d00a5ae311 100644--- a/app/Http/Controllers/Admin/UpdateController.php+++ b/app/Http/Controllers/Admin/UpdateController.php@@ -112,15 +112,15 @@ class UpdateController extends Controller$check = version_compare($current, $first->getTitle());FireflyConfig::set('last_update_check', time());} catch (FireflyException $e) {- Log::error(sprintf('Could not check for updates: %s', $e->getMessage()));+ Log::error(sprintf('Could not check for updates: %s', $e->getMessage())); // @codeCoverageIgnore}if ($check === -2) {- $string = strval(trans('firefly.update_check_error'));+ $string = strval(trans('firefly.update_check_error')); // @codeCoverageIgnore}if ($check === -1) {// there is a new FF version!- $string = strval(trans('firefly.update_new_version_alert', ['your_version' => $current, 'new_version' => $first->getTitle()]));+ $string = strval(trans('firefly.update_new_version_alert', ['your_version' => $current, 'new_version' => $first->getTitle(), 'date' => $first->getUpdated()->formatLocalized($this->monthAndDayFormat)]));}if ($check === 0) {// you are running the current version!diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.phpindex 74ea4fea3f..e079ca7c37 100644--- a/resources/lang/en_US/firefly.php+++ b/resources/lang/en_US/firefly.php@@ -153,7 +153,7 @@ return ['admin_update_check_now_title' => 'Check for updates now','admin_update_check_now_explain' => 'If you press the button, Firefly III will see if your current version is the latest.','check_for_updates_button' => 'Check now!',- 'update_new_version_alert' => 'A new version is available. You are running v:your_version, the latest version is v:new_version.',+ 'update_new_version_alert' => 'A new version is available. You are running v:your_version, the latest version is v:new_version which was released on :date.','update_current_version_alert' => 'You are running v:version, which is the latest available release.','update_newer_version_alert' => 'You are running v:your_version, which is newer than the latest release, v:new_version.','update_check_error' => 'An error occurred while checking for updates. Please view the log files.',diff --git a/tests/Feature/Controllers/Admin/UpdateControllerTest.php b/tests/Feature/Controllers/Admin/UpdateControllerTest.phpindex 7d05ff5ee8..68d0ab7843 100644--- a/tests/Feature/Controllers/Admin/UpdateControllerTest.php+++ b/tests/Feature/Controllers/Admin/UpdateControllerTest.php@@ -22,8 +22,10 @@ declare(strict_types=1);namespace Tests\Feature\Controllers\Admin;+use Carbon\Carbon;use FireflyConfig;use FireflyIII\Models\Configuration;+use FireflyIII\Services\Github\Object\Release;use FireflyIII\Services\Github\Request\UpdateRequest;use Tests\TestCase;@@ -70,6 +72,7 @@ class UpdateControllerTest extends TestCaseFireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);FireflyConfig::shouldReceive('set')->withArgs(['permission_update_check', 1])->once()->andReturn(new Configuration);+ FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', time()])->once()->andReturn(new Configuration);$this->be($this->user());$response = $this->post(route('admin.update-check.post'), ['check_for_updates' => 1]);$response->assertSessionHas('success');@@ -82,18 +85,79 @@ class UpdateControllerTest extends TestCase*/public function testUpdateCheck(){+ $falseConfig = new Configuration;+ $falseConfig->data = false;+ FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);+ FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', time()])->once()->andReturn(new Configuration);+ $version = config('firefly.version');$releases = [+ new Release(['id' => 'x', 'title' => $version . '.1', 'content' => '', 'updated' => new Carbon]),+ ];+ $updater = $this->mock(UpdateRequest::class);+ $updater->shouldReceive('call')->andReturnNull();+ $updater->shouldReceive('getReleases')->andReturn($releases);++ // expect a new release (because of .1)+ $this->be($this->user());+ $response = $this->post(route('admin.update-check.manual'));+ $response->assertStatus(200);+ $response->assertSee($version);+ $response->assertSee('which was released on');+ $response->assertSee($version . '.1');+ }+++ /**+ * @covers \FireflyIII\Http\Controllers\Admin\UpdateController::updateCheck+ */+ public function testUpdateCheckCurrent()+ {+ $falseConfig = new Configuration;+ $falseConfig->data = false;+ FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);+ FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', time()])->once()->andReturn(new Configuration);+ $version = config('firefly.version');+ $releases = [+ new Release(['id' => 'x', 'title' => $version, 'content' => '', 'updated' => new Carbon]),];- $updater = $this->mock(UpdateRequest::class);+ $updater = $this->mock(UpdateRequest::class);$updater->shouldReceive('call')->andReturnNull();- $updater->shouldReceive('getReleases')->andReturn(true);+ $updater->shouldReceive('getReleases')->andReturn($releases);++ // expect a new release (because of .1)+ $this->be($this->user());+ $response = $this->post(route('admin.update-check.manual'));+ $response->assertStatus(200);+ $response->assertSee($version);+ $response->assertSee('the latest available release');+ }++ /**+ * @covers \FireflyIII\Http\Controllers\Admin\UpdateController::updateCheck+ */+ public function testUpdateCheckNewer()+ {+ $falseConfig = new Configuration;+ $falseConfig->data = false;+ FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);+ FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', time()])->once()->andReturn(new Configuration);+ $version = config('firefly.version') . '-alpha';+ $releases = [+ new Release(['id' => 'x', 'title' => $version, 'content' => '', 'updated' => new Carbon]),+ ];+ $updater = $this->mock(UpdateRequest::class);+ $updater->shouldReceive('call')->andReturnNull();+ $updater->shouldReceive('getReleases')->andReturn($releases);+ // expect a new release (because of .1)$this->be($this->user());$response = $this->post(route('admin.update-check.manual'));$response->assertStatus(200);+ $response->assertSee($version);+ $response->assertSee('which is newer than the');}