83 lines
2.5 KiB
PHP
83 lines
2.5 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Kimai time-tracking app.
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace App\Tests\API;
|
|
|
|
use App\Entity\User;
|
|
|
|
/**
|
|
* @coversDefaultClass \App\API\CustomerController
|
|
* @group integration
|
|
*/
|
|
class CustomerControllerTest extends APIControllerBaseTest
|
|
{
|
|
public function testIsSecure()
|
|
{
|
|
$this->assertUrlIsSecured('/api/customers');
|
|
}
|
|
|
|
public function testGetCollection()
|
|
{
|
|
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
|
$this->assertAccessIsGranted($client, '/api/customers');
|
|
$result = json_decode($client->getResponse()->getContent(), true);
|
|
|
|
$this->assertIsArray($result);
|
|
$this->assertNotEmpty($result);
|
|
$this->assertEquals(1, count($result));
|
|
$this->assertStructure($result[0], false);
|
|
}
|
|
|
|
public function testGetCollectionWithQuery()
|
|
{
|
|
$query = ['order' => 'ASC', 'orderBy' => 'name', 'visible' => 3];
|
|
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
|
$this->assertAccessIsGranted($client, '/api/customers', 'GET', $query);
|
|
$result = json_decode($client->getResponse()->getContent(), true);
|
|
|
|
$this->assertIsArray($result);
|
|
$this->assertNotEmpty($result);
|
|
$this->assertEquals(1, count($result));
|
|
$this->assertStructure($result[0], false);
|
|
}
|
|
|
|
public function testGetEntity()
|
|
{
|
|
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
|
$this->assertAccessIsGranted($client, '/api/customers/1');
|
|
$result = json_decode($client->getResponse()->getContent(), true);
|
|
|
|
$this->assertIsArray($result);
|
|
$this->assertStructure($result, true);
|
|
}
|
|
|
|
public function testNotFound()
|
|
{
|
|
$this->assertEntityNotFound(User::ROLE_USER, '/api/customers/2');
|
|
}
|
|
|
|
protected function assertStructure(array $result, $full = true)
|
|
{
|
|
$expectedKeys = ['id', 'name', 'visible'];
|
|
|
|
if ($full) {
|
|
$expectedKeys = [
|
|
'id', 'name', 'number', 'comment', 'visible', 'company', 'contact', 'address', 'country', 'currency',
|
|
'phone', 'fax', 'mobile', 'mail', 'timezone'
|
|
];
|
|
}
|
|
|
|
$actual = array_keys($result);
|
|
sort($actual);
|
|
sort($expectedKeys);
|
|
|
|
$this->assertEquals($expectedKeys, $actual, 'Customer structure does not match');
|
|
}
|
|
}
|