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()
{
$this->refreshInfo();
$info = [
'latest_version' => '',
'current_version' => $this->currentVersion,
@ -87,6 +89,8 @@ class UpdateController extends Controller
public function checkUpdates()
{
$this->refreshInfo();
return json([
'latest' => $this->getUpdateInfo('latest_version'),
'available' => $this->newVersionAvailable()
@ -102,6 +106,8 @@ class UpdateController extends Controller
public function download(Request $request)
{
$this->refreshInfo();
$action = $request->input('action');
if (! $this->newVersionAvailable()) return;
@ -243,4 +249,15 @@ class UpdateController extends Controller
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/']);
$this->visit('/admin/update')
->see(trans('admin.update.info.pre-release'))
->see(trans('admin.update.errors.connection'))
->see(config('app.version'))
->uncheck('check_update')
@ -71,18 +72,13 @@ class UpdateControllerTest extends TestCase
option('update_source')
);
option(['update_source' => vfs\vfsStream::url('root/update.json')]);
$time = $this->generateFakeUpdateInfo('4.0.0');
$this->visit('/admin/update')
->see(config('app.version'))
->see('4.0.0')
->see('test')
->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()
@ -117,12 +113,12 @@ class UpdateControllerTest extends TestCase
Storage::disk('root')->deleteDirectory('storage/update_cache');
$this->generateFakeUpdateInfo('4.0.0');
Storage::shouldReceive('disk')
->with('root')
->once()
->with('root')
->andReturnSelf();
Storage::shouldReceive('makeDirectory')
->with('storage/update_cache')
->once()
->with('storage/update_cache')
->andReturn(false);
$this->get('/admin/update/download?action=prepare-download')
->see(trans('admin.update.errors.write-permission'));