Skip to content
Snippets Groups Projects
Commit 7de47589 authored by Travis Carden's avatar Travis Carden Committed by Adam G-H
Browse files

Update ORCA implementation (#97)

parent 14cd53df
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@ env:
global:
- ORCA_SUT_NAME=drupal/lightning_workflow
- ORCA_SUT_BRANCH=8.x-3.x
- ORCA_VERSION=v1.0.0-alpha13
- ORCA_VERSION=v1.0.0-alpha16
matrix:
fast_finish: true
......@@ -36,6 +36,8 @@ matrix:
- env: ORCA_JOB=DEPRECATED_CODE_SCAN_CONTRIB
- env: ORCA_JOB=INTEGRATED_DEV
- env: ORCA_JOB=CORE_NEXT
# Temporary allowances.
- env: ORCA_JOB=STATIC_CODE_ANALYSIS
before_install:
- git clone --branch ${ORCA_VERSION} --depth 1 https://github.com/acquia/orca.git ../orca
......
......@@ -279,7 +279,12 @@ export default class extends Component
{
return this.state.transitions.map(t => {
return {
when: t.when.getTime() / 1000,
// JavaScript returns time stamps in millseconds, but PHP handles them
// in seconds. Divide by 1000 to convert to seconds, then round down to
// ensure we do not send a floating-point value back to the server. We
// always round down (instead of using Math.round()) to in order to
// prevent off-by-one-second timing failures in tests.
when: Math.floor(t.when.getTime() / 1000),
state: t.state,
};
});
......
This diff is collapsed.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -134,7 +134,7 @@ class TransitionManager {
return;
}
if (! is_numeric($transition['when'])) {
if (! preg_match('/^[0-9]+$/', $transition['when'])) {
$variables = [
'%when' => $transition['when'],
];
......
......@@ -60,7 +60,7 @@ class TransitionTest extends WebDriverTestBase {
$this->createTransition('Published', time() - 10);
$this->getSession()->getPage()->pressButton('Save');
$this->cronRun();
$assert_session->elementExists('css', 'a[rel="edit-form"]')->click();
$this->clickEditLink();
$assert_session->pageTextContains('Current state Published');
$assert_session->elementNotExists('css', '.scheduled-transition');
}
......@@ -75,7 +75,7 @@ class TransitionTest extends WebDriverTestBase {
$this->createTransition('Archived', time() - 10);
$this->getSession()->getPage()->pressButton('Save');
$this->cronRun();
$assert_session->elementExists('css', 'a[rel="edit-form"]')->click();
$this->clickEditLink();
// It will still be in the draft state because the transition should resolve
// to Draft -> Archived, which doesn't exist.
$assert_session->pageTextContains('Current state Draft');
......@@ -89,16 +89,16 @@ class TransitionTest extends WebDriverTestBase {
$page->selectFieldOption('moderation_state[0][state]', 'In review');
$page->pressButton('Save');
$assert_session->elementExists('css', 'a[rel="edit-form"]')->click();
$this->clickEditLink();
$this->createTransition('Published', $now + 8);
$page->pressButton('Save');
$this->setRequestTime($now + 10);
$this->cronRun();
$assert_session->elementExists('css', 'a[rel="edit-form"]')->click();
$this->clickEditLink();
$page->selectFieldOption('moderation_state[0][state]', 'Archived');
$page->pressButton('Save');
$this->cronRun();
$assert_session->elementExists('css', 'a[rel="edit-form"]')->click();
$this->clickEditLink();
$assert_session->pageTextContains('Current state Archived');
}
......@@ -113,7 +113,7 @@ class TransitionTest extends WebDriverTestBase {
$page->clickLink('Promotion options');
$page->checkField('Promoted to front page');
$page->pressButton('Save');
$assert_session->elementExists('css', 'a[rel="edit-form"]')->click();
$this->clickEditLink();
$page->fillField('Title', 'MC Hammer');
$page->selectFieldOption('moderation_state[0][state]', 'Draft');
$this->createTransition('Published', $now + 8);
......
......@@ -27,27 +27,12 @@ class TransitionManagerTest extends KernelTestBase {
'system',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig('system');
// In order to prove that time zones are normalized correctly, set the
// system default and Drupal default time zones differently.
date_default_timezone_set('UTC');
$this->config('system.date')
->set('timezone.default', 'America/New_York')
->save();
}
/**
* @covers ::validate
*
* @dataProvider providerValidate
*/
public function testValidate($value, $expect_errors) {
public function testValidate($value, $expected_error = NULL) {
$element = [
'#value' => Json::encode($value),
'#name' => 'test_element',
......@@ -59,7 +44,16 @@ class TransitionManagerTest extends KernelTestBase {
TransitionManager::validate($element, $form_state);
$this->assertSame($expect_errors, FormState::hasAnyErrors());
$errors = $form_state->getErrors();
$errors = array_map('strval', $errors);
$errors = array_map('strip_tags', $errors);
if ($expected_error) {
$this->assertContains($expected_error, $errors);
}
else {
$this->assertEmpty($errors);
}
}
/**
......@@ -71,46 +65,49 @@ class TransitionManagerTest extends KernelTestBase {
return [
'empty string' => [
'',
TRUE,
'Expected scheduled transitions to be an array.',
],
'null' => [
NULL,
TRUE,
'Expected scheduled transitions to be an array.',
],
'boolean false' => [
FALSE,
TRUE,
'Expected scheduled transitions to be an array.',
],
'boolean true' => [
TRUE,
TRUE,
'Expected scheduled transitions to be an array.',
],
'random string' => [
$this->randomString(128),
TRUE,
'Expected scheduled transitions to be an array.',
],
'integer' => [
123,
TRUE,
'Expected scheduled transitions to be an array.',
],
'float' => [
123.45,
'Expected scheduled transitions to be an array.',
],
'empty array' => [
[],
FALSE,
],
'time' => [
'time, no date' => [
[
'when' => '08:57',
],
TRUE,
'Scheduled transitions must have a date and time.',
],
'date' => [
'date, no time' => [
[
[
'state' => 'fubar',
'when' => '1984-09-19',
],
],
TRUE,
'"1984-09-19" is not a valid date and time.',
],
'date and time' => [
[
......@@ -118,7 +115,16 @@ class TransitionManagerTest extends KernelTestBase {
'when' => '1938-37-12 08:57',
],
],
TRUE,
'"1938-37-12 08:57" is not a valid date and time.',
],
'date as float' => [
[
[
'state' => 'fubar',
'when' => '123.45',
],
],
'"123.45" is not a valid date and time.',
],
'valid different time stamps, invalid order' => [
[
......@@ -131,7 +137,7 @@ class TransitionManagerTest extends KernelTestBase {
'when' => mktime(2, 30, 0, 9, 4, 2018),
],
],
TRUE,
"You cannot schedule a transition to take place before 3:42 PM on November 5, 2018.",
],
'valid same dates, valid times, invalid order' => [
[
......@@ -144,7 +150,7 @@ class TransitionManagerTest extends KernelTestBase {
'when' => mktime(4, 46, 0, 9, 19, 2022),
],
],
TRUE,
"You cannot schedule a transition to take place before 6:30 AM on September 19, 2022.",
],
'valid different dates' => [
[
......@@ -157,7 +163,6 @@ class TransitionManagerTest extends KernelTestBase {
'when' => mktime(15, 42, 0, 11, 5, 2022),
],
],
FALSE,
],
'valid same dates, different times' => [
[
......@@ -170,7 +175,6 @@ class TransitionManagerTest extends KernelTestBase {
'when' => mktime(15, 42, 0, 9, 19, 2022),
],
],
FALSE,
],
];
}
......
......@@ -116,4 +116,13 @@ trait SchedulerUiTrait {
$this->container->get('state')->set('lightning_scheduler.request_time', $request_time);
}
/**
* Clicks the link to the edit form for an entity.
*/
protected function clickEditLink() {
$this->assertSession()
->elementExists('named', ['link', 'edit-form'])
->click();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment