Skip to content

Commit

Permalink
unit test optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
ferishili committed Jul 21, 2023
1 parent 09ab83f commit cb2dd3b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
8 changes: 4 additions & 4 deletions tests/DataProvider/EventsDataProvider.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
<?php
namespace Tests\DataProvider;
use GuzzleHttp\Psr7;

class EventsDataProvider {

public static function getAllCases(): array
{
return [
Expand Down Expand Up @@ -41,7 +41,7 @@ public static function getAcls()

public static function getMetadata($title)
{
return '[{"label":"Opencast Series Dublincore","flavor":"dublincore\/episode","fields":[{"id":"title","value":"PHP UNIT TEST_' . strtotime('now') . '_' . strtoupper($title) . '_{update_replace}"},{"id":"subjects","value":["This is default subject"]},{"id":"description","value":"This is a default description for video"},{"id":"startDate","value":"' . date('Y-m-d') . '"},{"id":"startTime","value":"' . date('H:i:s') . 'Z"}]}]';
return '[{"label":"Opencast Event Dublincore","flavor":"dublincore\/episode","fields":[{"id":"title","value":"PHP UNIT TEST_' . strtotime('now') . '_' . strtoupper($title) . '_{update_replace}"},{"id":"subjects","value":["This is default subject"]},{"id":"description","value":"This is a default description for video"},{"id":"startDate","value":"' . date('Y-m-d') . '"},{"id":"startTime","value":"' . date('H:i:s') . 'Z"}]}]';
}

public static function getProcessing()
Expand Down Expand Up @@ -69,4 +69,4 @@ public static function getVttFile()
return Psr7\Utils::tryFopen(__DIR__ . '/test_files/video_test_de.vtt', 'r');
}
}
?>
?>
1 change: 1 addition & 0 deletions tests/Unit/OcEventsApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public function create_and_update_event(string $createdEventIdentifier): string
$this->assertContains($responseCreate['code'], [200, 201], 'Failure to create an event');
$createdEventIdentifier = $responseCreate['body']->identifier;
$this->assertNotEmpty($createdEventIdentifier);
sleep(5);

$metadata = str_replace(
'{update_replace}',
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/OcGroupsApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function empty_created_id(): string
*/
public function create_get_update_delete_group(string $identifier): string
{
$name = 'PHPUNIT_TESTING_GROUP';
$name = 'PHPUNIT_TESTING_GROUP_' . uniqid();
// Get the group.
$response0 = $this->ocGroupsApi->get(strtolower($name));
if ($response0['code'] == 404) {
Expand Down
19 changes: 17 additions & 2 deletions tests/Unit/OcWorkflowsApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,21 @@ public function get_definition_run_update_delete_workflow(): void
{
$data = [];
// Get event
$response0 = $this->ocEventsApi->getAll();
$response0 = $this->ocEventsApi->getAll(
['withpublications' => true]
);
$this->assertSame(200, $response0['code'], 'Failure to get events for the workflows!');
$events = $response0['body'];
$event = $events[array_rand($events)];
$event = null;
foreach ($events as $ev) {
if ($ev->status === "EVENTS.EVENTS.STATUS.PROCESSED") {
$event = $ev;
break;
}
}
if (empty($event)) {
$this->markTestSkipped('No proper event found to apply workflow!');
}
$this->assertNotEmpty($event);
$data['event_identifier'] = $event->identifier;

Expand Down Expand Up @@ -70,18 +81,22 @@ public function get_definition_run_update_delete_workflow(): void
$this->assertSame(201, $response3['code'], 'Failure to create (run) a workflow');
$workflowId = $response3['body'];
$this->assertNotEmpty($workflowId);
sleep(1);

// Get the workflow.
$response4 = $this->ocWorkflowsApi->get($workflowId->identifier, true, true);
$this->assertSame(200, $response4['code'], 'Failure to get a workflow');
sleep(1);

// Update workflow.
$response5 = $this->ocWorkflowsApi->update($workflowId->identifier, 'stopped');
$this->assertSame(200, $response5['code'], 'Failure to update a workflow');
sleep(1);

// Delete the workflow.
$response6 = $this->ocWorkflowsApi->delete($workflowId->identifier);
$this->assertSame(204, $response6['code'], 'Failure to delete a workflow');
sleep(1);
}
}
?>

0 comments on commit cb2dd3b

Please sign in to comment.