-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
220 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
|
||
} | ||
} |