Skip to content

Commit

Permalink
fixup! Adjust tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Feb 18, 2024
1 parent 8e565ee commit 3e64873
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
1 change: 1 addition & 0 deletions tests/Unit/Controller/ApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ public function dataTestCreateNewForm() {
return [
'forms' => ['expectedForm' => [
'id' => 7,
'state' => 0,
'hash' => 'formHash',
'title' => '',
'description' => '',
Expand Down
54 changes: 47 additions & 7 deletions tests/Unit/Service/FormsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public function dataGetForm() {
// Just the full form without submissions
'one-full-form' => [[
'id' => 42,
'state' => 0,
'hash' => 'abcdefg',
'title' => 'Form 1',
'description' => 'Description Text',
Expand Down Expand Up @@ -250,6 +251,7 @@ public function testGetForm(array $expected) {
// The form
$form = new Form();
$form->setId(42);
$form->setState(0); // default => 0 means active
$form->setHash('abcdefg');
$form->setTitle('Form 1');
$form->setDescription('Description Text');
Expand Down Expand Up @@ -341,13 +343,14 @@ public function dataGetPartialForm() {
return [
'onePartialOwnedForm' => [[
'id' => 42,
'state' => 0,
'hash' => 'abcdefg',
'title' => 'Form 1',
'expires' => 0,
'lastUpdated' => 123456789,
'permissions' => Constants::PERMISSION_ALL,
'submissionCount' => 123,
'partial' => true
'partial' => true,
]]
];
}
Expand All @@ -358,6 +361,7 @@ public function dataGetPartialForm() {
*/
public function testGetPartialForm(array $expected) {
$form = new Form();
$form->setState(0);
$form->setId(42);
$form->setHash('abcdefg');
$form->setTitle('Form 1');
Expand All @@ -384,7 +388,8 @@ public function dataGetPartialFormShared() {
'lastUpdated' => 123456789,
'permissions' => ['results', 'submit'],
'submissionCount' => 123,
'partial' => true
'state' => 0,
'partial' => true,
]]
];
}
Expand All @@ -397,6 +402,7 @@ public function dataGetPartialFormShared() {
public function testGetPartialFormShared(array $expected) {
$form = new Form();
$form->setId(42);
$form->setState(0);
$form->setHash('abcdefg');
$form->setTitle('Form 1');
$form->setOwnerId('otherUser');
Expand Down Expand Up @@ -428,6 +434,7 @@ public function dataGetPublicForm() {
// Bare form without questions, checking removed access & ownerId
'one-full-form' => [[
'id' => 42,
'state' => 0,
'hash' => 'abcdefg',
'title' => 'Form 1',
'description' => 'Description Text',
Expand Down Expand Up @@ -455,6 +462,7 @@ public function testGetPublicForm(array $expected) {
// The form
$form = new Form();
$form->setId(42);
$form->setState(0);
$form->setHash('abcdefg');
$form->setTitle('Form 1');
$form->setDescription('Description Text');
Expand Down Expand Up @@ -1034,6 +1042,7 @@ public function dataIsSharedFormShown() {
return [
'dontShowToOwner' => [
'ownerId' => 'currentUser',
'state' => 0,
'expires' => 0,
'access' => [
'permitAllUsers' => true,
Expand All @@ -1044,6 +1053,7 @@ public function dataIsSharedFormShown() {
],
'expiredForm' => [
'ownerId' => 'notCurrentUser',
'state' => 0,
'expires' => 1,
'access' => [
'permitAllUsers' => true,
Expand All @@ -1054,6 +1064,7 @@ public function dataIsSharedFormShown() {
],
'shownToAll' => [
'ownerId' => 'notCurrentUser',
'state' => 0,
'expires' => 0,
'access' => [
'permitAllUsers' => true,
Expand All @@ -1064,6 +1075,7 @@ public function dataIsSharedFormShown() {
],
'sharedToUser' => [
'ownerId' => 'notCurrentUser',
'state' => 0,
'expires' => 0,
'access' => [
'permitAllUsers' => false,
Expand All @@ -1074,14 +1086,37 @@ public function dataIsSharedFormShown() {
],
'notShown' => [
'ownerId' => 'notCurrentUser',
'state' => 0,
'expires' => 0,
'access' => [
'permitAllUsers' => true,
'showToAllUsers' => false,
],
'shareType' => IShare::TYPE_LINK,
'expected' => false,
]
],
'ArchivedIsNotShown' => [
'ownerId' => 'notCurrentUser',
'state' => Constants::FORM_STATE_ARCHIVED,
'expires' => 0,
'access' => [
'permitAllUsers' => true,
'showToAllUsers' => true,
],
'shareType' => IShare::TYPE_USER,
'expected' => false,
],
'ClosedIsNotShown' => [
'ownerId' => 'notCurrentUser',
'state' => Constants::FORM_STATE_CLOSED,
'expires' => 0,
'access' => [
'permitAllUsers' => true,
'showToAllUsers' => true,
],
'shareType' => IShare::TYPE_USER,
'expected' => false,
],
];
}
/**
Expand All @@ -1096,6 +1131,7 @@ public function dataIsSharedFormShown() {
public function testIsSharedFormShown(string $ownerId, int $expires, array $access, int $shareType, bool $expected) {
$form = new Form();
$form->setId(42);
$form->setState(0);
$form->setOwnerId($ownerId);
$form->setExpires($expires);
$form->setAccess($access);
Expand Down Expand Up @@ -1227,19 +1263,23 @@ public function testIsSharedToCircle_circlesDisabled() {

public function dataHasFormExpired() {
return [
'hasExpired' => [time() - 3600, true],
'hasNotExpired' => [time() + 3600, false],
'doesNeverExpire' => [0, false]
'hasExpired' => [time() - 3600, Constants::FORM_STATE_ACTIVE, true],
'hasNotExpired' => [time() + 3600, Constants::FORM_STATE_ACTIVE, false],
'doesNeverExpire' => [0, Constants::FORM_STATE_ACTIVE, false],
'isClosed' => [time() + 3600, Constants::FORM_STATE_CLOSED, true],
'isArchived' => [time() + 3600, Constants::FORM_STATE_ARCHIVED, true],
];
}
/**
* @dataProvider dataHasFormExpired
*
* @param int $expires
* @param int $state the form state
* @param bool $expected has expired
*/
public function testHasFormExpired(int $expires, bool $expected) {
public function testHasFormExpired(int $expires, int $state, bool $expected) {
$form = new Form();
$form->setState($state);
$form->setExpires($expires);

$this->assertEquals($expected, $this->formsService->hasFormExpired($form));
Expand Down

0 comments on commit 3e64873

Please sign in to comment.