Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
environment_indicator
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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
environment_indicator
Merge requests
!84
Issue
#3500006
Add basic PHPUnit tests
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Merged
Issue
#3500006
Add basic PHPUnit tests
issue/environment_indicator-3500006:3500006-create-basic-phpunit
into
4.x
Overview
0
Commits
31
Pipelines
29
Changes
7
Merged
Issue #3500006 Add basic PHPUnit tests
Chris Green
requested to merge
issue/environment_indicator-3500006:3500006-create-basic-phpunit
into
4.x
5 months ago
Overview
0
Commits
31
Pipelines
29
Changes
7
Closes
#3500006
0
0
Merge request reports
Compare
4.x
version 27
47d799cf
2 months ago
version 26
d871ec32
2 months ago
version 25
e1abbc87
2 months ago
version 24
7fa193b4
2 months ago
version 23
8280723b
5 months ago
version 22
a53e9795
5 months ago
version 21
4cff360f
5 months ago
version 20
9570e2a8
5 months ago
version 19
39aad28e
5 months ago
version 18
de127363
5 months ago
version 17
38b63c0f
5 months ago
version 16
43a620e5
5 months ago
version 15
bc0b7460
5 months ago
version 14
4a3f83b9
5 months ago
version 13
2b8fe22f
5 months ago
version 12
2e1fd526
5 months ago
version 11
bb1b18c0
5 months ago
version 10
21253b01
5 months ago
version 9
a79e60d1
5 months ago
version 8
673e224c
5 months ago
version 7
21df8e0b
5 months ago
version 6
bdd5c661
5 months ago
version 5
f5d5af34
5 months ago
version 4
4ab59054
5 months ago
version 3
40e05fcd
5 months ago
version 2
53d47c68
5 months ago
version 1
8d3bf524
5 months ago
4.x (base)
and
latest version
latest version
486396d1
31 commits,
2 months ago
version 27
47d799cf
30 commits,
2 months ago
version 26
d871ec32
29 commits,
2 months ago
version 25
e1abbc87
28 commits,
2 months ago
version 24
7fa193b4
26 commits,
2 months ago
version 23
8280723b
25 commits,
5 months ago
version 22
a53e9795
24 commits,
5 months ago
version 21
4cff360f
23 commits,
5 months ago
version 20
9570e2a8
22 commits,
5 months ago
version 19
39aad28e
21 commits,
5 months ago
version 18
de127363
20 commits,
5 months ago
version 17
38b63c0f
19 commits,
5 months ago
version 16
43a620e5
18 commits,
5 months ago
version 15
bc0b7460
17 commits,
5 months ago
version 14
4a3f83b9
16 commits,
5 months ago
version 13
2b8fe22f
15 commits,
5 months ago
version 12
2e1fd526
14 commits,
5 months ago
version 11
bb1b18c0
13 commits,
5 months ago
version 10
21253b01
12 commits,
5 months ago
version 9
a79e60d1
11 commits,
5 months ago
version 8
673e224c
9 commits,
5 months ago
version 7
21df8e0b
8 commits,
5 months ago
version 6
bdd5c661
7 commits,
5 months ago
version 5
f5d5af34
6 commits,
5 months ago
version 4
4ab59054
5 commits,
5 months ago
version 3
40e05fcd
4 commits,
5 months ago
version 2
53d47c68
3 commits,
5 months ago
version 1
8d3bf524
1 commit,
5 months ago
7 files
+
781
−
47
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
7
tests/src/Functional/EnvironmentIndicatorTest.php
0 → 100644
+
181
−
0
View file @ 486396d1
Edit in single-file editor
Open in Web IDE
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\Tests\environment_indicator\Functional
;
use
Drupal\Core\StringTranslation\StringTranslationTrait
;
use
Drupal\Tests\BrowserTestBase
;
/**
* Tests for Environment Indicator.
*
* @group environment_indicator
*/
class
EnvironmentIndicatorTest
extends
BrowserTestBase
{
use
StringTranslationTrait
;
/**
* {@inheritdoc}
*/
protected
static
$modules
=
[
'environment_indicator'
,
'environment_indicator_ui'
,
];
/**
* {@inheritdoc}
*/
protected
$defaultTheme
=
'stark'
;
/**
* A user with permission to see the environment indicator.
*
* @var \Drupal\user\UserInterface
*/
protected
$privilegedUser
;
/**
* A user without permission to see the environment indicator.
*
* @var \Drupal\user\UserInterface
*/
protected
$unprivilegedUser
;
/**
* A user with permission to create environment switchers.
*
* @var \Drupal\user\UserInterface
*/
protected
$environmentIndicatorAdministrator
;
/**
* The path to the environment_indicator module.
*
* @var string
*/
protected
string
$modulePath
;
/**
* The state service.
*
* @var \Drupal\Core\State\StateInterface
*/
protected
$state
;
/**
* {@inheritdoc}
*/
protected
function
setUp
():
void
{
parent
::
setUp
();
// Retrieve the dynamic module path.
$moduleHandler
=
\Drupal
::
service
(
'extension.list.module'
);
$this
->
modulePath
=
$moduleHandler
->
getPath
(
'environment_indicator'
);
$this
->
state
=
\Drupal
::
state
();
// Create users.
$this
->
privilegedUser
=
$this
->
drupalCreateUser
([
'access environment indicator'
]);
$this
->
unprivilegedUser
=
$this
->
drupalCreateUser
();
}
/**
* Tests that the environment indicator appears in the page top region.
*
* This test verifies that the environment indicator appears in the page top
* region with the expected attributes.
*/
public
function
testVisibilityWithPermissions
():
void
{
$config
=
$this
->
config
(
'environment_indicator.indicator'
);
$config
->
set
(
'name'
,
'Red Green Environment'
)
->
set
(
'fg_color'
,
'green'
)
->
set
(
'bg_color'
,
'red'
)
->
save
();
$this
->
container
->
get
(
'cache_tags.invalidator'
)
->
invalidateTags
([
'config:environment_indicator.indicator'
]);
$this
->
drupalLogin
(
$this
->
privilegedUser
);
$this
->
drupalGet
(
'<front>'
);
$session
=
$this
->
assertSession
();
$session
->
pageTextContains
(
'Red Green Environment'
);
$session
->
elementExists
(
'css'
,
'#environment-indicator'
);
$output
=
$this
->
getSession
()
->
getPage
()
->
find
(
'css'
,
'#environment-indicator'
)
->
getAttribute
(
'style'
);
$this
->
assertNotEmpty
(
$output
,
'Style attribute should not be empty.'
);
$this
->
assertStringContainsString
(
'background-color: red'
,
$output
);
$this
->
assertStringContainsString
(
'color: green'
,
$output
);
$this
->
assertSession
()
->
elementExists
(
"css"
,
"link[href*='
{
$this
->
modulePath
}
/css/environment_indicator.css']"
);
// Change configuration values.
$config
=
$this
->
config
(
'environment_indicator.indicator'
);
$config
->
set
(
'name'
,
'Test Environment'
)
->
set
(
'fg_color'
,
'#ffffff'
)
->
set
(
'bg_color'
,
'#000000'
)
->
save
();
// Clear drupal cache.
$this
->
container
->
get
(
'cache_tags.invalidator'
)
->
invalidateTags
([
'config:environment_indicator.indicator'
]);
$this
->
drupalLogin
(
$this
->
privilegedUser
);
$this
->
drupalGet
(
'<front>'
);
$session
=
$this
->
assertSession
();
$session
->
pageTextContains
(
'Test Environment'
);
$session
->
elementExists
(
'css'
,
'#environment-indicator'
);
$output
=
$this
->
getSession
()
->
getPage
()
->
find
(
'css'
,
'#environment-indicator'
)
->
getAttribute
(
'style'
);
$this
->
assertNotEmpty
(
$output
,
'Style attribute should not be empty.'
);
$this
->
assertStringContainsString
(
'background-color: #000000'
,
$output
);
$this
->
assertStringContainsString
(
'color: #ffffff'
,
$output
);
// Change configuration values.
$config
=
$this
->
config
(
'environment_indicator.indicator'
);
$config
->
set
(
'name'
,
'Development Environment'
)
->
set
(
'fg_color'
,
'#efefef'
)
->
set
(
'bg_color'
,
'#12285f'
)
->
save
();
// Clear drupal cache.
$this
->
container
->
get
(
'cache_tags.invalidator'
)
->
invalidateTags
([
'config:environment_indicator.indicator'
]);
$this
->
drupalGet
(
'<front>'
);
// Assert that the environment indicator exists with
// the expected attributes.
$session
->
elementExists
(
'css'
,
'#environment-indicator'
);
$output
=
$this
->
getSession
()
->
getPage
()
->
find
(
'css'
,
'#environment-indicator'
)
->
getAttribute
(
'style'
);
$this
->
assertNotEmpty
(
$output
,
'Style attribute should not be empty.'
);
$this
->
assertStringContainsString
(
'background-color: #12285f'
,
$output
);
$this
->
assertStringContainsString
(
'color: #efefef'
,
$output
);
$session
->
pageTextContains
(
'Development Environment'
);
}
/**
* Tests visibility for unauthorized users.
*/
public
function
testVisibilityWithoutPermissions
():
void
{
$config
=
$this
->
config
(
'environment_indicator.indicator'
);
$config
->
set
(
'name'
,
'Test Environment'
)
->
set
(
'fg_color'
,
'#000000'
)
->
set
(
'bg_color'
,
'#ffffff'
)
->
save
();
$this
->
container
->
get
(
'cache_tags.invalidator'
)
->
invalidateTags
([
'config:environment_indicator.indicator'
]);
$this
->
drupalLogin
(
$this
->
drupalCreateUser
());
$this
->
drupalGet
(
'<front>'
);
$this
->
assertSession
()
->
elementNotExists
(
'css'
,
'#environment-indicator'
);
$this
->
assertSession
()
->
elementNotExists
(
"css"
,
"link[href*='
{
$this
->
modulePath
}
/css/environment_indicator.css']"
);
}
/**
* Tests the indicator with the default configuration.
*/
public
function
testIndicatorDefaultConfiguration
():
void
{
$this
->
drupalLogin
(
$this
->
privilegedUser
);
$this
->
state
->
set
(
'environment_indicator.current_release'
,
'v1.2.44'
);
$config
=
$this
->
config
(
'environment_indicator.indicator'
);
$config
->
set
(
'name'
,
'Indicator Environment'
)
->
set
(
'fg_color'
,
'#000000'
)
->
set
(
'bg_color'
,
'#ffffff'
)
->
save
();
$this
->
container
->
get
(
'cache_tags.invalidator'
)
->
invalidateTags
([
'config:environment_indicator.indicator'
]);
$this
->
drupalGet
(
'<front>'
);
$output
=
$this
->
getSession
()
->
getPage
()
->
find
(
'css'
,
'#environment-indicator'
)
->
getAttribute
(
'style'
);
$this
->
assertNotEmpty
(
$output
,
'Style attribute should not be empty.'
);
$this
->
assertStringContainsString
(
'background-color: #ffffff'
,
$output
);
$this
->
assertStringContainsString
(
'color: #000000'
,
$output
);
$this
->
assertSession
()
->
elementExists
(
'css'
,
'div#environment-indicator span.description'
);
$this
->
assertSession
()
->
pageTextContains
(
'v1.2.44'
);
}
}
Loading