Skip to content

Commit

Permalink
VACMS-18312: Aging Content Emails Sent at Midnight (#18525)
Browse files Browse the repository at this point in the history
* VACMS-18311: Add allow list to AC notifications.

* VACMS-18311: Corrects logic for restricted/allowed controls.

* VACMS-18311: Ensures that the ECA is set to run always during the tests.

* VACMS-18311: Adds allow list to tests.

* VACMS-18311: Prevent a php error when checking send permissions.

* VACMS-18311: Updates eca configs to use correct user id token.

* VACMS-18312: Set aging content workflows to trigger at midnight.

* VACMS-18312: Updates aging content workflows to be enabled.
- Updates aging content test.
  • Loading branch information
dsasser authored Jul 18, 2024
1 parent ca18912 commit e8299f7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
4 changes: 2 additions & 2 deletions config/sync/eca.eca.aging_content_expired_fwb.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
uuid: bbc82ad3-6ffd-4c88-8f06-b4a59c855f44
langcode: en
status: false
status: true
dependencies:
config:
- views.view.aging_content
Expand All @@ -19,7 +19,7 @@ events:
plugin: 'eca_base:eca_cron'
label: Cron
configuration:
frequency: '* * * * *'
frequency: '0 0 * * *'
successors:
-
id: eca_views_query
Expand Down
4 changes: 2 additions & 2 deletions config/sync/eca.eca.aging_content_warn_fwb.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
uuid: 8accd7d5-70c2-4e26-93b0-96bbbbf7562a
langcode: en
status: false
status: true
dependencies:
config:
- views.view.aging_content
Expand All @@ -19,7 +19,7 @@ events:
plugin: 'eca_base:eca_cron'
label: Cron
configuration:
frequency: '* * * * *'
frequency: '0 0 * * *'
successors:
-
id: eca_views_query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public function setUp(): void {
$this->drupalLogin($user);

$node_base = [
'title' => 'Expirable Content Test Node',
'status' => 1,
'moderation_state' => 'published',
'type' => 'banner',
Expand All @@ -46,10 +45,10 @@ public function setUp(): void {
];

foreach ($dates as $key => $date) {
$node = $this->createNode($node_base);
$node->set('field_last_saved_by_an_editor', $date);
$node->set('title', $node->getTitle() . ':' . $key);
$node->save();
$this->createNode($node_base + [
'field_last_saved_by_an_editor' => $date,
'title' => 'Expirable Content Test Node:' . $key,
]);
}
}

Expand All @@ -73,22 +72,21 @@ public function dataProvider(): array {
* @dataProvider dataProvider
*
* @throws \Behat\Mink\Exception\ResponseTextException
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public function testFullWidthBannerJobQueued(string $type) {
// Enable the ECA if it is not already.
/** @var \Drupal\eca\Entity\Eca $eca */
$eca = \Drupal::entityTypeManager()->getStorage('eca')->load("aging_content_{$type}_fwb");

$status = $eca->status();
$eca->enable();
// Ensure that the ECA model will always fire during cron.
$current_events = $events = $eca->get('events');
$events['eca_base_eca_cron']['configuration']['frequency'] = '* * * * *';
$eca->set('events', $events);
$eca->save();
$session = $this->getSession();

// Set cron frequency so that the ECA Cron Event will always fire.
$this->drupalGet("/admin/config/workflow/eca/aging_content_{$type}_fwb/event/eca_base_eca_cron/edit");
$frequencyElement = $session->getPage()->findById('edit-event-frequency');
$currentFrequency = $frequencyElement->getValue();
$frequencyElement->setValue('* * * * *');
$session->getPage()->findById('edit-actions-submit')->click();

// Enable the ECA Model if it is not already.
$this->drupalGet("/admin/config/workflow/eca/aging_content_{$type}_fwb/edit");
$session->getPage()->findById('edit-options-status')->check();
$session->getPage()->findById('edit-submit')->click();

// Run cron to queue the job.
$this->drupalGet('admin/reports/status');
Expand All @@ -98,12 +96,18 @@ public function testFullWidthBannerJobQueued(string $type) {
$this->drupalGet('admin/config/system/queues/jobs/aging_content');
$this->assertSession()->pageTextContains("Expirable Content Test Node:{$type}");

// Set ECA to previous state. This is to prevent duplicate queued items.
$eca->setStatus($status);
$eca->set('events', $current_events);
$eca->save();
// Disable the ECA Model. This is to prevent duplicate queued items.
$this->drupalGet("/admin/config/workflow/eca/aging_content_{$type}_fwb/edit");
$session->getPage()->findById('edit-options-status')->uncheck();
$session->getPage()->findById('edit-submit')->click();

// Set cron frequency back to previous state.
$this->drupalGet("/admin/config/workflow/eca/aging_content_{$type}_fwb/event/eca_base_eca_cron/edit");
$frequencyElement = $session->getPage()->findById('edit-event-frequency');
$frequencyElement->setValue($currentFrequency);
$session->getPage()->findById('edit-actions-submit')->click();

// Run cron again to execute the job, which sends the notification.
// Run cron again to process queued job, which sends the notification.
$this->drupalGet('admin/reports/status');
$this->clickLink($this->t('Run cron'));

Expand Down

0 comments on commit e8299f7

Please sign in to comment.