Skip to content

Commit

Permalink
feat: new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tchapi committed Jan 20, 2024
1 parent 69566c3 commit 88cadf3
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 1 deletion.
2 changes: 1 addition & 1 deletion templates/users/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</div>
</div>
{% else %}
<div class="my-5 py-5 d-flex justify-content-center align-items-center text-muted">{{ "no.users.yet"|trans }}</div>
<div id="no-user" class="my-5 py-5 d-flex justify-content-center align-items-center text-muted">{{ "no.users.yet"|trans }}</div>
{% endfor %}
</div>

Expand Down
98 changes: 98 additions & 0 deletions tests/Functional/CalendarControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace App\Tests\Functional;

use App\Security\AdminUser;
use App\Repository\CalendarInstanceRepository;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class CalendarControllerTest extends WebTestCase
{
public function testCalendarIndex(): void
{
$user = new AdminUser('admin', 'test');

$client = static::createClient();
$client->loginUser($user);
$client->request('GET', "/calendars/test_user");

$this->assertResponseIsSuccessful();

$this->assertSelectorExists('nav.navbar');
$this->assertSelectorTextContains('h1', 'Calendars for Test User');
$this->assertSelectorTextContains('a.btn', '+ New Calendar');
$this->assertSelectorTextContains('h5', 'default.calendar.title');
}

public function testCalendarEdit(): void
{
$user = new AdminUser('admin', 'test');

$client = static::createClient();
$client->loginUser($user);

$calendarRepository = static::getContainer()->get(CalendarInstanceRepository::class);
$calendar = $calendarRepository->findOneByDisplayName('default.calendar.title');

$client->request('GET', "/calendars/test_user/edit/".$calendar->getId());

$this->assertResponseIsSuccessful();

$this->assertSelectorTextContains('h1', 'Editing Calendar «default.calendar.title»');
$this->assertSelectorTextContains('button#calendar_instance_save', 'Save');

$client->submitForm('calendar_instance_save');

$this->assertResponseRedirects("/calendars/test_user");
$client->followRedirect();

$this->assertSelectorTextContains('h5', 'default.calendar.title');
}

public function testCalendarNew(): void
{
$user = new AdminUser('admin', 'test');

$client = static::createClient();
$client->loginUser($user);
$crawler = $client->request('GET', "/calendars/test_user/new");

$this->assertResponseIsSuccessful();

$this->assertSelectorTextContains('h1', 'New Calendar ');
$this->assertSelectorTextContains('button#calendar_instance_save', 'Save');

$buttonCrawlerNode = $crawler->selectButton('calendar_instance_save');

$form = $buttonCrawlerNode->form();
$client->submit($form, [
'calendar_instance[uri]' => 'new_test_calendar',
'calendar_instance[displayName]' => 'New test calendar',
'calendar_instance[description]' => 'new calendar',
'calendar_instance[calendarColor]' => '#00112233',
]);

$this->assertResponseRedirects("/calendars/test_user");
$client->followRedirect();

$this->assertSelectorTextContains('h5', 'default.calendar.title');
$this->assertAnySelectorTextContains('h5', 'New test calendar');
}

public function testCalendarDelete(): void
{
$user = new AdminUser('admin', 'test');

$client = static::createClient();
$client->loginUser($user);

$calendarRepository = static::getContainer()->get(CalendarInstanceRepository::class);
$calendar = $calendarRepository->findOneByDisplayName('default.calendar.title');
$client->request('GET', "/calendars/test_user/delete/".$calendar->getId());

$this->assertResponseRedirects("/calendars/test_user");
$client->followRedirect();

$this->assertSelectorTextNotContains('h5', 'default.calendar.title');
}
}
121 changes: 121 additions & 0 deletions tests/Functional/UserControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

namespace App\Tests\Functional;

use App\Security\AdminUser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class UserControllerTest extends WebTestCase
{
public function testUserIndex(): void
{
$user = new AdminUser('admin', 'test');

$client = static::createClient();
$client->loginUser($user);
$client->request('GET', "/users/");

$this->assertResponseIsSuccessful();

$this->assertSelectorExists('nav.navbar');
$this->assertSelectorTextContains('h1', 'Users and Resources');
$this->assertSelectorTextContains('a.btn', '+ New User');
$this->assertSelectorTextContains('h5', 'Test User');
}

public function testUserEdit(): void
{
$user = new AdminUser('admin', 'test');

$client = static::createClient();
$client->loginUser($user);
$client->request('GET', "/users/edit/test_user");

$this->assertResponseIsSuccessful();

$this->assertSelectorTextContains('h1', 'Editing User «test_user»');
$this->assertSelectorTextContains('button#user_save', 'Save');

$client->submitForm('user_save');

$this->assertResponseRedirects("/users/");
$client->followRedirect();

$this->assertSelectorTextContains('h5', 'Test User');
}

public function testUserNew(): void
{
$user = new AdminUser('admin', 'test');

$client = static::createClient();
$client->loginUser($user);
$crawler = $client->request('GET', "/users/new");

$this->assertResponseIsSuccessful();

$this->assertSelectorTextContains('h1', 'New User');
$this->assertSelectorTextContains('button#user_save', 'Save');

$buttonCrawlerNode = $crawler->selectButton('user_save');

$form = $buttonCrawlerNode->form();
$client->submit($form, [
'user[username]' => 'new_test_user',
'user[displayName]' => 'New test User',
'user[email]' => '[email protected]',
'user[password][first]' => 'coucou',
'user[password][second]' => 'coucou',
'user[isAdmin]' => false,
]);

$this->assertResponseRedirects("/users/");
$client->followRedirect();

$this->assertSelectorTextContains('h5', 'Test User');
$this->assertAnySelectorTextContains('h5', 'New test User');
}

public function testUserDelete(): void
{
$user = new AdminUser('admin', 'test');

$client = static::createClient();
$client->loginUser($user);
$client->request('GET', "/users/delete/test_user");

$this->assertResponseRedirects("/users/");
$client->followRedirect();

$this->assertSelectorTextContains('div#no-user', 'No users yet.');
}

public function testUserDelegates(): void
{
$user = new AdminUser('admin', 'test');

$client = static::createClient();
$client->loginUser($user);
$client->request('GET', "/users/delegates/test_user");

$this->assertResponseIsSuccessful();

$this->assertSelectorExists('nav.navbar');
$this->assertSelectorTextContains('h1', 'Delegates for Test User');
$this->assertSelectorTextContains('a.btn', '+ Add a delegate');
$this->assertAnySelectorTextContains('div', 'Delegation is enabled for this account.');
$this->assertAnySelectorTextContains('a.btn', 'Disable it');

$client->clickLink('Disable it');

$this->assertResponseRedirects("/users/delegates/test_user");
$client->followRedirect();

$this->assertSelectorExists('nav.navbar');
$this->assertSelectorTextContains('h1', 'Delegates for Test User');
$this->assertSelectorTextNotContains('a.btn', '+ Add a delegate');
$this->assertAnySelectorTextContains('div', 'Delegation is not enabled for this account.');
$this->assertAnySelectorTextContains('a.btn', 'Enable it');

}
}

0 comments on commit 88cadf3

Please sign in to comment.