mirror of
https://gh.wpcy.net/https://github.com/fairpm/aspirecloud.git
synced 2026-06-20 02:22:28 +08:00
321 lines
11 KiB
PHP
321 lines
11 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\WpOrg\Plugin;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
use function Safe\json_encode;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('returns an empty response for empty requests', function () {
|
|
$this
|
|
->withHeader('Accept', 'application/json')
|
|
->post('/plugins/update-check/1.1', [
|
|
'plugins' => json_encode(['plugins' => []]),
|
|
'translations' => json_encode([]),
|
|
'locale' => json_encode([]),
|
|
])
|
|
->assertStatus(200)
|
|
->assertExactJson(['plugins' => [], 'translations' => []]);
|
|
});
|
|
|
|
it('returns plugin updates from minimal input', function () {
|
|
Plugin::factory(['slug' => 'aaa', 'version' => '1.2.3'])->create();
|
|
Plugin::factory(['slug' => 'bbb', 'version' => '0.5'])->create();
|
|
|
|
$this
|
|
->withHeader('Accept', 'application/json')
|
|
->post('/plugins/update-check/1.1', [
|
|
'plugins' => json_encode([
|
|
'plugins' => [
|
|
'aaa/plugin-a.php' => ['Version' => '1.0.2'], // out of date
|
|
'bbb/plugin-b.php' => ['Version' => '0.5'], // up to date
|
|
],
|
|
]),
|
|
'translations' => json_encode([]),
|
|
'locale' => json_encode([]),
|
|
])
|
|
->assertStatus(200)
|
|
->assertJson([
|
|
'plugins' => [
|
|
'aaa/plugin-a.php' => [
|
|
'plugin' => 'aaa/plugin-a.php',
|
|
'slug' => 'aaa',
|
|
'new_version' => '1.2.3',
|
|
],
|
|
],
|
|
])
|
|
->assertJsonCount(1, 'plugins')
|
|
->assertJsonMissingPath('plugins.bbb')
|
|
->assertJsonMissingPath('plugins.no_update')
|
|
->assertExactJsonStructure([
|
|
'plugins' => [
|
|
'*' => [
|
|
'banners' => ['high', 'low'],
|
|
'banners_rtl',
|
|
'compatibility' => [
|
|
'php' => ['minimum', 'recommended'],
|
|
'wordpress' => ['maximum', 'minimum', 'tested'],
|
|
],
|
|
'icons' => ['1x', '2x'],
|
|
'id',
|
|
'new_version',
|
|
'package',
|
|
'plugin',
|
|
'requires',
|
|
'requires_php',
|
|
'requires_plugins',
|
|
'slug',
|
|
'tested',
|
|
'url',
|
|
],
|
|
],
|
|
'translations',
|
|
]);
|
|
});
|
|
|
|
it('returns all plugin updates', function () {
|
|
Plugin::factory(['slug' => 'aaa', 'version' => '1.2.3'])->create();
|
|
Plugin::factory(['slug' => 'bbb', 'version' => '0.3'])->create();
|
|
|
|
$this
|
|
->withHeader('Accept', 'application/json')
|
|
->post('/plugins/update-check/1.1', [
|
|
'plugins' => json_encode([
|
|
'plugins' => [
|
|
'aaa/plugin-a.php' => ['Version' => '1.0.3'],
|
|
'bbb/plugin-b.php' => ['Version' => '0.2'],
|
|
],
|
|
]),
|
|
'translations' => json_encode([]),
|
|
'locale' => json_encode([]),
|
|
])
|
|
->assertStatus(200)
|
|
->assertJson([
|
|
'plugins' => [
|
|
'aaa/plugin-a.php' => [
|
|
'plugin' => 'aaa/plugin-a.php',
|
|
'slug' => 'aaa',
|
|
'new_version' => '1.2.3',
|
|
],
|
|
],
|
|
])
|
|
->assertJson([
|
|
'plugins' => [
|
|
'bbb/plugin-b.php' => [
|
|
'plugin' => 'bbb/plugin-b.php',
|
|
'slug' => 'bbb',
|
|
'new_version' => '0.3',
|
|
],
|
|
],
|
|
])
|
|
->assertJsonCount(2, 'plugins')
|
|
->assertJsonMissingPath('plugins.no_update')
|
|
->assertExactJsonStructure([
|
|
'plugins' => [
|
|
'*' => [
|
|
'banners' => ['high', 'low'],
|
|
'banners_rtl',
|
|
'compatibility' => [
|
|
'php' => ['minimum', 'recommended'],
|
|
'wordpress' => ['maximum', 'minimum', 'tested'],
|
|
],
|
|
'icons' => ['1x', '2x'],
|
|
'id',
|
|
'new_version',
|
|
'package',
|
|
'plugin',
|
|
'requires',
|
|
'requires_php',
|
|
'requires_plugins',
|
|
'slug',
|
|
'tested',
|
|
'url',
|
|
],
|
|
],
|
|
'translations',
|
|
]);
|
|
});
|
|
|
|
it('filters updates with nonstandard UpdateURI', function () {
|
|
Plugin::factory(['slug' => 'aaa', 'version' => '1.2.3'])->create();
|
|
Plugin::factory(['slug' => 'bbb', 'version' => '0.3'])->create();
|
|
|
|
$this
|
|
->withHeader('Accept', 'application/json')
|
|
->post('/plugins/update-check/1.1', [
|
|
'plugins' => json_encode([
|
|
'plugins' => [
|
|
'aaa/plugin-a.php' => ['Version' => '1.0.3', 'UpdateURI' => 'false'],
|
|
'bbb/plugin-b.php' => ['Version' => '0.2'],
|
|
],
|
|
]),
|
|
'translations' => json_encode([]),
|
|
'locale' => json_encode([]),
|
|
])
|
|
->assertStatus(200)
|
|
->assertJson([
|
|
'plugins' => [
|
|
'bbb/plugin-b.php' => [
|
|
'plugin' => 'bbb/plugin-b.php',
|
|
'slug' => 'bbb',
|
|
'new_version' => '0.3',
|
|
],
|
|
],
|
|
])
|
|
->assertJsonCount(1, 'plugins')
|
|
->assertJsonMissingPath('plugins.no_update')
|
|
->assertExactJsonStructure([
|
|
'plugins' => [
|
|
'*' => [
|
|
'banners' => ['high', 'low'],
|
|
'banners_rtl',
|
|
'compatibility' => [
|
|
'php' => ['minimum', 'recommended'],
|
|
'wordpress' => ['maximum', 'minimum', 'tested'],
|
|
],
|
|
'icons' => ['1x', '2x'],
|
|
'id',
|
|
'new_version',
|
|
'package',
|
|
'plugin',
|
|
'requires',
|
|
'requires_php',
|
|
'requires_plugins',
|
|
'slug',
|
|
'tested',
|
|
'url',
|
|
],
|
|
],
|
|
'translations',
|
|
]);
|
|
});
|
|
|
|
it('uses defaults for malformed requests', function () {
|
|
Plugin::factory(['slug' => 'aaa', 'version' => '1.2.3'])->create();
|
|
Plugin::factory(['slug' => 'bbb', 'version' => '0.5'])->create();
|
|
|
|
$this
|
|
->withHeader('Accept', 'application/json')
|
|
->post('/plugins/update-check/1.1', [
|
|
'plugins' => json_encode([
|
|
'plugins' => [
|
|
'aaa/plugin-a.php' => ['Version' => '1.0.2'], // out of date
|
|
'bbb.php' => ['Version' => '0.5'], // up to date
|
|
],
|
|
]),
|
|
'translations' => '', // becomes null!
|
|
'locale' => 'not_json',
|
|
])
|
|
->assertStatus(200)
|
|
->assertJson([
|
|
'plugins' => [
|
|
'aaa/plugin-a.php' => [
|
|
'plugin' => 'aaa/plugin-a.php',
|
|
'slug' => 'aaa',
|
|
'new_version' => '1.2.3',
|
|
],
|
|
],
|
|
])
|
|
->assertJsonMissingPath('plugins.bbb')
|
|
->assertJsonMissingPath('plugins.no_update')
|
|
->assertExactJsonStructure([
|
|
'plugins' => [
|
|
'*' => [
|
|
'banners' => ['high', 'low'],
|
|
'banners_rtl',
|
|
'compatibility' => [
|
|
'php' => ['minimum', 'recommended'],
|
|
'wordpress' => ['maximum', 'minimum', 'tested'],
|
|
],
|
|
'icons' => ['1x', '2x'],
|
|
'id',
|
|
'new_version',
|
|
'package',
|
|
'plugin',
|
|
'requires',
|
|
'requires_php',
|
|
'requires_plugins',
|
|
'slug',
|
|
'tested',
|
|
'url',
|
|
],
|
|
],
|
|
'translations',
|
|
]);
|
|
});
|
|
|
|
it('includes no_update when all=true', function () {
|
|
Plugin::factory(['slug' => 'aaa', 'version' => '1.2.3'])->create();
|
|
Plugin::factory(['slug' => 'bbb', 'version' => '0.5'])->create();
|
|
|
|
$this
|
|
->withHeader('Accept', 'application/json')
|
|
->post('/plugins/update-check/1.1?all=true', [
|
|
'plugins' => json_encode([
|
|
'plugins' => [
|
|
'aaa/plugin-a.php' => ['Version' => '1.0.2'], // out of date
|
|
'bbb/plugin-b.php' => ['Version' => '0.5'], // up to date
|
|
],
|
|
]),
|
|
'translations' => json_encode([]),
|
|
'locale' => json_encode([]),
|
|
])
|
|
->assertStatus(200)
|
|
->assertJson([
|
|
'plugins' => [
|
|
'aaa/plugin-a.php' => [
|
|
'plugin' => 'aaa/plugin-a.php',
|
|
'slug' => 'aaa',
|
|
'new_version' => '1.2.3',
|
|
],
|
|
],
|
|
])
|
|
->assertJsonMissingPath('plugins.bbb')
|
|
->assertExactJsonStructure([
|
|
'plugins' => [
|
|
'aaa/plugin-a.php' => [
|
|
'banners' => ['high', 'low'],
|
|
'banners_rtl',
|
|
'compatibility' => [
|
|
'php' => ['minimum', 'recommended'],
|
|
'wordpress' => ['maximum', 'minimum', 'tested'],
|
|
],
|
|
'icons' => ['1x', '2x'],
|
|
'id',
|
|
'new_version',
|
|
'package',
|
|
'plugin',
|
|
'requires',
|
|
'requires_php',
|
|
'requires_plugins',
|
|
'slug',
|
|
'tested',
|
|
'url',
|
|
],
|
|
],
|
|
'no_update' => [
|
|
'bbb/plugin-b.php' => [
|
|
'banners' => ['high', 'low'],
|
|
'banners_rtl',
|
|
'compatibility' => [
|
|
'php' => ['minimum', 'recommended'],
|
|
'wordpress' => ['maximum', 'minimum', 'tested'],
|
|
],
|
|
'icons' => ['1x', '2x'],
|
|
'id',
|
|
'new_version',
|
|
'package',
|
|
'plugin',
|
|
'requires',
|
|
'requires_php',
|
|
'requires_plugins',
|
|
'slug',
|
|
'tested',
|
|
'url',
|
|
],
|
|
],
|
|
'translations',
|
|
]);
|
|
});
|