release 0.8 (#567)

This commit is contained in:
Kevin Papst
2019-02-19 11:03:11 +01:00
committed by GitHub
parent b4f1cae323
commit 47b7046743
40 changed files with 446 additions and 341 deletions

View File

@@ -67,7 +67,7 @@ class ActivityControllerTest extends APIControllerBaseTest
$this->assertAccessIsGranted($client, $url, 'GET', $parameters);
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertInternalType('array', $result);
$this->assertIsArray($result);
$this->assertNotEmpty($result);
$this->assertEquals(count($expected), count($result));
for ($i = 0; $i < count($result); $i++) {
@@ -93,13 +93,32 @@ class ActivityControllerTest extends APIControllerBaseTest
yield ['/api/activities', ['project' => '2', 'visible' => VisibilityQuery::SHOW_HIDDEN], [[false], [true, 2]]];
}
public function testGetCollectionWithQuery()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->loadActivityTestData($client);
$query = ['order' => 'ASC', 'orderBy' => 'project', 'globalsFirst' => 'false'];
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/activities', 'GET', $query);
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertIsArray($result);
$this->assertNotEmpty($result);
$this->assertEquals(5, count($result));
$this->assertStructure($result[0], false);
$this->assertEquals(1, $result[2]['project']);
$this->assertEquals(2, $result[3]['project']);
$this->assertEquals(2, $result[4]['project']);
}
public function testGetEntity()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/activities/1');
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertInternalType('array', $result);
$this->assertIsArray($result);
$expectedKeys = ['id', 'name', 'comment', 'visible'];
$actual = array_keys($result);

View File

@@ -35,7 +35,7 @@ class ApiDocControllerTest extends ControllerBaseTest
$this->assertAccessIsGranted($client, '/api/doc.json');
$this->assertContains('"title":"Kimai 2 - API Docs"', $client->getResponse()->getContent());
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertInternalType('array', $result);
$this->assertIsArray($result);
$this->assertNotEmpty($result);
}

View File

@@ -28,7 +28,20 @@ class CustomerControllerTest extends APIControllerBaseTest
$this->assertAccessIsGranted($client, '/api/customers');
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertInternalType('array', $result);
$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);
@@ -40,7 +53,7 @@ class CustomerControllerTest extends APIControllerBaseTest
$this->assertAccessIsGranted($client, '/api/customers/1');
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertInternalType('array', $result);
$this->assertIsArray($result);
$this->assertStructure($result, true);
}

View File

@@ -29,7 +29,7 @@ class HealthcheckControllerTest extends APIControllerBaseTest
$this->assertAccessIsGranted($client, '/api/ping');
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertInternalType('array', $result);
$this->assertIsArray($result);
$this->assertEquals(['message' => 'pong'], $result);
}
@@ -39,7 +39,7 @@ class HealthcheckControllerTest extends APIControllerBaseTest
$this->assertAccessIsGranted($client, '/api/version');
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertInternalType('array', $result);
$this->assertIsArray($result);
$this->assertArrayHasKey('version', $result);
$this->assertArrayHasKey('candidate', $result);

View File

@@ -32,7 +32,7 @@ class ProjectControllerTest extends APIControllerBaseTest
$this->assertAccessIsGranted($client, '/api/projects');
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertInternalType('array', $result);
$this->assertIsArray($result);
$this->assertNotEmpty($result);
$this->assertEquals(1, count($result));
$this->assertStructure($result[0], false);
@@ -81,7 +81,7 @@ class ProjectControllerTest extends APIControllerBaseTest
$this->assertAccessIsGranted($client, $url, 'GET', $parameters);
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertInternalType('array', $result);
$this->assertIsArray($result);
$this->assertEquals(count($expected), count($result), 'Found wrong amount of projects');
for ($i = 0; $i < count($expected); $i++) {
@@ -111,7 +111,7 @@ class ProjectControllerTest extends APIControllerBaseTest
$this->assertAccessIsGranted($client, '/api/projects/1');
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertInternalType('array', $result);
$this->assertIsArray($result);
$this->assertStructure($result);
}

View File

