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,145 @@
<?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 PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\TestDox;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use App\Tests\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
/**
* Class GameControllerTest
*
* @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('Game Controller')]
class GameControllerTest extends WebTestCase
{
private KernelBrowser $client;
protected function setUp(): void
{
parent::setUp();
$this->client = static::createClient();
}
#[Test]
#[TestDox('Homepage loads successfully with navigation links')]
public function homepageLoadsSuccessfully(): void
{
$crawler = $this->client->request('GET', '/');
self::assertResponseStatusCodeSame(Response::HTTP_OK);
self::assertSelectorExists('h1');
self::assertSelectorExists('a[href="/play"]');
}
#[Test]
#[TestDox('Play page loads successfully')]
public function playPageLoadsSuccessfully(): void
{
$crawler = $this->client->request('GET', '/play');
self::assertResponseStatusCodeSame(Response::HTTP_OK);
self::assertResponseHasHeader('Content-Type');
}
#[Test]
#[TestDox('Play page with game association loads successfully')]
public function playPageWithGameAssocLoadsSuccessfully(): void
{
$crawler = $this->client->request('GET', '/play/testgame123');
self::assertResponseStatusCodeSame(Response::HTTP_OK);
self::assertResponseHasHeader('Content-Type');
}
#[Test]
#[TestDox('Privacy policy page loads successfully')]
public function privacyPolicyPageLoadsSuccessfully(): void
{
$crawler = $this->client->request('GET', '/privacy-policy');
self::assertResponseStatusCodeSame(Response::HTTP_OK);
self::assertSelectorExists('h1');
}
#[Test]
#[TestDox('Terms of service page loads successfully')]
public function termsOfServicePageLoadsSuccessfully(): void
{
$crawler = $this->client->request('GET', '/terms-of-service');
self::assertResponseStatusCodeSame(Response::HTTP_OK);
self::assertSelectorExists('h1');
}
#[Test]
#[TestDox('Contact page loads successfully with form')]
public function contactPageLoadsSuccessfully(): void
{
$crawler = $this->client->request('GET', '/contact');
self::assertResponseStatusCodeSame(Response::HTTP_OK);
self::assertSelectorExists('form');
self::assertSelectorExists('button[type="submit"]');
}
#[Test]
#[TestDox('Landing page loads successfully with play link')]
public function landingPageLoadsSuccessfully(): void
{
$crawler = $this->client->request('GET', '/landing-page');
self::assertResponseStatusCodeSame(Response::HTTP_OK);
self::assertSelectorExists('h1');
self::assertSelectorExists('a[href="/play"]');
}
#[Test]
#[TestDox('Rules page loads successfully')]
public function rulesPageLoadsSuccessfully(): void
{
$crawler = $this->client->request('GET', '/rules');
self::assertResponseStatusCodeSame(Response::HTTP_OK);
self::assertSelectorExists('h1');
}
#[Test]
#[TestDox('Homepage contains navigation links to play, login, and register')]
public function homepageContainsNavigationLinks(): void
{
$crawler = $this->client->request('GET', '/');
self::assertResponseIsSuccessful();
self::assertSelectorExists('a[href="/play"]');
self::assertSelectorExists('a[href="/login"]');
self::assertSelectorExists('a[href="/register"]');
}
#[Test]
#[TestDox('Play page has correct meta tags for SEO and social sharing')]
public function playPageHasCorrectMetaTags(): void
{
$this->client->request('GET', '/play');
self::assertResponseIsSuccessful();
self::assertSelectorExists('meta[name="description"]');
self::assertSelectorExists('meta[property="og:title"]');
}
}

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);
}
}

View File

@@ -0,0 +1,148 @@
<?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\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 SecurityControllerTest
*
* @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('Security Controller')]
class SecurityControllerTest extends WebTestCase
{
private KernelBrowser $client;
protected function setUp(): void
{
parent::setUp();
$this->client = static::createClient();
}
#[Test]
#[TestDox('Login page loads successfully with form fields')]
public function loginPageLoadsSuccessfully(): void
{
$crawler = $this->client->request('GET', '/login');
self::assertResponseStatusCodeSame(Response::HTTP_OK);
self::assertSelectorExists('form');
self::assertSelectorExists('input[name="_username"]');
self::assertSelectorExists('input[name="_password"]');
self::assertSelectorExists('button[type="submit"]');
}
#[Test]
#[TestDox('Login page has links to register and forgot password')]
public function loginPageHasRegisterLink(): void
{
$crawler = $this->client->request('GET', '/login');
self::assertResponseIsSuccessful();
self::assertSelectorExists('a[href="/register"]');
self::assertSelectorExists('a[href="/forgot-password"]');
}
#[Test]
#[TestDox('Register page loads successfully with form')]
public function registerPageLoadsSuccessfully(): void
{
$crawler = $this->client->request('GET', '/register');
self::assertResponseStatusCodeSame(Response::HTTP_OK);
self::assertSelectorExists('form');
self::assertSelectorExists('button[type="submit"]');
}
#[Test]
#[TestDox('Register page has link to login')]
public function registerPageHasLoginLink(): void
{
$crawler = $this->client->request('GET', '/register');
self::assertResponseIsSuccessful();
self::assertSelectorExists('a[href="/login"]');
}
#[Test]
#[TestDox('Forgot password page loads successfully with form')]
public function forgotPasswordPageLoadsSuccessfully(): void
{
$crawler = $this->client->request('GET', '/forgot-password');
self::assertResponseStatusCodeSame(Response::HTTP_OK);
self::assertSelectorExists('form');
self::assertSelectorExists('button[type="submit"]');
}
#[Test]
#[TestDox('Account activation with invalid token redirects to login')]
public function activateWithInvalidTokenShowsError(): void
{
$this->client->request('GET', '/activate/invalid-token');
self::assertResponseRedirects('/login');
}
#[Test]
#[TestDox('Password reset with invalid token redirects to forgot password')]
public function resetPasswordWithInvalidTokenShowsError(): void
{
$this->client->request('GET', '/reset-password/invalid-token');
self::assertResponseRedirects('/forgot-password');
}
#[Test]
#[TestDox('Authenticated user is redirected from login page to homepage')]
public function authenticatedUserRedirectsFromLogin(): void
{
$user = UserFactory::createOne();
$this->client->loginUser($user->_real());
$this->client->request('GET', '/login');
self::assertResponseRedirects('/');
}
#[Test]
#[TestDox('Authenticated user is redirected from register page to homepage')]
public function authenticatedUserRedirectsFromRegister(): void
{
$user = UserFactory::createOne();
$this->client->loginUser($user->_real());
$this->client->request('GET', '/register');
self::assertResponseRedirects('/');
}
#[Test]
#[TestDox('Login form has remember me checkbox')]
public function loginFormHasRememberMeCheckbox(): void
{
$crawler = $this->client->request('GET', '/login');
self::assertResponseIsSuccessful();
self::assertSelectorExists('input[name="_remember_me"]');
}
}