Skip to content

Commit

Permalink
Merge pull request #17 from OS2Forms/46515_starting_girutils_test_suite
Browse files Browse the repository at this point in the history
[46515]  GIRUtils test suite started
  • Loading branch information
agger-magenta authored Nov 8, 2021
2 parents f7871d1 + ee57f81 commit 914634d
Show file tree
Hide file tree
Showing 15 changed files with 422 additions and 136 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
# Ignore composer.lock & vendor/
composer.lock
vendor/

# Ignore Vim swap files.
*.swp
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ before_install:
- echo "memory_limit=2G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini

install:
- composer global require drush/drush:8.x-dev drupal/coder mglaman/drupal-check friendsoftwig/twigcs codeception/codeception codeception/module-asserts codeception/module-phpbrowser
- composer global require drush/drush:8.x-dev drupal/coder mglaman/drupal-check friendsoftwig/twigcs codeception/codeception codeception/module-asserts codeception/module-phpbrowser droptica/codeception-drupal-bootstrap:dev-codeception codeception/module-db -W
- export PATH="$HOME/.config/composer/vendor/bin:$PATH"
- phpcs --config-set installed_paths ../../drupal/coder/coder_sniffer
- phpenv rehash
Expand Down Expand Up @@ -38,6 +38,6 @@ script:
- eslint $DRUPAL_ROOT/modules/contrib/os2forms_egir
- stylelint --aei $DRUPAL_ROOT/modules/contrib/os2forms_egir/**/*.css
- drupal-check $DRUPAL_ROOT/modules/contrib/os2forms_egir
- cd $PROJECT_PATH
- codecept run unit
# - cd $PROJECT_PATH
# - codecept run unit

