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.
135 lines
4.3 KiB
135 lines
4.3 KiB
10 months ago
|
<?php
|
||
|
namespace App\Tests;
|
||
|
|
||
|
use App\Factory\TechniqueFactory;
|
||
|
|
||
|
class TechniqueTest extends AbstractTest
|
||
|
{
|
||
|
|
||
|
public function testListTechniques(): void
|
||
|
{
|
||
|
TechniqueFactory::createMany(10, [
|
||
|
'prerequisite' => NULL
|
||
|
]);
|
||
|
|
||
|
$response = static::createClientWithToken()->request('GET', '/api/techniques');
|
||
|
$this->assertEquals(10, count($response->toArray()));
|
||
|
}
|
||
|
|
||
|
public function testListTechniquesWithPrerequisite(): void
|
||
|
{
|
||
|
$prerequisite = TechniqueFactory::createOne([
|
||
|
'prerequisite' => NULL
|
||
|
]);
|
||
|
|
||
|
TechniqueFactory::createMany(2, [
|
||
|
'prerequisite' => $prerequisite
|
||
|
]);
|
||
|
|
||
|
$response = static::createClientWithToken()->request('GET', '/api/techniques');
|
||
|
$this->assertEquals(3, count($response->toArray()));
|
||
|
}
|
||
|
|
||
|
public function testShowTechnique(): void
|
||
|
{
|
||
|
$technique = TechniqueFactory::createOne([
|
||
|
'prerequisite' => NULL
|
||
|
]);
|
||
|
|
||
|
$response = static::createClientWithToken()->request('GET',
|
||
|
'/api/techniques/' . $technique->getId()
|
||
|
->toBase32());
|
||
|
|
||
|
$this->assertJsonEquals(
|
||
|
[
|
||
|
'id' => $technique->getId()
|
||
|
->toBase32(),
|
||
|
'name' => $technique->getName(),
|
||
|
'costs' => $technique->getCosts(),
|
||
|
'damage' => $technique->getDamage(),
|
||
|
'energy' => $technique->getEnergy(),
|
||
|
'accuracy' => $technique->getAccuracy()
|
||
|
], $response->getContent());
|
||
|
}
|
||
|
|
||
|
public function testShowTechniqueWithPrerequisite(): void
|
||
|
{
|
||
|
$prerequisite = TechniqueFactory::createOne([
|
||
|
'prerequisite' => NULL
|
||
|
]);
|
||
|
|
||
|
$technique = TechniqueFactory::createOne([
|
||
|
'prerequisite' => $prerequisite
|
||
|
]);
|
||
|
|
||
|
$response = static::createClientWithToken()->request('GET',
|
||
|
'/api/techniques/' . $technique->getId()
|
||
|
->toBase32());
|
||
|
|
||
|
$this->assertJsonEquals(
|
||
|
[
|
||
|
'id' => $technique->getId()
|
||
|
->toBase32(),
|
||
|
'name' => $technique->getName(),
|
||
|
'costs' => $technique->getCosts(),
|
||
|
'damage' => $technique->getDamage(),
|
||
|
'energy' => $technique->getEnergy(),
|
||
|
'accuracy' => $technique->getAccuracy(),
|
||
|
'prerequisite' => '/api/techniques/' . $prerequisite->getId()
|
||
|
->toBase32()
|
||
|
], $response->getContent());
|
||
|
}
|
||
|
|
||
|
public function testCreateTechniqueAsAdmin(): void
|
||
|
{
|
||
|
$response = static::createClientWithToken("dehecht")->request('POST', '/api/techniques',
|
||
|
[
|
||
|
'json' => [
|
||
|
'name' => 'Drei-Schwert-Style',
|
||
|
'costs' => 2,
|
||
|
'damage' => '3 * strength',
|
||
|
'energy' => '1.5 * constitution + 2 * strength',
|
||
|
'accuracy' => '2 * agility'
|
||
|
]
|
||
|
]);
|
||
|
|
||
|
$this->assertResponseStatusCodeSame(201);
|
||
|
|
||
|
$this->assertArrayHasKey('id', $response->toArray());
|
||
|
}
|
||
|
|
||
|
public function testCreateTechniqueFailsAsUser(): void
|
||
|
{
|
||
|
static::createClientWithToken()->request('POST', '/api/techniques',
|
||
|
[
|
||
|
'json' => [
|
||
|
'name' => 'Drei-Schwert-Style',
|
||
|
'costs' => 2,
|
||
|
'damage' => '3 * strength',
|
||
|
'energy' => '1.5 * constitution + 2 * strength',
|
||
|
'accuracy' => '2 * agility'
|
||
|
]
|
||
|
]);
|
||
|
|
||
|
$this->assertResponseStatusCodeSame(403);
|
||
|
}
|
||
|
|
||
|
public function testFailToCreateTechniqueWithNonExistentPrerequisite(): void
|
||
|
{
|
||
|
$response = static::createClientWithToken("dehecht")->request('POST', '/api/techniques',
|
||
|
[
|
||
|
'json' => [
|
||
|
'name' => 'Drei-Schwert-Style',
|
||
|
'costs' => 2,
|
||
|
'damage' => '3 * strength',
|
||
|
'energy' => '1.5 * constitution + 2 * strength',
|
||
|
'accuracy' => '2 * agility',
|
||
|
'prerequisite' => '/api/techniques/01ARZ3NDEKTSV4RRFFQ69G5FAV'
|
||
|
]
|
||
|
]);
|
||
|
|
||
|
$this->assertTrue($response->getStatusCode() / 100 != 2);
|
||
|
}
|
||
|
}
|
||
|
|