1
0
mirror of https://github.com/flarum/core.git synced 2025-08-13 11:54:32 +02:00

Extension Tests (#9)

This commit is contained in:
Sami Mazouz
2021-11-08 20:22:07 +01:00
committed by GitHub
parent 5cef9ad52c
commit a9ff884231
17 changed files with 429 additions and 1003 deletions

View File

@@ -0,0 +1,55 @@
<?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\extensions;
use Flarum\PackageManager\Tests\integration\RefreshComposerSetup;
use Flarum\PackageManager\Tests\integration\TestCase;
class RemoveExtensionTest extends TestCase
{
use RefreshComposerSetup;
/**
* @test
*/
public function extension_installed_by_default()
{
$this->assertExtensionExists('flarum-tags');
}
/**
* @test
*/
public function removing_an_extension_works()
{
$response = $this->send(
$this->request('DELETE', '/api/package-manager/extensions/flarum-tags', [
'authenticatedAs' => 1
])
);
$this->assertEquals(204, $response->getStatusCode());
$this->assertExtensionNotExists('flarum-tags');
}
/**
* @test
*/
public function removing_a_non_existant_extension_fails()
{
$response = $this->send(
$this->request('DELETE', '/api/package-manager/extensions/flarum-potato', [
'authenticatedAs' => 1
])
);
$this->assertEquals(409, $response->getStatusCode());
}
}

View File

@@ -0,0 +1,85 @@
<?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\extensions;
use Flarum\PackageManager\Tests\integration\RefreshComposerSetup;
use Flarum\PackageManager\Tests\integration\TestCase;
class RequireExtensionTest extends TestCase
{
use RefreshComposerSetup;
/**
* @test
*/
public function extension_uninstalled_by_default()
{
$this->assertExtensionNotExists('v17development-blog');
}
/**
* @test
*/
public function requiring_an_existing_extension_fails()
{
$response = $this->send(
$this->request('POST', '/api/package-manager/extensions', [
'authenticatedAs' => 1,
'json' => [
'data' => [
'package' => 'flarum/tags'
]
]
])
);
$this->assertEquals(409, $response->getStatusCode());
}
/**
* @test
*/
public function requiring_a_compatible_extension_works()
{
$response = $this->send(
$this->request('POST', '/api/package-manager/extensions', [
'authenticatedAs' => 1,
'json' => [
'data' => [
'package' => 'v17development/flarum-blog'
]
]
])
);
$this->assertEquals(200, $response->getStatusCode());
$this->assertExtensionExists('v17development-blog');
}
/**
* @test
*/
public function requiring_an_uncompatible_extension_fails()
{
$response = $this->send(
$this->request('POST', '/api/package-manager/extensions', [
'authenticatedAs' => 1,
'json' => [
'data' => [
'package' => 'flarum/auth-github'
]
]
])
);
$this->assertEquals(409, $response->getStatusCode());
$this->assertEquals('extension_incompatible_with_instance', $this->guessedCause($response));
}
}

View File

@@ -0,0 +1,55 @@
<?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\extensions;
use Flarum\PackageManager\Tests\integration\RefreshComposerSetup;
use Flarum\PackageManager\Tests\integration\TestCase;
class UpdateExtensionTest extends TestCase
{
use RefreshComposerSetup;
/**
* @test
*/
public function extension_installed_by_default()
{
$this->assertExtensionExists('flarum-tags');
}
/**
* @test
*/
public function updating_an_existing_extension_works()
{
$response = $this->send(
$this->request('PATCH', '/api/package-manager/extensions/flarum-tags', [
'authenticatedAs' => 1,
])
);
$this->assertEquals(204, $response->getStatusCode());
$this->assertExtensionExists('flarum-tags');
}
/**
* @test
*/
public function updating_a_non_existing_extension_fails()
{
$response = $this->send(
$this->request('PATCH', '/api/package-manager/extensions/flarum-potato', [
'authenticatedAs' => 1,
])
);
$this->assertEquals(409, $response->getStatusCode());
}
}