|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace CodedMonkey\Dirigent\Tests\FunctionalTests\Controller\Dashboard; |
| 4 | + |
| 5 | +use CodedMonkey\Dirigent\Controller\Dashboard\DashboardCredentialsController; |
| 6 | +use CodedMonkey\Dirigent\Doctrine\Entity\Credentials; |
| 7 | +use CodedMonkey\Dirigent\Doctrine\Entity\CredentialsType; |
| 8 | +use CodedMonkey\Dirigent\Tests\Helper\MockEntityFactoryTrait; |
| 9 | +use CodedMonkey\Dirigent\Tests\Helper\WebTestCaseTrait; |
| 10 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 11 | +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
| 12 | +use Symfony\Component\HttpFoundation\Response; |
| 13 | + |
| 14 | +#[CoversClass(DashboardCredentialsController::class)] |
| 15 | +class DashboardCredentialsControllerTest extends WebTestCase |
| 16 | +{ |
| 17 | + use MockEntityFactoryTrait; |
| 18 | + use WebTestCaseTrait; |
| 19 | + |
| 20 | + public function testCreate(): void |
| 21 | + { |
| 22 | + $client = static::createClient(); |
| 23 | + $this->loginUser('admin'); |
| 24 | + |
| 25 | + $client->request('GET', '/credentials/new'); |
| 26 | + |
| 27 | + $this->assertResponseStatusCodeSame(Response::HTTP_OK); |
| 28 | + |
| 29 | + $client->submitForm('Create', [ |
| 30 | + 'Credentials[name]' => 'Test credentials', |
| 31 | + 'Credentials[type]' => CredentialsType::HttpBasic->value, |
| 32 | + 'Credentials[username]' => 'testuser', |
| 33 | + 'Credentials[password]' => 'testpassword', |
| 34 | + ]); |
| 35 | + |
| 36 | + $this->assertResponseStatusCodeSame(Response::HTTP_FOUND); |
| 37 | + |
| 38 | + $credentials = $this->findEntity(Credentials::class, ['name' => 'Test credentials']); |
| 39 | + |
| 40 | + self::assertNotNull($credentials, 'A credentials entry was created.'); |
| 41 | + self::assertSame(CredentialsType::HttpBasic, $credentials->getType()); |
| 42 | + self::assertSame('testuser', $credentials->getUsername()); |
| 43 | + } |
| 44 | + |
| 45 | + public function testEdit(): void |
| 46 | + { |
| 47 | + $client = static::createClient(); |
| 48 | + $this->loginUser('admin'); |
| 49 | + |
| 50 | + $credentials = new Credentials(); |
| 51 | + $credentials->setName('Original name'); |
| 52 | + $credentials->setType(CredentialsType::HttpBasic); |
| 53 | + $credentials->setUsername('originaluser'); |
| 54 | + $credentials->setPassword('originalpassword'); |
| 55 | + |
| 56 | + $this->persistEntities($credentials); |
| 57 | + |
| 58 | + $credentialsId = $credentials->getId(); |
| 59 | + |
| 60 | + $client->request('GET', "/credentials/{$credentialsId}/edit"); |
| 61 | + |
| 62 | + $this->assertResponseStatusCodeSame(Response::HTTP_OK); |
| 63 | + |
| 64 | + $client->submitForm('Save changes', [ |
| 65 | + 'Credentials[name]' => 'Updated name', |
| 66 | + 'Credentials[type]' => CredentialsType::HttpBasic->value, |
| 67 | + 'Credentials[username]' => 'updateduser', |
| 68 | + 'Credentials[password]' => 'updatedpassword', |
| 69 | + ]); |
| 70 | + |
| 71 | + $this->assertResponseStatusCodeSame(Response::HTTP_FOUND); |
| 72 | + |
| 73 | + $this->clearEntities(); |
| 74 | + $credentials = $this->findEntity(Credentials::class, $credentialsId); |
| 75 | + |
| 76 | + self::assertNotNull($credentials); |
| 77 | + self::assertSame('Updated name', $credentials->getName()); |
| 78 | + self::assertSame('updateduser', $credentials->getUsername()); |
| 79 | + } |
| 80 | +} |
0 commit comments