mirror of
https://github.com/flarum/core.git
synced 2025-08-12 19:34:18 +02:00
test: Updates (#11)
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\PackageManager\Tests\integration\api;
|
||||
|
||||
use Flarum\PackageManager\Tests\integration\ChangeComposerConfig;
|
||||
use Flarum\PackageManager\Tests\integration\DummyExtensions;
|
||||
use Flarum\PackageManager\Tests\integration\RefreshComposerSetup;
|
||||
use Flarum\PackageManager\Tests\integration\TestCase;
|
||||
|
||||
class MajorUpdateTest extends TestCase
|
||||
{
|
||||
use RefreshComposerSetup, ChangeComposerConfig, DummyExtensions;
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function cannot_update_when_no_update_check_ran()
|
||||
{
|
||||
$this->makeDummyExtensionCompatibleWith("flarum/dummy-incompatible-extension", ">=0.1.0-beta.15 <=0.1.0-beta.16");
|
||||
$this->setComposerConfig([
|
||||
'require' => [
|
||||
'flarum/core' => '^0.1.0-beta.15',
|
||||
'flarum/tags' => '^0.1.0-beta.15',
|
||||
'flarum/dummy-incompatible-extension' => '^1.0.0'
|
||||
],
|
||||
'minimum-stability' => 'beta',
|
||||
]);
|
||||
|
||||
$response = $this->send(
|
||||
$this->request('POST', '/api/package-manager/major-update', [
|
||||
'authenticatedAs' => 1,
|
||||
])
|
||||
);
|
||||
|
||||
$this->assertEquals(409, $response->getStatusCode());
|
||||
$this->assertEquals('no_new_major_version', $this->errorDetails($response)['code']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function can_update_when_major_update_available()
|
||||
{
|
||||
$this->makeDummyExtensionCompatibleWith("flarum/dummy-compatible-extension", "^0.1.0-beta.15 | ^1.0.0");
|
||||
$this->setComposerConfig([
|
||||
'require' => [
|
||||
'flarum/core' => '^0.1.0-beta.15',
|
||||
'flarum/tags' => '^0.1.0-beta.15',
|
||||
'flarum/dummy-compatible-extension' => '^1.0.0'
|
||||
],
|
||||
'minimum-stability' => 'beta',
|
||||
]);
|
||||
|
||||
$lastUpdateCheck = $this->send(
|
||||
$this->request('POST', '/api/package-manager/check-for-updates', [
|
||||
'authenticatedAs' => 1,
|
||||
])
|
||||
);
|
||||
|
||||
$this->forgetComposerApp();
|
||||
|
||||
$response = $this->send(
|
||||
$this->request('POST', '/api/package-manager/major-update', [
|
||||
'authenticatedAs' => 1,
|
||||
])
|
||||
);
|
||||
|
||||
$newMinorCoreVersion = array_filter(
|
||||
json_decode((string) $lastUpdateCheck->getBody(), true)['updates']['installed'],
|
||||
function ($package) {
|
||||
return $package['name'] === 'flarum/core';
|
||||
}
|
||||
)[0]['latest-major'];
|
||||
|
||||
$this->assertEquals(204, $response->getStatusCode());
|
||||
$this->assertPackageVersion("flarum/core", str_replace('v', '^', $newMinorCoreVersion));
|
||||
$this->assertPackageVersion("flarum/tags", "*");
|
||||
$this->assertPackageVersion("flarum/dummy-compatible-extension", "*");
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function cannot_update_with_incompatible_extensions()
|
||||
{
|
||||
$this->makeDummyExtensionCompatibleWith("flarum/dummy-incompatible-extension-a", ">=0.1.0-beta.16 <0.1.0-beta.17");
|
||||
$this->makeDummyExtensionCompatibleWith("flarum/dummy-incompatible-extension-b", ">=0.1.0-beta.16 <=0.1.0-beta.17");
|
||||
$this->makeDummyExtensionCompatibleWith("flarum/dummy-incompatible-extension-c", "0.1.0-beta.16");
|
||||
$this->setComposerConfig([
|
||||
'require' => [
|
||||
'flarum/core' => '^0.1.0-beta.16',
|
||||
'flarum/tags' => '^0.1.0-beta.16',
|
||||
'flarum/dummy-incompatible-extension-a' => '^1.0.0',
|
||||
'flarum/dummy-incompatible-extension-b' => '^1.0.0',
|
||||
'flarum/dummy-incompatible-extension-c' => '^1.0.0',
|
||||
],
|
||||
'minimum-stability' => 'beta',
|
||||
]);
|
||||
|
||||
$this->send(
|
||||
$this->request('POST', '/api/package-manager/check-for-updates', [
|
||||
'authenticatedAs' => 1,
|
||||
])
|
||||
);
|
||||
|
||||
$response = $this->send(
|
||||
$this->request('POST', '/api/package-manager/major-update', [
|
||||
'authenticatedAs' => 1,
|
||||
])
|
||||
);
|
||||
|
||||
$this->assertEquals(409, $response->getStatusCode());
|
||||
$this->assertEquals('extensions_incompatible_with_new_major', $this->errorDetails($response)['guessed_cause']);
|
||||
$this->assertEquals([
|
||||
'flarum/dummy-incompatible-extension-a',
|
||||
'flarum/dummy-incompatible-extension-b',
|
||||
'flarum/dummy-incompatible-extension-c'
|
||||
], $this->errorDetails($response)['incompatible_extensions']);
|
||||
}
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\PackageManager\Tests\integration\api;
|
||||
|
||||
use Flarum\PackageManager\Event\FlarumUpdated;
|
||||
use Flarum\PackageManager\Settings\LastUpdateRun;
|
||||
use Flarum\PackageManager\Tests\integration\ChangeComposerConfig;
|
||||
use Flarum\PackageManager\Tests\integration\DummyExtensions;
|
||||
use Flarum\PackageManager\Tests\integration\RefreshComposerSetup;
|
||||
use Flarum\PackageManager\Tests\integration\TestCase;
|
||||
|
||||
class MinorUpdateTest extends TestCase
|
||||
{
|
||||
use RefreshComposerSetup, ChangeComposerConfig, DummyExtensions;
|
||||
|
||||
/**
|
||||
* @test--
|
||||
*/
|
||||
public function can_update_to_next_minor_version()
|
||||
{
|
||||
$this->makeDummyExtensionCompatibleWith("flarum/dummy-compatible-extension", "^1.0.0");
|
||||
$this->setComposerConfig([
|
||||
'require' => [
|
||||
// The only reason we don't set this to `^1.0.0` and let it update to latest minor,
|
||||
// is because migrations that run DDL queries might be introduced in future versions,
|
||||
// therefore breaking the test transaction.
|
||||
'flarum/core' => '>=1.0.0 <= 1.1.0',
|
||||
// We leave tags fixed to a version,
|
||||
// the update handler must be able to set it to `*`.
|
||||
'flarum/tags' => '1.0.3',
|
||||
'flarum/lang-english' => '*',
|
||||
'flarum/dummy-compatible-extension' => '^1.0.0'
|
||||
]
|
||||
]);
|
||||
|
||||
$response = $this->send(
|
||||
$this->request('POST', '/api/package-manager/minor-update', [
|
||||
'authenticatedAs' => 1,
|
||||
])
|
||||
);
|
||||
|
||||
$this->assertEquals(204, $response->getStatusCode());
|
||||
$this->assertPackageVersion('flarum/tags', '*');
|
||||
$this->assertPackageVersion('flarum/dummy-compatible-extension', '*');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function can_update_with_latest_ext_incompatible_with_latest_core()
|
||||
{
|
||||
$this->makeDummyExtensionCompatibleWith("flarum/dummy-extension", "1.0.0");
|
||||
$this->setComposerConfig([
|
||||
'require' => [
|
||||
'flarum/core' => '>=1.0.0 <=1.1.0',
|
||||
'flarum/tags' => '1.0.3',
|
||||
'flarum/lang-english' => '*',
|
||||
'flarum/dummy-extension' => '^1.0.0'
|
||||
]
|
||||
]);
|
||||
|
||||
$this->send(
|
||||
$this->request('POST', '/api/package-manager/check-for-updates', [
|
||||
'authenticatedAs' => 1,
|
||||
])
|
||||
);
|
||||
|
||||
$this->forgetComposerApp();
|
||||
|
||||
$response = $this->send(
|
||||
$this->request('POST', '/api/package-manager/minor-update', [
|
||||
'authenticatedAs' => 1,
|
||||
])
|
||||
);
|
||||
|
||||
/** @var LastUpdateRun $lastUpdateRun */
|
||||
$lastUpdateRun = $this->app()->getContainer()->make(LastUpdateRun::class);
|
||||
|
||||
$this->assertEquals(204, $response->getStatusCode());
|
||||
$this->assertPackageVersion("flarum/tags", "*");
|
||||
$this->assertPackageVersion("flarum/dummy-extension", "*");
|
||||
$this->assertEquals([
|
||||
'flarum/core',
|
||||
'flarum/lang-english',
|
||||
'flarum/tags'
|
||||
], $lastUpdateRun->for(FlarumUpdated::MINOR)->get()['limitedPackages']);
|
||||
}
|
||||
}
|
@@ -100,7 +100,7 @@ class RequireExtensionTest extends TestCase
|
||||
);
|
||||
|
||||
$this->assertEquals(409, $response->getStatusCode());
|
||||
$this->assertEquals('extension_incompatible_with_instance', $this->guessedCause($response));
|
||||
$this->assertEquals('extension_incompatible_with_instance', $this->errorDetails($response)['guessed_cause']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,6 +120,6 @@ class RequireExtensionTest extends TestCase
|
||||
);
|
||||
|
||||
$this->assertEquals(409, $response->getStatusCode());
|
||||
$this->assertEquals('extension_incompatible_with_instance', $this->guessedCause($response));
|
||||
$this->assertEquals('extension_incompatible_with_instance', $this->errorDetails($response)['guessed_cause']);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user