format("c"); return sodium_bin2base64(sodium_crypto_sign($message, $sign_secret), SODIUM_BASE64_VARIANT_URLSAFE); } /** * Requirement: A user should be able to create a dojo! */ public function testCreateDojo(): void { $userName = "FooBarFigher"; $dojoName = "BigFightDojo"; $userRepository = $this->getContainer()->get(UserRepository::class); $this->assertCount(0, $userRepository->findByAuthName($userName)); static::createClient()->request('POST', '/api/dojos', [ 'headers' => [ 'accept' => 'application/json', 'X-AUTH-TOKEN' => $this->generateAuthToken($userName) ], 'json' => [ 'name' => $dojoName ] ]); $this->assertResponseStatusCodeSame(201); $this->assertCount(1, $userRepository->findByAuthName($userName)); } /** * Requirement: A user should NOT be able to create more than one dojos! */ public function testUserCannotCreateMultipleDojos(): void { $userName = "FooBarFigher"; $dojoName = "BigFightDojo"; DojoFactory::createOne([ 'name' => $dojoName, 'owner' => UserFactory::createOne([ 'authName' => $userName ]) ]); static::createClient()->request('POST', '/api/dojos', [ 'headers' => [ 'accept' => 'application/json', 'X-AUTH-TOKEN' => $this->generateAuthToken($userName) ], '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 testChangeDojoName(): void { $userName = "FooBarFigher"; $dojoName = "BigFightDojo"; $newDojoName = "BigFightDojo"; $dojo = DojoFactory::createOne( [ 'name' => $dojoName, 'owner' => UserFactory::createOne([ 'authName' => $userName ]) ]); static::createClient()->request('PATCH', '/api/dojos/' . $dojo->id, [ 'headers' => [ 'content-type' => 'application/merge-patch+json', 'accept' => 'application/json', 'X-AUTH-TOKEN' => $this->generateAuthToken($userName) ], 'json' => [ 'name' => $newDojoName ] ]); $this->assertResponseStatusCodeSame(200); } }