5 changes: 5 additions & 0 deletions codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ paths:
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
lint: true
report_useless_tests: true
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed
coverage:
enabled: true
84 changes: 46 additions & 38 deletions os2forms_egir.module
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ function os2forms_egir_gir_approver_is_initiator($processID, $queueID) {
function os2forms_egir_gir_change_org_unit($processID, $queueID) {
// Get ID for webform which spawned this process.
$sid = MaestroEngine::getEntityIdentiferByUniqueID($processID, 'submission');

$utils = new GIRUtils();

if ($sid) {

$webform_submission = WebformSubmission::load($sid);
Expand All @@ -140,7 +143,7 @@ function os2forms_egir_gir_change_org_unit($processID, $queueID) {
$validity = ['from' => $start_date, 'to' => $end_date];

// Org Unit edit details.
$org_unit_uuid = GIRUtils::getTermData($org_unit_id, 'field_uuid');
$org_unit_uuid = $utils->getTermData($org_unit_id, 'field_uuid');

$ou_edit = [
'type' => 'org_unit',
Expand All @@ -154,11 +157,11 @@ function os2forms_egir_gir_change_org_unit($processID, $queueID) {
// Owner edit details.
// We need the UUID of the owner *object*.
$owner_path = '/service/ou/' . $org_unit_uuid . '/details/owner';
$owner_json = GIRUtils::getJsonFromApi($owner_path);
$owner_json = $utils->getJsonFromApi($owner_path);
$owner_obj_uuid = reset($owner_json)["uuid"];

// And then the UUID of the owner person.
$owner_person_uuid = GIRUtils::getUserData($owner_id, 'field_uuid');
$owner_person_uuid = $utils->getUserData($owner_id, 'field_uuid');

$owner_edit = [
'type' => 'owner',
Expand All @@ -172,9 +175,9 @@ function os2forms_egir_gir_change_org_unit($processID, $queueID) {

$edit_data = [$ou_edit, $owner_edit];
$json_data = json_encode($edit_data);
GIRUtils::formsLog()->notice('Edit data sent: <' . $json_data . '>');
$utils->formsLog()->notice('Edit data sent: <' . $json_data . '>');

$resp = GIRUtils::postJsonToApi('/service/details/edit', $json_data);
$resp = $utils->postJsonToApi('/service/details/edit', $json_data);

if ($resp->getStatusCode() === 200) {
$url_status = 'Success';
Expand All @@ -198,6 +201,7 @@ function os2forms_egir_gir_change_org_unit($processID, $queueID) {
function os2forms_egir_gir_change_external($processID, $queueID) {
// Get ID for webform which spawned this process.
$sid = MaestroEngine::getEntityIdentiferByUniqueID($processID, 'submission');
$utils = new GIRUtils();
if ($sid) {

$webform_submission = WebformSubmission::load($sid);
Expand Down Expand Up @@ -227,16 +231,16 @@ function os2forms_egir_gir_change_external($processID, $queueID) {
else {
return FALSE;
}
GIRUtils::formsLog()->notice(var_export($values, TRUE));
GIRUtils::formsLog()->notice(var_export($extra_uuids, TRUE));
$utils->formsLog()->notice(var_export($values, TRUE));
$utils->formsLog()->notice(var_export($extra_uuids, TRUE));
// Config.
$config = new EGIRConfig();

// Validity.
$validity = ['from' => $start_date, 'to' => $end_date];

// Employee edit details.
$external_uuid = GIRUtils::getUserData($external_id, 'field_uuid');
$external_uuid = $utils->getUserData($external_id, 'field_uuid');
$empl_edit = [
'type' => 'employee',
'uuid' => $external_uuid,
Expand Down Expand Up @@ -268,8 +272,8 @@ function os2forms_egir_gir_change_external($processID, $queueID) {
];

// Employment edit details.
$consultancy_uuid = GIRUtils::getTermData($consultancy_id, 'field_uuid');
$consultant_type_uuid = GIRUtils::getTermData($consultant_type_id, 'field_uuid');
$consultancy_uuid = $utils->getTermData($consultancy_id, 'field_uuid');
$consultant_type_uuid = $utils->getTermData($consultant_type_id, 'field_uuid');
$engagement_edit = [
'type' => 'engagement',
'uuid' => $extra_uuids['engagement_uuid'],
Expand All @@ -287,9 +291,9 @@ function os2forms_egir_gir_change_external($processID, $queueID) {
$engagement_edit,
];
$json_data = json_encode($edit_data);
GIRUtils::formsLog()->notice('Edit data sent:' . var_export($json_data, TRUE));
$utils->formsLog()->notice('Edit data sent:' . var_export($json_data, TRUE));

$resp = GIRUtils::postJsonToApi('/service/details/edit', $json_data);
$resp = $utils->postJsonToApi('/service/details/edit', $json_data);

if ($resp->getStatusCode() === 200) {
$url_status = 'Success';
Expand All @@ -313,6 +317,7 @@ function os2forms_egir_gir_change_external($processID, $queueID) {
function os2forms_egir_gir_disable_org_unit($processID, $queueID) {
// Get ID for webform which spawned this process.
$sid = MaestroEngine::getEntityIdentiferByUniqueID($processID, 'submission');
$utils = new GIRUtils();
if ($sid) {

$webform_submission = WebformSubmission::load($sid);
Expand All @@ -332,12 +337,12 @@ function os2forms_egir_gir_disable_org_unit($processID, $queueID) {
// We terminate *from* end_date *to* infinity.
// NB: This kind of validity payload is only possible as of MO ^2.0!
$validity = ['validity' => ['from' => $end_date, 'to' => NULL]];
$org_unit_uuid = GIRUtils::getTermData($org_unit_id, 'field_uuid');
$org_unit_uuid = $utils->getTermData($org_unit_id, 'field_uuid');

$json_data = json_encode($validity);
GIRUtils::formsLog()->notice('Termination data sent: <' . $json_data . '>');
$utils->formsLog()->notice('Termination data sent: <' . $json_data . '>');

$resp = GIRUtils::postJsonToApi("/service/ou/{$org_unit_uuid}/terminate", $json_data);
$resp = $utils->postJsonToApi("/service/ou/{$org_unit_uuid}/terminate", $json_data);

if ($resp->getStatusCode() === 200) {
$url_status = 'Success';
Expand Down Expand Up @@ -378,12 +383,12 @@ function os2forms_egir_gir_disable_external($processID, $queueID) {
else {
return FALSE;
}
$external_uuid = GIRUtils::getUserData($external_id, 'field_uuid');
$external_uuid = $utils->getUserData($external_id, 'field_uuid');
// Unfortunately, terminating *from* end date *to* infinity is currently
// not possible from this endpoint. We use the old way.
$validity = ['validity' => ['to' => $end_date]];
$json_data = json_encode($validity);
$resp = GIRUtils::postJsonToApi("/service/e/{$external_uuid}/terminate", $json_data);
$resp = $utils->postJsonToApi("/service/e/{$external_uuid}/terminate", $json_data);

if ($resp->getStatusCode() === 200) {
$url_status = 'Success';
Expand All @@ -407,6 +412,7 @@ function os2forms_egir_gir_disable_external($processID, $queueID) {
function os2forms_egir_gir_create_org_unit($processID, $queueID) {
// Get ID for webform which spawned this process.
$sid = MaestroEngine::getEntityIdentiferByUniqueID($processID, 'submission');
$utils = new GIRUtils();
if ($sid) {

$webform_submission = WebformSubmission::load($sid);
Expand Down Expand Up @@ -437,7 +443,7 @@ function os2forms_egir_gir_create_org_unit($processID, $queueID) {
$validity = ['from' => $start_date, 'to' => $end_date];

// Owner data.
$owner_uuid = GIRUtils::getUserData($owner_id, 'field_uuid');
$owner_uuid = $utils->getUserData($owner_id, 'field_uuid');
$owner_details = [
'type' => 'owner',
'owner' => ['uuid' => $owner_uuid],
Expand All @@ -456,9 +462,9 @@ function os2forms_egir_gir_create_org_unit($processID, $queueID) {
];

$json_data = json_encode($ou_data);
GIRUtils::formsLog()->notice('Org unit sent: <' . $json_data . '>');
$utils->formsLog()->notice('Org unit sent: <' . $json_data . '>');

$resp = GIRUtils::postJsonToApi('/service/ou/create', $json_data);
$resp = $utils->postJsonToApi('/service/ou/create', $json_data);

if ($resp->getStatusCode() === 201) {
$url_status = 'Success';
Expand All @@ -482,6 +488,7 @@ function os2forms_egir_gir_create_org_unit($processID, $queueID) {
function os2forms_egir_gir_create_external($processID, $queueID) {
// Get ID for webform which spawned this process.
$sid = MaestroEngine::getEntityIdentiferByUniqueID($processID, 'submission');
$utils = new GIRUtils();
if ($sid) {

$webform_submission = WebformSubmission::load($sid);
Expand Down Expand Up @@ -517,9 +524,9 @@ function os2forms_egir_gir_create_external($processID, $queueID) {
$validity = ['from' => $start_date, 'to' => $end_date];

// Get consultancy data MO UUIDs.
$consultancy_uuid = GIRUtils::getTermData($consultancy_id, 'field_uuid');
$consultant_type_uuid = GIRUtils::getTermData($consultant_type_id, 'field_uuid');
$cost_center_uuid = GIRUtils::getTermData($cost_center_id, 'field_uuid');
$consultancy_uuid = $utils->getTermData($consultancy_id, 'field_uuid');
$consultant_type_uuid = $utils->getTermData($consultant_type_id, 'field_uuid');
$cost_center_uuid = $utils->getTermData($cost_center_id, 'field_uuid');

// Generate employment UUID.
$employment_uuid = Uuid::uuid4()->toString();
Expand Down Expand Up @@ -568,7 +575,7 @@ function os2forms_egir_gir_create_external($processID, $queueID) {

// Remaining engagement associations.
foreach ($org_units as $ou) {
$ou_uuid = GIRUtils::getTermData($ou, 'field_uuid');
$ou_uuid = $utils->getTermData($ou, 'field_uuid');
array_push($details,
[
'type' => 'engagement_association',
Expand All @@ -588,11 +595,11 @@ function os2forms_egir_gir_create_external($processID, $queueID) {
];

$json_data = json_encode($external_data);
GIRUtils::formsLog()->notice('External sent: <' . $json_data . '>');
$utils->formsLog()->notice('External sent: <' . $json_data . '>');

// Param ?force=true is required because we create engagements and
// engagement associations, which are interdependent, at the same time.
$resp = GIRUtils::postJsonToApi('/service/e/create?force=true', $json_data);
$resp = $utils->postJsonToApi('/service/e/create?force=true', $json_data);

if ($resp->getStatusCode() === 201) {
$url_status = 'Success';
Expand All @@ -617,6 +624,7 @@ function os2forms_egir_gir_create_external($processID, $queueID) {
*/
function os2forms_egir_gir_move_external($processID, $queueID) {
$sid = MaestroEngine::getEntityIdentiferByUniqueID($processID, 'submission');
$utils = new GIRUtils();
if ($sid) {

$webform_submission = WebformSubmission::load($sid);
Expand All @@ -639,14 +647,14 @@ function os2forms_egir_gir_move_external($processID, $queueID) {
return FALSE;
}
$engagement_uuid = $extra_uuids['engagement_uuid'];
$old_ou_uuid = GIRUtils::getTermData($old_ou_id, 'field_uuid');
$new_ou_uuid = GIRUtils::getTermData($new_ou_id, 'field_uuid');
$ea_edit = GIRUtils::getMoveData($engagement_uuid, $old_ou_uuid, $new_ou_uuid);
$old_ou_uuid = $utils->getTermData($old_ou_id, 'field_uuid');
$new_ou_uuid = $utils->getTermData($new_ou_id, 'field_uuid');
$ea_edit = $utils->getMoveData($engagement_uuid, $old_ou_uuid, $new_ou_uuid);
$json_data = json_encode($ea_edit);
$json_log = var_export($json_data, TRUE);
GIRUtils::formsLog()->notice("Edit data sent: {$json_log}");
$utils->formsLog()->notice("Edit data sent: {$json_log}");

$resp = GIRUtils::postJsonToApi('/service/details/edit', $json_data);
$resp = $utils->postJsonToApi('/service/details/edit', $json_data);

if ($resp->getStatusCode() === 200) {
$url_status = 'Success';
Expand Down Expand Up @@ -689,24 +697,24 @@ function os2forms_egir_gir_move_many_externals($processID, $queueID) {
}

// Org unit UUIDs.
$old_ou_uuid = GIRUtils::getTermData($old_ou_id, 'field_uuid');
$new_ou_uuid = GIRUtils::getTermData($new_ou_id, 'field_uuid');
$old_ou_uuid = $utils->getTermData($old_ou_id, 'field_uuid');
$new_ou_uuid = $utils->getTermData($new_ou_id, 'field_uuid');

// Edit payload data.
$edit_data = [];
foreach ($externals as $external_id) {
$external_uuid = GIRUtils::getUserData($external_id, 'field_uuid');
$engagement_uuid = GIRUtils::getEngagement($external_uuid)['uuid'];
$move_data = GIRUtils::getMoveData($engagement_uuid, $old_ou_uuid, $new_ou_uuid);
$external_uuid = $utils->getUserData($external_id, 'field_uuid');
$engagement_uuid = $utils->getEngagement($external_uuid)['uuid'];
$move_data = $utils->getMoveData($engagement_uuid, $old_ou_uuid, $new_ou_uuid);
// We need to flatten $move_data.
$edit_data[] = array_merge(...$move_data);
}

$json_data = json_encode($edit_data);
$json_log = var_export($json_data, TRUE);
GIRUtils::formsLog()->notice("Edit data sent: {$json_log}");
$utils->formsLog()->notice("Edit data sent: {$json_log}");

$resp = GIRUtils::postJsonToApi('/service/details/edit', $json_data);
$resp = $utils->postJsonToApi('/service/details/edit', $json_data);

if ($resp->getStatusCode() === 200) {
$url_status = 'Success';
Expand Down
4 changes: 3 additions & 1 deletion src/Feeds/Fetcher/KeycloakAuthFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ public function fetch(FeedInterface $feed, StateInterface $state) {
$sink = $this->fileSystem->tempnam('temporary://', 'feeds_http_fetcher');
$sink = $this->fileSystem->realpath($sink);

$utils = new GIRUtils();

$response = $this->get(
$feed->getSource(), $sink,
$this->getCacheKey($feed), GIRUtils::getOpenIdToken()
$this->getCacheKey($feed), $utils->getOpenIdToken()
);
// @todo Handle redirects.
// @codingStandardsIgnoreStart
Expand Down
Loading

0 comments on commit 914634d

Please sign in to comment.