Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
smart_date
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
smart_date
Commits
4c35ed4f
Commit
4c35ed4f
authored
1 year ago
by
Chad Hester
Committed by
Martin Anderson-Clutz
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3432819
by chadhester, nicxvan, ultimike: Test for a later start date in a date range
parent
34e188a3
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!94
Resolve #3432819 "Test start date in range"
Pipeline
#130476
passed with warnings
1 year ago
Stage: build
Stage: validate
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/src/Functional/SmartDateStartValueTest.php
+133
-0
133 additions, 0 deletions
tests/src/Functional/SmartDateStartValueTest.php
with
133 additions
and
0 deletions
tests/src/Functional/SmartDateStartValueTest.php
0 → 100644
+
133
−
0
View file @
4c35ed4f
<?php
namespace
Drupal\Tests\smart_date\Functional
;
use
Drupal\field\Entity\FieldConfig
;
use
Drupal\field\Entity\FieldStorageConfig
;
/**
* Tests the start date value in a date range.
*
* This test uses SmartDateTestBase to set up a fixture site so that we can test
* for error messages when a user enters an invalid value for the start date in
* a date range.
*
* @code
* vendor/phpunit/phpunit/phpunit -c core/phpunit.xml --printer '\Drupal\Tests\Listeners\HtmlOutputPrinter' modules/start_date/tests/src/Functional
* @endcode
*
* @group start_date
*/
class
SmartDateStartValueTest
extends
SmartDateTestBase
{
/**
* The content type name.
*
* @var string
*/
protected
$contentTypeName
;
/**
* The field name.
*
* @var string
*/
protected
$fieldName
;
/**
* {@inheritdoc}
*/
protected
function
setUp
():
void
{
// Always call the parent setUp().
parent
::
setUp
();
// Create a test content type.
$this
->
contentTypeName
=
'smart_date_content'
;
$this
->
drupalCreateContentType
([
'type'
=>
$this
->
contentTypeName
]);
$this
->
fieldName
=
'field_date'
;
$field_storage
=
FieldStorageConfig
::
create
([
'field_name'
=>
$this
->
fieldName
,
'entity_type'
=>
'node'
,
'type'
=>
'smartdate'
,
]);
$field_storage
->
save
();
$field
=
FieldConfig
::
create
([
'field_name'
=>
$this
->
fieldName
,
'entity_type'
=>
'node'
,
'bundle'
=>
$this
->
contentTypeName
,
'label'
=>
'Date'
,
]);
$field
->
setDefaultValue
([
'default_duration'
=>
60
,
'default_duration_increments'
=>
"30
\r\n
60|1 hour
\r\n
90
\r\n
120|2 hours
\r\n
custom"
,
'default_date_type'
=>
''
,
'default_date'
=>
''
,
'min'
=>
''
,
'max'
=>
''
,
]);
$field
->
save
();
// Assign widget settings for the default form mode.
$settings
=
[
'type'
=>
'smartdate_timezone'
,
'weight'
=>
122
,
'region'
=>
'content'
,
'settings'
=>
[
'modal'
=>
FALSE
,
'default_tz'
=>
''
,
'custom_tz'
=>
''
,
'allowed_timezones'
=>
[],
'default_duration'
=>
60
,
'default_duration_increments'
=>
"30
\r\n
60|1 hour
\r\n
90
\r\n
120|2 hours
\r\n
custom"
,
'show_extra'
=>
FALSE
,
'hide_date'
=>
TRUE
,
'separator'
=>
'to'
,
'add_abbreviations'
=>
''
,
],
'third_party_settings'
=>
[],
];
/** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
$display_repository
=
\Drupal
::
service
(
'entity_display.repository'
);
$display_repository
->
getFormDisplay
(
'node'
,
$this
->
contentTypeName
)
->
setComponent
(
$this
->
fieldName
,
$settings
)
->
save
();
}
/**
* Tests for the existence of a default menu item on the home page.
*
* We'll open the home page and look for the Tools menu link called 'Add
* content.'
*/
public
function
testForStartDateAfterEndDate
()
{
$assert
=
$this
->
assertSession
();
$this
->
drupalLogin
(
$this
->
createUser
([
'create '
.
$this
->
contentTypeName
.
' content'
,
])
);
$this
->
drupalGet
(
'node/add/'
.
$this
->
contentTypeName
);
$title
=
$this
->
randomMachineName
(
20
);
$edit
=
[
'title[0][value]'
=>
$title
,
// Set the start value to be later than the end value,
// 2024-01-01 13:00:00.
$this
->
fieldName
.
'[0][time_wrapper][value][date]'
=>
'2024-01-01'
,
$this
->
fieldName
.
'[0][time_wrapper][value][time]'
=>
'13:00:00'
,
// Set the end date before the start date to trigger the error,
// 2024-01-01 12:00:00.
$this
->
fieldName
.
'[0][time_wrapper][end_value][date]'
=>
'2024-01-01'
,
$this
->
fieldName
.
'[0][time_wrapper][end_value][time]'
=>
'12:00:00'
,
];
$this
->
submitForm
(
$edit
,
'Save'
);
$assert
->
pageTextContains
(
'end date cannot be before the start date'
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment