Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3443915
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Issue forks
drupal-3443915
Commits
798a30f7
Commit
798a30f7
authored
7 years ago
by
catch
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2863372
by dagmar, Jo Fitzgerald: Convert dblog web tests to BrowserTestBase
parent
658325ea
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/modules/dblog/tests/src/Functional/DbLogTest.php
+22
-39
22 additions, 39 deletions
core/modules/dblog/tests/src/Functional/DbLogTest.php
with
22 additions
and
39 deletions
core/modules/dblog/
src/Tests
/DbLogTest.php
→
core/modules/dblog/
tests/src/Functional
/DbLogTest.php
+
22
−
39
View file @
798a30f7
<?php
namespace
Drupal\
dblog\Tests
;
namespace
Drupal\
Tests\dblog\Functional
;
use
Drupal\Component\Utility\Html
;
use
Drupal\Component\Utility\Unicode
;
use
Drupal\Core\Logger\RfcLogLevel
;
use
Drupal\Core\Url
;
use
Drupal\dblog\Controller\DbLogController
;
use
Drupal\simpletest\WebTestBase
;
use
Drupal\Tests\BrowserTestBase
;
use
Drupal\Tests\Traits\Core\CronRunTrait
;
/**
* Generate events and verify dblog entries; verify user access to log reports
...
...
@@ -15,7 +16,8 @@
*
* @group dblog
*/
class
DbLogTest
extends
WebTestBase
{
class
DbLogTest
extends
BrowserTestBase
{
use
CronRunTrait
;
/**
* Modules to enable.
...
...
@@ -312,7 +314,7 @@ private function verifyBreadcrumbs() {
$wid
=
db_query
(
'SELECT MIN(wid) FROM {watchdog}'
)
->
fetchField
();
$this
->
drupalGet
(
'admin/reports/dblog/event/'
.
$wid
);
$xpath
=
'//nav[@class="breadcrumb"]/ol/li[last()]/a'
;
$this
->
assertEqual
(
current
(
$this
->
xpath
(
$xpath
)),
'Recent log messages'
,
'DBLogs link displayed at breadcrumb in event page.'
);
$this
->
assertEqual
(
current
(
$this
->
xpath
(
$xpath
))
->
getText
()
,
'Recent log messages'
,
'DBLogs link displayed at breadcrumb in event page.'
);
}
/**
...
...
@@ -386,7 +388,7 @@ private function doUser() {
$user
=
user_load_by_name
(
$name
);
$this
->
assertTrue
(
$user
!=
NULL
,
format_string
(
'User @name was loaded'
,
[
'@name'
=>
$name
]));
// pass_raw property is needed by drupalLogin.
$user
->
pass
_r
aw
=
$pass
;
$user
->
pass
R
aw
=
$pass
;
// Log in user.
$this
->
drupalLogin
(
$user
);
// Log out user.
...
...
@@ -426,16 +428,13 @@ private function doUser() {
if
(
$links
=
$this
->
xpath
(
'//a[text()="'
.
$message_text
.
'"]'
))
{
// Found link with the message text.
$links
=
array_shift
(
$links
);
foreach
(
$links
->
attributes
()
as
$attr
=>
$value
)
{
if
(
$attr
==
'href'
)
{
// Extract link to details page.
$link
=
Unicode
::
substr
(
$value
,
strpos
(
$value
,
'admin/reports/dblog/event/'
));
$this
->
drupalGet
(
$link
);
// Check for full message text on the details page.
$this
->
assertRaw
(
$message
,
'DBLog event details was found: [delete user]'
);
break
;
}
}
$value
=
$links
->
getAttribute
(
'href'
);
// Extract link to details page.
$link
=
Unicode
::
substr
(
$value
,
strpos
(
$value
,
'admin/reports/dblog/event/'
));
$this
->
drupalGet
(
$link
);
// Check for full message text on the details page.
$this
->
assertRaw
(
$message
,
'DBLog event details was found: [delete user]'
);
}
$this
->
assertTrue
(
$link
,
'DBLog event was recorded: [delete user]'
);
// Visit random URL (to generate page not found event).
...
...
@@ -526,7 +525,7 @@ private function getContent($type) {
case
'forum'
:
$content
=
[
'title[0][value]'
=>
$this
->
randomMachineName
(
8
),
'taxonomy_forums'
=>
[
1
]
,
'taxonomy_forums'
=>
1
,
'body[0][value]'
=>
$this
->
randomMachineName
(
32
),
];
break
;
...
...
@@ -682,13 +681,13 @@ public function testFilter() {
protected
function
getLogEntries
()
{
$entries
=
[];
if
(
$table
=
$this
->
getLogsEntriesTable
())
{
$table
=
array_shift
(
$table
);
foreach
(
$table
->
tbody
->
tr
as
$row
)
{
foreach
(
$table
as
$row
)
{
$cells
=
$row
->
findAll
(
'css'
,
'td'
);
$entries
[]
=
[
'severity'
=>
$this
->
getSeverityConstant
(
$row
[
'class'
]
),
'type'
=>
$
this
->
asText
(
$row
->
td
[
1
]
),
'message'
=>
$
this
->
asText
(
$row
->
td
[
3
]
),
'user'
=>
$
this
->
asText
(
$row
->
td
[
4
]
),
'severity'
=>
$this
->
getSeverityConstant
(
$row
->
getAttribute
(
'class'
)
),
'type'
=>
$
cells
[
1
]
->
getText
(
),
'message'
=>
$
cells
[
3
]
->
getText
(
),
'user'
=>
$
cells
[
4
]
->
getText
(
),
];
}
}
...
...
@@ -702,7 +701,7 @@ protected function getLogEntries() {
* The return value of a xpath search.
*/
protected
function
getLogsEntriesTable
()
{
return
$this
->
xpath
(
'.//table[@id="admin-dblog"]'
);
return
$this
->
xpath
(
'.//table[@id="admin-dblog"]
/tbody/tr
'
);
}
/**
...
...
@@ -750,22 +749,6 @@ protected function getSeverityConstant($class) {
return
NULL
;
}
/**
* Extracts the text contained by the XHTML element.
*
* @param \SimpleXMLElement $element
* Element to extract text from.
*
* @return string
* Extracted text.
*/
protected
function
asText
(
\SimpleXMLElement
$element
)
{
if
(
!
is_object
(
$element
))
{
return
$this
->
fail
(
'The element is not an element.'
);
}
return
trim
(
html_entity_decode
(
strip_tags
(
$element
->
asXML
())));
}
/**
* Confirms that a log message appears on the database log overview screen.
*
...
...
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