Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
recurring_events
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
recurring_events
Commits
617bc7ff
Commit
617bc7ff
authored
5 years ago
by
Owen Bush
Browse files
Options
Downloads
Patches
Plain Diff
Added unit testing for consecutive recurring dates
parent
8265ef99
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/src/Unit/ConsecutiveRecurringDateTest.php
+107
-0
107 additions, 0 deletions
tests/src/Unit/ConsecutiveRecurringDateTest.php
tests/src/Unit/includes/OverriddenGlobalFunctions.php
+20
-0
20 additions, 0 deletions
tests/src/Unit/includes/OverriddenGlobalFunctions.php
with
127 additions
and
0 deletions
tests/src/Unit/ConsecutiveRecurringDateTest.php
0 → 100644
+
107
−
0
View file @
617bc7ff
<?php
namespace
Drupal\Tests\recurring_events\Unit
;
use
Drupal\recurring_events
\Plugin\Field\FieldType\ConsecutiveRecurringDate
;
use
Drupal\Core\Datetime\DrupalDateTime
;
use
Drupal\Core\DependencyInjection\ContainerBuilder
;
use
Drupal\Tests\UnitTestCase
;
/**
* @coversDefaultClass \Drupal\recurring_events\Plugin\Field\FieldType\ConsecutiveRecurringDate
* @group recurring_events
*/
class
ConsecutiveRecurringDateTest
extends
UnitTestCase
{
/**
* {@inheritdoc}
*/
public
function
setUp
()
{
parent
::
setUp
();
require_once
'includes/OverriddenGlobalFunctions.php'
;
$container
=
new
ContainerBuilder
();
\Drupal
::
setContainer
(
$container
);
$language_manager_mock
=
$this
->
getMockBuilder
(
'Drupal\\Core\\Language\\LanguageManagerInterface'
)
->
disableOriginalConstructor
()
->
getMock
();
$language_mock
=
$this
->
createMock
(
'Drupal\\Core\\Language\\LanguageInterface'
);
$language_manager_mock
->
expects
(
$this
->
any
())
->
method
(
'getCurrentLanguage'
)
->
will
(
$this
->
returnValue
(
$language_mock
));
$container
->
set
(
'language_manager'
,
$language_manager_mock
);
}
/**
* Tests ConsecutiveRecurringDate::findDailyDatesBetweenDates().
*/
public
function
testFindDailyDatesBetweenDates
()
{
$start_date
=
new
DrupalDateTime
(
'2019-01-01 00:00:00'
);
$end_date
=
new
DrupalDateTime
(
'2019-01-07 00:00:00'
);
$expected_dates
=
$dates
=
[];
$expected_date_objects
=
[
new
DrupalDateTime
(
'2019-01-01 00:00:00'
),
new
DrupalDateTime
(
'2019-01-02 00:00:00'
),
new
DrupalDateTime
(
'2019-01-03 00:00:00'
),
new
DrupalDateTime
(
'2019-01-04 00:00:00'
),
new
DrupalDateTime
(
'2019-01-05 00:00:00'
),
new
DrupalDateTime
(
'2019-01-06 00:00:00'
),
new
DrupalDateTime
(
'2019-01-07 00:00:00'
),
];
$date_objects
=
ConsecutiveRecurringDate
::
findDailyDatesBetweenDates
(
$start_date
,
$end_date
);
foreach
(
$expected_date_objects
as
$date
)
{
$expected_dates
[]
=
$date
->
format
(
'r'
);
}
foreach
(
$date_objects
as
$date
)
{
$dates
[]
=
$date
->
format
(
'r'
);
}
$this
->
assertSame
(
$expected_dates
,
$dates
);
}
/**
* Tests ConsecutiveRecurringDate::findSlotsBetweenTimes().
*/
public
function
testFindSlotsBetweenTimes
()
{
$start_date
=
new
DrupalDateTime
(
'2019-01-01 00:00:00'
);
$form_data
=
[
'end_time'
=>
'01:00:00'
,
'duration'
=>
'10'
,
'duration_units'
=>
'minute'
,
'buffer'
=>
'5'
,
'buffer_units'
=>
'minute'
,
];
$expected_dates
=
$dates
=
[];
$expected_date_objects
=
[
new
DrupalDateTime
(
'2019-01-01 00:00:00'
),
new
DrupalDateTime
(
'2019-01-01 00:15:00'
),
new
DrupalDateTime
(
'2019-01-01 00:30:00'
),
new
DrupalDateTime
(
'2019-01-01 00:45:00'
),
new
DrupalDateTime
(
'2019-01-01 01:00:00'
),
];
$date_objects
=
ConsecutiveRecurringDate
::
findSlotsBetweenTimes
(
$start_date
,
$form_data
);
foreach
(
$expected_date_objects
as
$date
)
{
$expected_dates
[]
=
$date
->
format
(
'r'
);
}
foreach
(
$date_objects
as
$date
)
{
$dates
[]
=
$date
->
format
(
'r'
);
}
$this
->
assertSame
(
$expected_dates
,
$dates
);
}
}
This diff is collapsed.
Click to expand it.
tests/src/Unit/includes/OverriddenGlobalFunctions.php
0 → 100644
+
20
−
0
View file @
617bc7ff
<?php
/**
* @file
* Includes some overridden global functions.
*/
if
(
!
function_exists
(
'drupal_get_user_timezone'
))
{
/**
* Overrides global drupal_get_user_timezone if not exists.
*
* @return string
* Timezone mocked.
*/
function
drupal_get_user_timezone
()
{
return
@
date_default_timezone_get
();
}
}
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