<?php
namespace Club\UserBundle\Tests\Controller;

use Club\UserBundle\Helper\TestCase as WebTestCase;

class AdminUserControllerTest extends WebTestCase
{
  protected $client;

  public function __construct()
  {
    $this->client = static::createClient();
    $this->login($this->client);
  }

  public function testIndex()
  {
    $crawler = $this->client->request('GET', '/en/admin/user');
    $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
  }

  public function testNew()
  {
    $crawler = $this->client->request('GET', '/en/admin/user/new');
    $this->assertEquals(200, $this->client->getResponse()->getStatusCode());

    $form = $crawler->selectButton('Save')->form();
    $crawler = $this->client->submit($form);
    $this->assertEquals(200, $this->client->getResponse()->getStatusCode());

    $form = $crawler->selectButton('Save')->form(array(
      'admin_user[profile][first_name]' => 'John',
      'admin_user[profile][last_name]' => 'Doe',
      'admin_user[profile][day_of_birth]' => '1984-06-29',
      'admin_user[profile][profile_address][street]' => 'Clubby Strasse 14',
      'admin_user[profile][profile_address][postal_code]' => '9000',
      'admin_user[profile][profile_address][city]' => 'Aalborg',
      'admin_user[profile][profile_emails][0][email_address]' => 'user@example.com',
      'admin_user[profile][profile_phone][phone_number]' => '+45 80808080',
    ));
    $crawler = $this->client->submit($form);
    $this->assertEquals(302, $this->client->getResponse()->getStatusCode());

    $crawler = $this->client->request('GET', '/en/admin/user/new');
    $this->assertEquals(200, $this->client->getResponse()->getStatusCode());

    $form = $crawler->selectButton('Save')->form(array(
      'admin_user[profile][first_name]' => 'John',
      'admin_user[profile][last_name]' => 'Doe',
      'admin_user[profile][day_of_birth]' => '1984-06-29',
      'admin_user[profile][profile_address][street]' => 'Clubby Strasse 14',
      'admin_user[profile][profile_address][postal_code]' => '9000',
      'admin_user[profile][profile_address][city]' => 'Aalborg',
    ));
    $crawler = $this->client->submit($form);
    $this->assertEquals(302, $this->client->getResponse()->getStatusCode());
  }
}
