You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			111 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			PHP
		
	
			
		
		
	
	
			111 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			PHP
		
	
| <?php
 | |
| namespace App\Tests;
 | |
| 
 | |
| use App\Factory\DojoFactory;
 | |
| use App\Factory\UserFactory;
 | |
| use App\Repository\UserRepository;
 | |
| 
 | |
| class DojoTest extends AbstractTest
 | |
| {
 | |
| 
 | |
|     /**
 | |
|      * Requirement: A user should be able to create a dojo!
 | |
|      */
 | |
|     public function testDojoCreate(): void
 | |
|     {
 | |
|         $userName = "FooBarFigher";
 | |
|         $dojoName = "BigFightDojo";
 | |
|         $userRepository = $this->getContainer()->get(UserRepository::class);
 | |
| 
 | |
|         $this->assertCount(0, $userRepository->findByAuthName($userName));
 | |
| 
 | |
|         static::createClientWithToken($userName)->request('POST', '/api/dojos', [
 | |
|             'json' => [
 | |
|                 'name' => $dojoName
 | |
|             ]
 | |
|         ]);
 | |
| 
 | |
|         $this->assertResponseStatusCodeSame(201);
 | |
| 
 | |
|         $user = $userRepository->findOneByAuthName($userName);
 | |
| 
 | |
|         $this->assertJsonContains([
 | |
|             'name' => $dojoName,
 | |
|             'owner' => $this->getIri($user)
 | |
|         ]);
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Requirement: A user should NOT be able to create more than one dojos!
 | |
|      */
 | |
|     public function testDojoUserCannotCreateMultipleDojos(): void
 | |
|     {
 | |
|         $userName = "FooBarFigher";
 | |
|         $dojoName = "BigFightDojo";
 | |
|         DojoFactory::createOne([
 | |
|             'name' => $dojoName,
 | |
|             'owner' => UserFactory::createOne([
 | |
|                 'authName' => $userName
 | |
|             ])
 | |
|         ]);
 | |
| 
 | |
|         static::createClientWithToken($userName)->request('POST', '/api/dojos', [
 | |
|             'json' => [
 | |
|                 'name' => $dojoName
 | |
|             ]
 | |
|         ]);
 | |
| 
 | |
|         $this->assertResponseStatusCodeSame(409); // 409 Conflict
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Requirement: A user should be able to change the dojos name!
 | |
|      * FIXME: Add limitation so users will not do this frequently.
 | |
|      */
 | |
|     public function testDojoChangeDojoName(): void
 | |
|     {
 | |
|         $userName = "FooBarFigher";
 | |
|         $dojoName = "BigFightDojo";
 | |
|         $newDojoName = "BigFightDojo";
 | |
|         $dojo = DojoFactory::createOne(
 | |
|             [
 | |
|                 'name' => $dojoName,
 | |
|                 'owner' => UserFactory::createOne([
 | |
|                     'authName' => $userName
 | |
|                 ])
 | |
|             ]);
 | |
| 
 | |
|         static::createClientWithToken($userName)->request('PATCH', '/api/dojos/' . $dojo->id,
 | |
|             [
 | |
|                 'headers' => [
 | |
|                     'content-type' => 'application/merge-patch+json'
 | |
|                 ],
 | |
|                 'json' => [
 | |
|                     'name' => $newDojoName
 | |
|                 ]
 | |
|             ]);
 | |
| 
 | |
|         $this->assertResponseStatusCodeSame(200);
 | |
|     }
 | |
| 
 | |
|     public function testDojoRetrieve(): void
 | |
|     {
 | |
|         $userName = "FooBarFigher";
 | |
|         $dojoName = "SmallFightDojo";
 | |
|         $dojo = DojoFactory::createOne(
 | |
|             [
 | |
|                 'name' => $dojoName,
 | |
|                 'owner' => UserFactory::createOne([
 | |
|                     'authName' => $userName
 | |
|                 ])
 | |
|             ]);
 | |
| 
 | |
|         static::createClientWithToken($userName)->request('GET', '/api/dojos/' . $dojo->getId());
 | |
| 
 | |
|         $this->assertJsonContains([
 | |
|             'name' => $dojoName
 | |
|         ]);
 | |
|     }
 | |
| }
 | |
| 
 |