fix for tests

This commit is contained in:
Pig Fang 2018-07-12 17:18:19 +08:00
parent 2cea484f50
commit 8e2b2c78fc
2 changed files with 21 additions and 8 deletions

View File

@ -32,6 +32,8 @@ class UpdateController extends Controller
public function showUpdatePage() public function showUpdatePage()
{ {
$this->refreshInfo();
$info = [ $info = [
'latest_version' => '', 'latest_version' => '',
'current_version' => $this->currentVersion, 'current_version' => $this->currentVersion,
@ -87,6 +89,8 @@ class UpdateController extends Controller
public function checkUpdates() public function checkUpdates()
{ {
$this->refreshInfo();
return json([ return json([
'latest' => $this->getUpdateInfo('latest_version'), 'latest' => $this->getUpdateInfo('latest_version'),
'available' => $this->newVersionAvailable() 'available' => $this->newVersionAvailable()
@ -102,6 +106,8 @@ class UpdateController extends Controller
public function download(Request $request) public function download(Request $request)
{ {
$this->refreshInfo();
$action = $request->input('action'); $action = $request->input('action');
if (! $this->newVersionAvailable()) return; if (! $this->newVersionAvailable()) return;
@ -243,4 +249,15 @@ class UpdateController extends Controller
return Arr::get($this->getUpdateInfo('releases'), $version); return Arr::get($this->getUpdateInfo('releases'), $version);
} }
/**
* Only used in testing.
*/
protected function refreshInfo()
{
if (config('app.env') == 'testing') {
$this->updateSource = option('update_source');
$this->currentVersion = config('app.version');
}
}
} }

View File

@ -60,6 +60,7 @@ class UpdateControllerTest extends TestCase
{ {
option(['update_source' => 'http://xxx.xx/']); option(['update_source' => 'http://xxx.xx/']);
$this->visit('/admin/update') $this->visit('/admin/update')
->see(trans('admin.update.info.pre-release'))
->see(trans('admin.update.errors.connection')) ->see(trans('admin.update.errors.connection'))
->see(config('app.version')) ->see(config('app.version'))
->uncheck('check_update') ->uncheck('check_update')
@ -71,18 +72,13 @@ class UpdateControllerTest extends TestCase
option('update_source') option('update_source')
); );
option(['update_source' => vfs\vfsStream::url('root/update.json')]);
$time = $this->generateFakeUpdateInfo('4.0.0'); $time = $this->generateFakeUpdateInfo('4.0.0');
$this->visit('/admin/update') $this->visit('/admin/update')
->see(config('app.version')) ->see(config('app.version'))
->see('4.0.0') ->see('4.0.0')
->see('test') ->see('test')
->see($time); ->see($time);
file_put_contents(vfs\vfsStream::url('root/update.json'), json_encode([
'latest_version' => '4.0.0'
]));
$this->visit('/admin/update')
->see(trans('admin.update.info.pre-release'));
} }
public function testCheckUpdates() public function testCheckUpdates()
@ -117,12 +113,12 @@ class UpdateControllerTest extends TestCase
Storage::disk('root')->deleteDirectory('storage/update_cache'); Storage::disk('root')->deleteDirectory('storage/update_cache');
$this->generateFakeUpdateInfo('4.0.0'); $this->generateFakeUpdateInfo('4.0.0');
Storage::shouldReceive('disk') Storage::shouldReceive('disk')
->with('root')
->once() ->once()
->with('root')
->andReturnSelf(); ->andReturnSelf();
Storage::shouldReceive('makeDirectory') Storage::shouldReceive('makeDirectory')
->with('storage/update_cache')
->once() ->once()
->with('storage/update_cache')
->andReturn(false); ->andReturn(false);
$this->get('/admin/update/download?action=prepare-download') $this->get('/admin/update/download?action=prepare-download')
->see(trans('admin.update.errors.write-permission')); ->see(trans('admin.update.errors.write-permission'));