|
|
|
@ -5,13 +5,13 @@ declare(strict_types=1); |
|
|
|
|
namespace Chamilo\Tests\CoreBundle\Repository\Node; |
|
|
|
|
|
|
|
|
|
use Chamilo\CoreBundle\Repository\Node\UserRepository; |
|
|
|
|
use Chamilo\Tests\AbstractApiTest; |
|
|
|
|
use Chamilo\Tests\ChamiloTestTrait; |
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @covers \UserRepository |
|
|
|
|
*/ |
|
|
|
|
class UserRepositoryTest extends KernelTestCase |
|
|
|
|
class UserRepositoryTest extends AbstractApiTest |
|
|
|
|
{ |
|
|
|
|
use ChamiloTestTrait; |
|
|
|
|
|
|
|
|
@ -26,10 +26,73 @@ class UserRepositoryTest extends KernelTestCase |
|
|
|
|
public function testCreateUser(): void |
|
|
|
|
{ |
|
|
|
|
self::bootKernel(); |
|
|
|
|
|
|
|
|
|
$this->createUser('user', 'user'); |
|
|
|
|
|
|
|
|
|
$count = self::getContainer()->get(UserRepository::class)->count([]); |
|
|
|
|
$this->assertSame(3, $count); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testCreateUserWithApi(): void |
|
|
|
|
{ |
|
|
|
|
$token = $this->getUserToken([]); |
|
|
|
|
$username = 'test'; |
|
|
|
|
$this->createClientWithCredentials($token)->request( |
|
|
|
|
'POST', |
|
|
|
|
'/api/users', |
|
|
|
|
[ |
|
|
|
|
'json' => [ |
|
|
|
|
'username' => $username, |
|
|
|
|
'firstname' => 'test', |
|
|
|
|
'lastname' => 'test', |
|
|
|
|
'website' => '', |
|
|
|
|
'biography' => '', |
|
|
|
|
'locale' => 'en', |
|
|
|
|
'plainPassword' => 'test', |
|
|
|
|
'timezone' => 'Europe\Paris', |
|
|
|
|
'email' => 'test@example.com', |
|
|
|
|
//'expiresAt' => new \DateTime(), |
|
|
|
|
'phone' => '123456', |
|
|
|
|
'address' => 'Paris', |
|
|
|
|
'roles' => [ |
|
|
|
|
'ROLE_USER', |
|
|
|
|
], |
|
|
|
|
], |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$this->assertResponseIsSuccessful(); |
|
|
|
|
$this->assertResponseStatusCodeSame(201); |
|
|
|
|
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); |
|
|
|
|
$this->assertJsonContains([ |
|
|
|
|
'@context' => '/api/contexts/User', |
|
|
|
|
'username' => $username, |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testUpdateUserWithApi(): void |
|
|
|
|
{ |
|
|
|
|
$user = $this->createUser('test'); |
|
|
|
|
|
|
|
|
|
$token = $this->getUserToken([]); |
|
|
|
|
|
|
|
|
|
$this->createClientWithCredentials($token)->request( |
|
|
|
|
'PUT', |
|
|
|
|
'/api/users/'.$user->getId(), |
|
|
|
|
[ |
|
|
|
|
'json' => [ |
|
|
|
|
'firstname' => 'updated', |
|
|
|
|
'lastname' => 'updated', |
|
|
|
|
], |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$this->assertResponseIsSuccessful(); |
|
|
|
|
$this->assertResponseStatusCodeSame(200); |
|
|
|
|
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); |
|
|
|
|
$this->assertJsonContains([ |
|
|
|
|
'@context' => '/api/contexts/User', |
|
|
|
|
'firstname' => 'updated', |
|
|
|
|
'lastname' => 'updated', |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|