如何测试用户登录页面?
How to test user login page?
我已经安装了FosUserBundle,我想用PhpUnit做一个测试来检查用户是否可以登录,但是我的代码一定是错误的,因为我不能被重定向。
我的代码:
public function testLogin()
{
$client = static::createClient();
$crawler = $client->request('GET', '/crm/login');
$buttonCrawlerNode = $crawler->selectButton('_submit');
$form = $buttonCrawlerNode->form();
$data = array('_username' => 'root','_password' => 'toor');
$client->submit($form,$data);
$crawler = $this->client->followRedirect();
$crawler = $client->request('GET', '/crm/home');
}
您似乎使用了 client
的 2 个不同实例
public function testLogin()
{
$client = static::createClient();
$crawler = $client->request('GET', '/crm/login');
$buttonCrawlerNode = $crawler->selectButton('_submit');
$form = $buttonCrawlerNode->form();
$data = array('_username' => 'root','_password' => 'toor');
$client->submit($form,$data);
//here you're using $this->client not $client
$crawler = $this->client->followRedirect();
$crawler = $client->request('GET', '/crm/home');
}
我已经安装了FosUserBundle,我想用PhpUnit做一个测试来检查用户是否可以登录,但是我的代码一定是错误的,因为我不能被重定向。
我的代码:
public function testLogin()
{
$client = static::createClient();
$crawler = $client->request('GET', '/crm/login');
$buttonCrawlerNode = $crawler->selectButton('_submit');
$form = $buttonCrawlerNode->form();
$data = array('_username' => 'root','_password' => 'toor');
$client->submit($form,$data);
$crawler = $this->client->followRedirect();
$crawler = $client->request('GET', '/crm/home');
}
您似乎使用了 client
public function testLogin()
{
$client = static::createClient();
$crawler = $client->request('GET', '/crm/login');
$buttonCrawlerNode = $crawler->selectButton('_submit');
$form = $buttonCrawlerNode->form();
$data = array('_username' => 'root','_password' => 'toor');
$client->submit($form,$data);
//here you're using $this->client not $client
$crawler = $this->client->followRedirect();
$crawler = $client->request('GET', '/crm/home');
}