You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
194 lines
6.6 KiB
194 lines
6.6 KiB
<?php
|
|
namespace App\Tests;
|
|
|
|
use App\Factory\CharacterFactory;
|
|
use App\Factory\DojoFactory;
|
|
use App\Factory\TechniqueFactory;
|
|
use App\Factory\UserFactory;
|
|
|
|
class CharacterTest extends AbstractTest
|
|
{
|
|
|
|
/**
|
|
* Requirement: A user should be able see all characters from a dojo, but only the public fields!
|
|
*/
|
|
public function testRetrieveCharactersFromDojoPublic(): void
|
|
{
|
|
$requestUser = UserFactory::createOne();
|
|
$dojo = DojoFactory::createOne();
|
|
CharacterFactory::createMany(4, [
|
|
'dojo' => $dojo
|
|
]);
|
|
CharacterFactory::createMany(10);
|
|
|
|
$response = static::createClientWithToken($requestUser->authName)->request('GET',
|
|
'/api/dojo/' . $dojo->id . '/characters');
|
|
|
|
$this->assertResponseStatusCodeSame(200);
|
|
|
|
$this->assertNotEquals("[[],[],[],[]]", $response->getContent());
|
|
|
|
// Because test fixtures are automatically loaded between each test, you can assert on them
|
|
$this->assertCount(4, $response->toArray());
|
|
|
|
$chars = $response->toArray();
|
|
$this->assertEquals(4, count($chars[0]));
|
|
$this->assertArrayHasKey('id', $chars[0]);
|
|
$this->assertArrayHasKey('name', $chars[0]);
|
|
$this->assertEquals('/api/dojos/' . $dojo->getId()
|
|
->toBase32(), $chars[0]['dojo']);
|
|
$this->assertArrayHasKey('age', $chars[0]);
|
|
$this->assertArrayNotHasKey('freeSkillPoints', $chars[0]);
|
|
$this->assertArrayNotHasKey('strength', $chars[0]); // not accessible via this route
|
|
$this->assertArrayNotHasKey('constitution', $chars[0]); // not accessible via this route
|
|
$this->assertArrayNotHasKey('agility', $chars[0]); // not accessible via this route
|
|
$this->assertArrayNotHasKey('chi', $chars[0]); // not accessible via this route
|
|
$this->assertArrayNotHasKey('techniques', $chars[0]); // not accessible via this route
|
|
}
|
|
|
|
/**
|
|
* Requirement: A user should be able see all of the characters from his dojo, not restricted by public fields!
|
|
*/
|
|
public function testRetrieveCharactersFromOwnDojoDetail(): void
|
|
{
|
|
$dojo = DojoFactory::createOne([
|
|
'owner' => UserFactory::createOne()
|
|
]);
|
|
|
|
$technique = TechniqueFactory::createOne();
|
|
|
|
$foo = CharacterFactory::createMany(4, [
|
|
'dojo' => $dojo,
|
|
'techniques' => [
|
|
$technique
|
|
]
|
|
]);
|
|
|
|
$this->assertEquals(1, count($foo[0]->getTechniques()));
|
|
|
|
CharacterFactory::createMany(10);
|
|
|
|
$response = static::createClientWithToken($dojo->getOwner()->authName)->request('GET', '/api/dojo/characters');
|
|
|
|
$this->assertResponseStatusCodeSame(200);
|
|
|
|
$this->assertNotEquals("[[],[],[],[]]", $response->getContent());
|
|
|
|
$chars = $response->toArray();
|
|
$this->assertEquals(10, count($chars[0]));
|
|
$this->assertArrayHasKey('id', $chars[0]);
|
|
$this->assertArrayHasKey('name', $chars[0]);
|
|
$this->assertArrayHasKey('dojo', $chars[0]);
|
|
$this->assertEquals('/api/dojos/' . $dojo->getId()
|
|
->toBase32(), $chars[0]['dojo']);
|
|
$this->assertArrayHasKey('age', $chars[0]);
|
|
$this->assertArrayHasKey('freeSkillPoints', $chars[0]);
|
|
$this->assertArrayHasKey('strength', $chars[0]);
|
|
$this->assertArrayHasKey('constitution', $chars[0]);
|
|
$this->assertArrayHasKey('agility', $chars[0]);
|
|
$this->assertArrayHasKey('chi', $chars[0]);
|
|
$this->assertArrayHasKey('techniques', $chars[0]);
|
|
$this->assertEquals('/api/techniques/' . $technique->getId()
|
|
->toBase32(), $chars[0]['techniques'][0]);
|
|
}
|
|
|
|
/**
|
|
* Requirement: MVP only (in the future the recuitment will be different).
|
|
* A user should be able to create a single character.
|
|
*/
|
|
public function testCreateCharacter(): void
|
|
{
|
|
$dojo = DojoFactory::createOne([
|
|
'owner' => UserFactory::createOne()
|
|
]);
|
|
|
|
$tech = TechniqueFactory::createOne([
|
|
'prerequisite' => NULL
|
|
]);
|
|
|
|
$response = static::createClientWithToken($dojo->getOwner()->authName)->request('POST', '/api/characters',
|
|
[
|
|
'json' => [
|
|
'name' => 'Dude',
|
|
'strength' => 1,
|
|
'constitution' => 1,
|
|
'agility' => 1,
|
|
'chi' => 1,
|
|
'techniques' => [
|
|
'/api/techniques/' . $tech->getId()
|
|
->toBase32()
|
|
]
|
|
]
|
|
]);
|
|
|
|
$this->assertResponseStatusCodeSame(201);
|
|
|
|
$this->assertArrayHasKey('id', $response->toArray());
|
|
}
|
|
|
|
/**
|
|
* Requirement: MVP only (in the future the recuitment will be different).
|
|
* A user should NOT be able spent more skill points than available.
|
|
*/
|
|
public function testCreateCharacterStatsTooHigh(): void
|
|
{
|
|
$dojo = DojoFactory::createOne([
|
|
'owner' => UserFactory::createOne()
|
|
]);
|
|
|
|
$tech = TechniqueFactory::createOne([
|
|
'prerequisite' => NULL
|
|
]);
|
|
|
|
static::createClientWithToken($dojo->getOwner()->authName)->request('POST', '/api/characters',
|
|
[
|
|
'json' => [
|
|
'name' => 'Dude',
|
|
'strength' => 99,
|
|
'constitution' => 1,
|
|
'agility' => 1,
|
|
'chi' => 1,
|
|
'techniques' => [
|
|
'/api/techniques/' . $tech->getId()
|
|
->toBase32()
|
|
]
|
|
]
|
|
]);
|
|
|
|
$this->assertResponseStatusCodeSame(422);
|
|
}
|
|
|
|
/**
|
|
* Requirement: MVP only (in the future the recuitment will be different).
|
|
* A user should NOT be able spent more skill points than available.
|
|
*/
|
|
public function testCreateCharacterTooExpensiveTechnique(): void
|
|
{
|
|
$dojo = DojoFactory::createOne([
|
|
'owner' => UserFactory::createOne()
|
|
]);
|
|
|
|
$tech = TechniqueFactory::createOne([
|
|
'costs' => 99
|
|
]);
|
|
|
|
static::createClientWithToken($dojo->getOwner()->authName)->request('POST', '/api/characters',
|
|
[
|
|
'json' => [
|
|
'name' => 'Dude',
|
|
'strength' => 1,
|
|
'constitution' => 1,
|
|
'agility' => 1,
|
|
'chi' => 1,
|
|
'techniques' => [
|
|
'/api/techniques/' . $tech->getId()
|
|
->toBase32()
|
|
]
|
|
]
|
|
]);
|
|
|
|
$this->assertResponseStatusCodeSame(422);
|
|
}
|
|
}
|
|
|