Test update checker.

This commit is contained in:
James Cole
2017-12-28 19:16:27 +01:00
parent 128085963f
commit ca1b6046f3
4 changed files with 74 additions and 8 deletions

View File

@@ -72,6 +72,8 @@ class VersionCheckEventHandler
return; return;
} }
// actually check for update and inform the user.
} }
} }

View File

@@ -112,15 +112,15 @@ class UpdateController extends Controller
$check = version_compare($current, $first->getTitle()); $check = version_compare($current, $first->getTitle());
FireflyConfig::set('last_update_check', time()); FireflyConfig::set('last_update_check', time());
} catch (FireflyException $e) { } 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) { if ($check === -2) {
$string = strval(trans('firefly.update_check_error')); $string = strval(trans('firefly.update_check_error')); // @codeCoverageIgnore
} }
if ($check === -1) { if ($check === -1) {
// there is a new FF version! // 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) { if ($check === 0) {
// you are running the current version! // you are running the current version!

View File

@@ -153,7 +153,7 @@ return [
'admin_update_check_now_title' => 'Check for updates now', '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.', '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!', '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_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_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.', 'update_check_error' => 'An error occurred while checking for updates. Please view the log files.',

View File

@@ -22,8 +22,10 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Admin; namespace Tests\Feature\Controllers\Admin;
use Carbon\Carbon;
use FireflyConfig; use FireflyConfig;
use FireflyIII\Models\Configuration; use FireflyIII\Models\Configuration;
use FireflyIII\Services\Github\Object\Release;
use FireflyIII\Services\Github\Request\UpdateRequest; use FireflyIII\Services\Github\Request\UpdateRequest;
use Tests\TestCase; use Tests\TestCase;
@@ -70,6 +72,7 @@ class UpdateControllerTest extends TestCase
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig); FireflyConfig::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(['permission_update_check', 1])->once()->andReturn(new Configuration);
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', time()])->once()->andReturn(new Configuration);
$this->be($this->user()); $this->be($this->user());
$response = $this->post(route('admin.update-check.post'), ['check_for_updates' => 1]); $response = $this->post(route('admin.update-check.post'), ['check_for_updates' => 1]);
$response->assertSessionHas('success'); $response->assertSessionHas('success');
@@ -82,18 +85,79 @@ class UpdateControllerTest extends TestCase
*/ */
public function testUpdateCheck() 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 = [ $releases = [
new Release(['id' => 'x', 'title' => $version . '.1', 'content' => '', 'updated' => new Carbon]),
]; ];
$updater = $this->mock(UpdateRequest::class); $updater = $this->mock(UpdateRequest::class);
$updater->shouldReceive('call')->andReturnNull(); $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()); $this->be($this->user());
$response = $this->post(route('admin.update-check.manual')); $response = $this->post(route('admin.update-check.manual'));
$response->assertStatus(200); $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->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('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');
} }