Private
Public Access
1
0

new: pkg: add test cases to back-end w/ real database connection in it #10

This commit is contained in:
2026-04-21 17:56:04 +02:00
parent 6bf908b43e
commit d704be5bff
38 changed files with 5429 additions and 17 deletions

View File

@@ -0,0 +1,146 @@
<?php declare(strict_types=1);
/**
* This file is part of the SplendidBear Websites' projects.
*
* Copyright (c) 2026 @ www.splendidbear.org
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Controller;
use App\Tests\Factory\PlayedGameFactory;
use App\Tests\Factory\UserFactory;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\TestDox;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use App\Tests\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
/**
* Class ProfileControllerTest
*
* @package App\Tests\Controller
* @author Lang <https://www.splendidbear.org>
* @category Class
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License
* @link www.splendidbear.org
* @since 2026. 04. 21.
*/
#[TestDox('Profile Controller')]
class ProfileControllerTest extends WebTestCase
{
private KernelBrowser $client;
protected function setUp(): void
{
parent::setUp();
$this->client = static::createClient();
}
#[Test]
#[TestDox('Profile page requires authentication')]
public function profilePageRequiresAuthentication(): void
{
$this->client->request('GET', '/profile');
self::assertResponseRedirects('/login');
}
#[Test]
#[TestDox('Profile security page requires authentication')]
public function profileSecurityPageRequiresAuthentication(): void
{
$this->client->request('GET', '/profile/security');
self::assertResponseRedirects('/login');
}
#[Test]
#[TestDox('Profile avatar upload requires authentication')]
public function profileAvatarPageRequiresAuthentication(): void
{
$this->client->request('POST', '/profile/avatar');
self::assertResponseRedirects('/login');
}
#[Test]
#[TestDox('Battle share page returns 404 for non-existent game')]
public function battleSharePageReturns404ForNonExistentGame(): void
{
$uuid = '00000000-0000-4000-a000-000000000000';
$this->client->request('GET', '/battle/' . $uuid);
self::assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
}
#[Test]
#[TestDox('Battle share page displays valid game details')]
public function battleSharePageShowsValidGame(): void
{
$game = PlayedGameFactory::new()
->withRegisteredPlayers()
->redWins()
->create();
$crawler = $this->client->request('GET', '/battle/' . $game->uuid);
self::assertResponseIsSuccessful();
self::assertSelectorExists('h1');
self::assertGreaterThan(0, $crawler->filter('body')->count());
}
#[Test]
#[TestDox('Battle share page has Open Graph meta tags for social sharing')]
public function battleSharePageHasOgMetaTags(): void
{
$game = PlayedGameFactory::new()
->withRegisteredPlayers()
->redWins()
->create();
$this->client->request('GET', '/battle/' . $game->uuid);
self::assertResponseIsSuccessful();
self::assertSelectorExists('meta[property="og:title"]');
self::assertSelectorExists('meta[property="og:image"]');
self::assertSelectorExists('meta[property="og:description"]');
self::assertSelectorExists('meta[property="og:type"]');
}
#[Test]
#[TestDox('OG battle image returns 404 for non-existent game')]
public function ogBattleImageReturns404ForNonExistentGame(): void
{
$uuid = '00000000-0000-4000-a000-000000000000';
$this->client->request('GET', '/og/battle/' . $uuid . '.png');
self::assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
}
#[Test]
#[TestDox('OG battle image generates valid PNG for existing game')]
public function ogBattleImageReturnsImageForValidGame(): void
{
$game = PlayedGameFactory::new()
->withRegisteredPlayers()
->redWins()
->create();
$this->client->request('GET', '/og/battle/' . $game->uuid . '.png');
self::assertResponseIsSuccessful();
self::assertResponseHeaderSame('Content-Type', 'image/png');
}
#[Test]
#[TestDox('Battle share page returns 404 for invalid UUID format')]
public function battleSharePageWithInvalidUuidFormat(): void
{
$this->client->request('GET', '/battle/invalid-uuid');
self::assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
}
}