Skip to content

Commit

Permalink
Test list and show groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Jan 11, 2024
1 parent 93a3f72 commit 62ab4a9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
14 changes: 10 additions & 4 deletions tests/End2End/ClientTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Redmine\Tests\End2End;

use DateTimeImmutable;
use PDO;
use PHPUnit\Framework\TestCase;
use Redmine\Client\NativeCurlClient;
Expand All @@ -24,6 +25,7 @@ public function setUp(): void
// Create backup of database
copy($this->sqliteFile, $this->sqliteBackup);

$now = new DateTimeImmutable();
$pdo = new PDO('sqlite:' . $this->sqliteFile);

// Get admin user to check sqlite connection
Expand All @@ -36,8 +38,12 @@ public function setUp(): void
$stmt->execute([':id' => $adminUser['id'], ':must_change_passwd' => 0]);

// Enable rest api
$stmt = $pdo->prepare('INSERT INTO settings(name, value) VALUES(:name, :value);');
$stmt->execute([':name' => 'rest_api_enabled', ':value' => 1]);
$stmt = $pdo->prepare('INSERT INTO settings(name, value, updated_on) VALUES(:name, :value, :updated_on);');
$stmt->execute([
':name' => 'rest_api_enabled',
':value' => 1,
':updated_on' => $now->format('Y-m-d H:i:s.u'),
]);

$this->apiKey = sha1((string) time());

Expand All @@ -47,8 +53,8 @@ public function setUp(): void
':user_id' => $adminUser['id'],
':action' => 'api',
':value' => $this->apiKey,
':created_on' => $adminUser['last_login_on'],
':updated_on' => $adminUser['last_login_on'],
':created_on' => $now->format('Y-m-d H:i:s.u'),
':updated_on' => $now->format('Y-m-d H:i:s.u'),
]);
}

Expand Down
37 changes: 35 additions & 2 deletions tests/End2End/Group/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,49 @@ public function testInteractionWithGroup(): void

/** @var Group */
$groupApi = $client->getApi('group');
$now = new DateTimeImmutable();

// Create group
$groupName = 'test group ' . $now->format('Y-m-d H:i:s');

$xmlData = $groupApi->create([
'name' => 'test group ' . (new DateTimeImmutable())->format('Y-m-d H:i:s'),
'name' => $groupName,
]);

$data = json_decode(json_encode($xmlData), true);

$this->assertIsArray($data, json_encode($data));
$this->assertIsString($data['id']);
$this->assertStringStartsWith('test group ', $data['name']);
$this->assertSame($groupName, $data['name']);

$groupId = (int) $data['id'];

// List groups
$data = $groupApi->list();

$this->assertSame(
[
'groups' => [
[
'id' => $groupId,
'name' => $groupName,
],
],
],
$data
);

// Read group
$data = $groupApi->show($groupId);

$this->assertSame(
[
'group' => [
'id' => $groupId,
'name' => $groupName,
]
],
$data
);
}
}

0 comments on commit 62ab4a9

Please sign in to comment.