@@ -14,6 +14,7 @@ use App\Entity\Customer;
use App\Entity\Project;
use App\Entity\User;
use App\Tests\DataFixtures\TimesheetFixtures;
use Symfony\Component\HttpFoundation\Response;
/**
* @coversDefaultClass \App\API\TimesheetController
@@ -118,7 +119,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testGetCollectionWithQuery()
{
$query = ['customer' => 1, 'project' => 1, 'page' => 2, 'size' => 5, 'order' => 'DESC', 'orderBy' => 'rate'];
$query = ['customer' => 1, 'project' => 1, 'activity' => 1, 'page' => 2, 'size' => 5, 'order' => 'DESC', 'orderBy' => 'rate'];
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
$result = json_decode($client->getResponse()->getContent(), true);
@@ -218,24 +219,6 @@ class TimesheetControllerTest extends APIControllerBaseTest
$this->assertApiCallValidationError($client->getResponse(), ['activity']);
}
public function testPostActionWithIdIsNotAllowed()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$data = [
'id' => 1,
'activity' => 1,
'project' => 1,
'begin' => (new \DateTime('- 8 hours'))->format('Y-m-d H:m'),
'end' => (new \DateTime())->format('Y-m-d H:m'),
'description' => 'foo',
'fixedRate' => 2016,
'hourlyRate' => 127
];
$this->request($client, '/api/timesheets', 'POST', [], json_encode($data));
$this->assertFalse($client->getResponse()->isSuccessful());
$this->assertEquals(400, $client->getResponse()->getStatusCode());
}
public function testNotFound()
{
$this->assertEntityNotFound(User::ROLE_USER, '/api/timesheets/20');
@@ -263,6 +246,38 @@ class TimesheetControllerTest extends APIControllerBaseTest
$this->assertEquals(1, $result['exported']);
}
public function testPatchActionWithInvalidUser()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new TimesheetFixtures();
$fixture
->setFixedRate(true)
->setHourlyRate(true)
->setAmount(10)
->setUser($this->getUserByRole($em, User::ROLE_TEAMLEAD))
->setStartDate(new \DateTime('-10 days'))
->setAllowEmptyDescriptions(false)
;
$this->importFixture($em, $fixture);
$data = [
'activity' => 1,
'project' => 1,
'begin' => (new \DateTime('- 7 hours'))->format('Y-m-d H:m'),
'end' => (new \DateTime())->format('Y-m-d H:m'),
'description' => 'foo',
'exported' => true,
];
$this->request($client, '/api/timesheets/15', 'PATCH', [], json_encode($data));
$response = $client->getResponse();
$this->assertFalse($response->isSuccessful());
$this->assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode());
$json = json_decode($response->getContent(), true);
$this->assertEquals('User cannot update timesheet', $json['message']);
}
public function testInvalidPatchAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);

View File

@@ -29,7 +29,7 @@ class UserControllerTest extends APIControllerBaseTest
$this->assertAccessIsGranted($client, '/api/users');
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertInternalType('array', $result);
$this->assertIsArray($result);
$this->assertNotEmpty($result);
$this->assertEquals(6, count($result));
$this->assertStructure($result[0], false);
@@ -41,7 +41,7 @@ class UserControllerTest extends APIControllerBaseTest
$this->assertAccessIsGranted($client, '/api/users/1');
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertInternalType('array', $result);
$this->assertIsArray($result);
$this->assertStructure($result);
}

View File

@@ -48,7 +48,7 @@ class CalendarControllerTest extends ControllerBaseTest
$response = $client->getResponse();
$this->assertTrue($response->isSuccessful());
$json = json_decode($response->getContent(), true);
$this->assertInternalType('array', $json);
$this->assertIsArray($json);
$this->assertEmpty($json);
}
@@ -68,11 +68,11 @@ class CalendarControllerTest extends ControllerBaseTest
$response = $client->getResponse();
$this->assertTrue($response->isSuccessful());
$json = json_decode($response->getContent(), true);
$this->assertInternalType('array', $json);
$this->assertIsArray($json);
$this->assertNotEmpty($json);
$this->assertEquals(10, count($json));
foreach ($json as $result) {
$this->assertInternalType('array', $result);
$this->assertIsArray($result);
$this->assertCalendarStructure($result);
}
}

View File

@@ -63,6 +63,7 @@ class TimesheetFixtures extends Fixture
public function setAllowEmptyDescriptions(bool $allowEmptyDescriptions)
{
$this->allowEmptyDescriptions = $allowEmptyDescriptions;
return $this;
}

View File

@@ -28,13 +28,13 @@ class ServiceInvoiceTest extends TestCase
$sut = new ServiceInvoice($repo);
$this->assertEmpty($sut->getCalculator());
$this->assertInternalType('array', $sut->getCalculator());
$this->assertIsArray($sut->getCalculator());
$this->assertEmpty($sut->getRenderer());
$this->assertInternalType('array', $sut->getRenderer());
$this->assertIsArray($sut->getRenderer());
$this->assertEmpty($sut->getNumberGenerator());
$this->assertInternalType('array', $sut->getNumberGenerator());
$this->assertIsArray($sut->getNumberGenerator());
$this->assertEmpty($sut->getDocuments());
$this->assertInternalType('array', $sut->getDocuments());
$this->assertIsArray($sut->getDocuments());
$this->assertNull($sut->getCalculatorByName('default'));
$this->assertNull($sut->getDocumentByName('default'));

View File

@@ -33,7 +33,7 @@ class InvoiceModelTest extends TestCase
$this->assertNull($sut->getQuery());
$this->assertNull($sut->getDueDate());
$this->assertEmpty($sut->getEntries());
$this->assertInternalType('array', $sut->getEntries());
$this->assertIsArray($sut->getEntries());
$this->assertInstanceOf(\DateTime::class, $sut->getInvoiceDate());
}

View File

@@ -23,7 +23,7 @@ class YearTest extends TestCase
$sut = new Year('1999');
$this->assertNull($sut->getMonth('01'));
$this->assertEmpty($sut->getMonths());
$this->assertInternalType('array', $sut->getMonths());
$this->assertIsArray($sut->getMonths());
$this->assertEquals('1999', $sut->getYear());
}

View File

@@ -36,7 +36,7 @@ class InvoiceDocumentRepositoryTest extends TestCase
{
$sut = new InvoiceDocumentRepository([]);
$this->assertEmpty($sut->findAll());
$this->assertInternalType('array', $sut->findAll());
$this->assertIsArray($sut->findAll());
$this->assertNull($sut->findByName('default'));
}

View File

@@ -45,7 +45,7 @@ class TimesheetRepositoryTest extends AbstractRepositoryTest
$query->setResultType(BaseQuery::RESULT_TYPE_OBJECTS);
$result = $repository->findByQuery($query);
$this->assertInternalType('array', $result);
$this->assertIsArray($result);
}
public function testStoppedEntriesCannotBeStoppedAgain()

View File

@@ -220,7 +220,7 @@ class ExtensionsTest extends TestCase
foreach ($icons as $icon) {
$result = $sut->icon($icon);
$this->assertNotEmpty($result, 'Problem with icon definition: ' . $icon);
$this->assertInternalType('string', $result);
$this->assertIsString($result);
}
// test fallback will be returned

View File

@@ -20,6 +20,8 @@ class DurationTest extends TestCase
public function testFormat()
{
$sut = new Duration();
$this->assertNull($sut->format(null));
$this->assertEquals('02:38', $sut->format(9494));
$this->assertEquals('02:38:14', $sut->format(9494, Duration::FORMAT_WITH_SECONDS));
}
@@ -73,7 +75,7 @@ class DurationTest extends TestCase
['13', Duration::FORMAT_COLON],
['13-13', Duration::FORMAT_COLON],
['13.13', Duration::FORMAT_COLON],
[1111, 1111, Duration::FORMAT_NATURAL],
[1111, Duration::FORMAT_NATURAL],
// invalid modes
[17, 'foo'],

View File

@@ -142,6 +142,7 @@ class LocaleSettingsTest extends TestCase
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Unknown locale given: xx
*/
public function testInvalidLocaleWithGivenLocale()
{
@@ -197,4 +198,16 @@ class LocaleSettingsTest extends TestCase
$this->assertEquals('YYYY-MM-DD HH:mm', $sut->getDateTimePickerFormat());
$this->assertEquals('DD.MM.YYYY HH:mm', $sut->getDateTimePickerFormat('de'));
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Unknown setting for locale en: date_time_picker
*/
public function testUnknownSetting()
{
$sut = $this->getSut('en', ['en' => [
'xxx' => 'dd.MM.yyyy HH:mm',
]]);
$sut->getDateTimePickerFormat('en');
}
}

View File

@@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase;
/**
* @covers \App\Utils\Markdown
* @covers \App\Utils\ParsedownExtension
*/
class MarkdownTest extends TestCase
{
@@ -51,6 +52,26 @@ sdfsdf [asdfasdf](#test-1) asdfasdf
# test
aasdfasdf
EOT;
$this->assertEquals($html, $sut->toHtml($markdown));
}
public function testDuplicateIds()
{
$sut = new Markdown();
$html = <<<'EOT'
<h1 id="test">test</h1>
<h2 id="test-1">test</h2>
<h3 id="test-2">test</h3>
<h1 id="test-3">test</h1>
EOT;
$markdown = <<<EOT
# test
## test
### test
# test
EOT;
$this->assertEquals($html, $sut->toHtml($markdown));
}