Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
timepicker
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
timepicker
Merge requests
!26
Issue # 3513301: Added an initial Basic Test Class file.
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue # 3513301: Added an initial Basic Test Class file.
issue/timepicker-3513301:3513301-write-basic-tests
into
3.0.x
Overview
0
Commits
4
Pipelines
5
Changes
2
Merged
Daniel Rodriguez
requested to merge
issue/timepicker-3513301:3513301-write-basic-tests
into
3.0.x
2 months ago
Overview
0
Commits
4
Pipelines
5
Changes
2
Expand
Closes
#3513301
0
0
Merge request reports
Compare
3.0.x
version 3
08405df9
2 months ago
version 2
09433710
2 months ago
version 1
cf5059f4
2 months ago
3.0.x (base)
and
latest version
latest version
51c9243d
4 commits,
2 months ago
version 3
08405df9
3 commits,
2 months ago
version 2
09433710
2 commits,
2 months ago
version 1
cf5059f4
1 commit,
2 months ago
2 files
+
145
−
2
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
tests/src/Functional/TimepickerAdminTest.php
0 → 100644
+
141
−
0
Options
<?php
namespace
Drupal\Tests\timepicker\Functional
;
use
Drupal\Tests\BrowserTestBase
;
use
Drupal\node\Entity\Node
;
use
Drupal\node\Entity\NodeType
;
use
Drupal\datetime\Plugin\Field\FieldType\DateTimeItem
;
use
Drupal\field\Entity\FieldConfig
;
use
Drupal\field\Entity\FieldStorageConfig
;
use
Drupal\Core\Field\FieldStorageDefinitionInterface
;
/**
* Tests the Timepicker module.
*
* @group timepicker
*/
class
TimepickerAdminTest
extends
BrowserTestBase
{
/**
* {@inheritdoc}
*/
protected
static
$modules
=
[
'node'
,
'datetime'
,
'text'
,
'timepicker'
];
/**
* {@inheritdoc}
*/
protected
$defaultTheme
=
'stark'
;
/**
* Tests if user can load the front page among other things.
*/
public
function
testLoadSite
()
{
// Load the front page.
$this
->
drupalGet
(
'<front>'
);
// Confirm that the site didn't throw a server error or something else.
$this
->
assertSession
()
->
statusCodeEquals
(
200
);
$this
->
drupalGet
(
"user"
);
}
/**
* Tests if an admin user can log in.
*/
public
function
testAdminUser
()
{
// Log in an administrative user.
$this
->
drupalLogin
(
$this
->
rootUser
);
$this
->
drupalGet
(
'admin/config'
);
$session
=
$this
->
assertSession
();
$session
->
statusCodeEquals
(
200
);
}
/**
* Testing to create a node with a datetime textfield.
*/
public
function
testLoadSiteAfterChanges
()
{
// Create the article content type with a datetime and a text textfield.
$node_type
=
NodeType
::
create
([
'type'
=>
'article'
,
]);
$node_type
->
save
();
// Add a text field.
$field_storage
=
FieldStorageConfig
::
create
([
'field_name'
=>
'test_field'
,
'entity_type'
=>
'node'
,
'type'
=>
'text'
,
]);
$field_storage
->
save
();
$field
=
FieldConfig
::
create
([
'field_name'
=>
'test_field'
,
'entity_type'
=>
'node'
,
'bundle'
=>
'article'
,
'label'
=>
'Test field'
,
]);
$field
->
save
();
// Add a datetime field.
$field_datetime_storage
=
FieldStorageConfig
::
create
([
'field_name'
=>
'field_datetime'
,
'type'
=>
'datetime'
,
'entity_type'
=>
'node'
,
'settings'
=>
[
'datetime_type'
=>
DateTimeItem
::
DATETIME_TYPE_DATETIME
],
'cardinality'
=>
FieldStorageDefinitionInterface
::
CARDINALITY_UNLIMITED
,
]);
$field_datetime_storage
->
save
();
$field_datetime
=
FieldConfig
::
create
([
'field_storage'
=>
$field_datetime_storage
,
'bundle'
=>
'article'
,
]);
$field_datetime
->
save
();
// Creates two different articles and tests them.
$node1
=
Node
::
create
([
'title'
=>
'Test node title'
,
'type'
=>
'article'
,
'test_field'
=>
[
'value'
=>
'foo'
,
],
'field_datetime'
=>
[
'value'
=>
"2014-08-22T00:00:00"
,
],
]);
$node1
->
save
();
$node2
=
Node
::
create
([
'title'
=>
'Test node title 2'
,
'type'
=>
'article'
,
'test_field'
=>
[
'value'
=>
'food'
,
],
'field_datetime'
=>
[
'value'
=>
"2023-02-14T00:00:00"
,
],
]);
$node2
->
save
();
$this
->
assertNotEquals
(
$node1
,
$node2
,
"There was an error creating the content type or the nodes"
);
}
/**
* Tests if an admin access to pages again.
*/
public
function
testAdminUserAfterChanges
()
{
// Log in an administrative user.
$this
->
drupalLogin
(
$this
->
rootUser
);
$this
->
drupalGet
(
'admin/modules'
);
$session
=
$this
->
assertSession
();
$session
->
statusCodeEquals
(
200
);
}
}
Loading