mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 17:29:04 +00:00 
			
		
		
		
	Refactored class
This commit is contained in:
		| @@ -11,8 +11,26 @@ use Symfony\Component\DomCrawler\Crawler; | ||||
|  * | ||||
|  * @author Kevin Veen-Birkenbach [aka. Frantz] | ||||
|  */ | ||||
| class UserLoginTest extends WebTestCase | ||||
| class UserFunctionTest extends WebTestCase | ||||
| { | ||||
|     /** | ||||
|      *  | ||||
|      * @var string | ||||
|      */ | ||||
|     private $username = ''; | ||||
|      | ||||
|     /** | ||||
|      *  | ||||
|      * @var string | ||||
|      */ | ||||
|     private $password = ''; | ||||
|      | ||||
|     /** | ||||
|      *  | ||||
|      * @var string | ||||
|      */ | ||||
|     private $email = ''; | ||||
|      | ||||
|     /** | ||||
|      * @var Crawler | ||||
|      */ | ||||
| @@ -20,6 +38,29 @@ class UserLoginTest extends WebTestCase | ||||
| 
 | ||||
|     private $client; | ||||
| 
 | ||||
|     private function initAttributs():void{ | ||||
|         $this->username = 'function_test_user'; | ||||
|         $this->password = 'function_test_user_password'; | ||||
|         $this->email = 'function_test_user@test.test'; | ||||
|     } | ||||
|      | ||||
|     private function crawlUrl(string $url):void{ | ||||
|         $this->crawler = $this->client->request('GET', $url); | ||||
|         $this->client->followRedirects(); | ||||
|     } | ||||
|      | ||||
|     private function registerUser():void{ | ||||
|         $this->crawlUrl('/register/'); | ||||
|         $form = $this->crawler->selectButton('Register')->form(); | ||||
|         $form['fos_user_registration_form[username]']->setValue($this->username); | ||||
|         $form['fos_user_registration_form[email]']->setValue($this->email); | ||||
|         $form['fos_user_registration_form[plainPassword][first]']->setValue($this->password); | ||||
|         $form['fos_user_registration_form[plainPassword][second]']->setValue($this->password); | ||||
|         $this->client->submit($form); | ||||
|     } | ||||
|      | ||||
|      | ||||
|      | ||||
|     /** | ||||
|      * Prepares the environment before running a test. | ||||
|      */ | ||||
| @@ -27,24 +68,22 @@ class UserLoginTest extends WebTestCase | ||||
|     { | ||||
|         parent::setUp(); | ||||
|         $this->client = $this->createClient(); | ||||
|         $this->crawler = $this->client->request('GET', '/login'); | ||||
|         $this->initAttributs(); | ||||
|         $this->registerUser(); | ||||
|     } | ||||
| 
 | ||||
|      | ||||
|     public function testIfLoginFormPageIsReachable(): void | ||||
|     { | ||||
|         $this->assertEquals(200, $this->client->getResponse() | ||||
|             ->getStatusCode()); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @todo Implemnt test for success message | ||||
|      */ | ||||
|     public function testSuccessfullLogin(): void | ||||
|     public function testLoginSuccessfull(): void | ||||
|     { | ||||
|         $this->client->followRedirects(); | ||||
|         $this->crawlUrl('/login/'); | ||||
|         $form = $this->crawler->selectButton('Log in')->form(); | ||||
|         $form['_username']->setValue(DummyFixtures::USER_NAME); | ||||
|         $form['_password']->setValue(DummyFixtures::USER_PASSWORD); | ||||
|         $form['_username']->setValue($this->username); | ||||
|         $form['_password']->setValue($this->password); | ||||
|         $form['_remember_me']->setValue('on'); | ||||
|         $this->client->submit($form); | ||||
|         $this->assertContains( | ||||
| @@ -60,16 +99,16 @@ class UserLoginTest extends WebTestCase | ||||
|             $this->client->getResponse()->getContent() | ||||
|             ); | ||||
|         $this->assertContains( | ||||
|             DummyFixtures::USER_NAME, | ||||
|             $this->username, | ||||
|             $this->client->getResponse()->getContent() | ||||
|             ); | ||||
|     } | ||||
| 
 | ||||
|     public function testWrongPassword(): void | ||||
|     public function testLoginWrongPassword(): void | ||||
|     { | ||||
|         $this->client->followRedirects(); | ||||
|         $this->crawlUrl('/login/'); | ||||
|         $form = $this->crawler->selectButton('Log in')->form(); | ||||
|         $form['_username']->setValue(DummyFixtures::USER_NAME); | ||||
|         $form['_username']->setValue($this->username); | ||||
|         $form['_password']->setValue('wrong password'); | ||||
|         $form['_remember_me']->setValue('on'); | ||||
|         $this->client->submit($form); | ||||
| @@ -79,12 +118,12 @@ class UserLoginTest extends WebTestCase | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
|     public function testWrongUsername(): void | ||||
|     public function testLoginWrongUsername(): void | ||||
|     { | ||||
|         $this->client->followRedirects(); | ||||
|         $this->crawlUrl('/login/'); | ||||
|         $form = $this->crawler->selectButton('Log in')->form(); | ||||
|         $form['_username']->setValue('unknown_username'); | ||||
|         $form['_password']->setValue(DummyFixtures::USER_PASSWORD); | ||||
|         $form['_password']->setValue($this->password); | ||||
|         $form['_remember_me']->setValue('on'); | ||||
|         $this->client->submit($form); | ||||
|         $this->assertContains( | ||||
		Reference in New Issue
	
	Block a user