Skip to content
GitLab
Explore
Sign in
project
drupal
Compare revisions
22aa4508e72733e79560231f2b1b76e03dcdcf6c to 8.2.x
Hide whitespace changes
Inline
Side-by-side
core/modules/system/src/Tests/Module/UninstallTest.php
View file @
55845022
...
...
@@ -121,6 +121,11 @@ function testUninstallPage() {
$this
->
drupalGet
(
'admin/modules/uninstall/confirm'
);
$this
->
assertUrl
(
'admin/modules/uninstall'
);
$this
->
assertTitle
(
t
(
'Uninstall'
)
.
' | Drupal'
);
// Make sure the correct error is shown when no modules are selected.
$edit
=
array
();
$this
->
drupalPostForm
(
'admin/modules/uninstall'
,
$edit
,
t
(
'Uninstall'
));
$this
->
assertText
(
t
(
'No modules selected.'
),
'No module is selected to uninstall'
);
}
/**
...
...
core/modules/system/tests/modules/entity_test_third_party/config/schema/entity_test_third_party.schema.yml
0 → 100644
View file @
55845022
core.entity_view_display.*.*.*.third_party.entity_test_third_party
:
type
:
mapping
label
:
'
Schema
for
entity_test
module
additions
to
entity_view_display
entity'
mapping
:
key
:
type
:
string
label
:
'
Label
for
key'
core/modules/system/tests/modules/entity_test_third_party/entity_test_third_party.info.yml
0 → 100644
View file @
55845022
name
:
'
Entity
test
third-party
settings
module'
type
:
module
description
:
'
Provides
third-party
settings
for
test
entity
types.'
package
:
Testing
version
:
VERSION
core
:
8.x
dependencies
:
-
entity_test
core/modules/system/tests/modules/js_webassert_test/js/js_webassert_test.wait_for_ajax_request.js
0 → 100644
View file @
55845022
/**
* @file
* Testing behavior for JSWebAssertTest.
*/
(
function
(
$
,
Drupal
,
drupalSettings
)
{
'
use strict
'
;
/**
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
* Makes changes in the DOM to be able to test the completion of AJAX in assertWaitOnAjaxRequest.
*/
Drupal
.
behaviors
.
js_webassert_test_wait_for_ajax_request
=
{
attach
:
function
(
context
)
{
$
(
'
input[name="test_assert_wait_on_ajax_input"]
'
).
val
(
'
js_webassert_test
'
);
}
};
})(
jQuery
,
Drupal
,
drupalSettings
);
core/modules/system/tests/modules/js_webassert_test/js/js_webassert_test.wait_for_element.js
0 → 100644
View file @
55845022
/**
* @file
* Testing behavior for JSWebAssertTest.
*/
(
function
(
$
,
Drupal
,
drupalSettings
)
{
'
use strict
'
;
/**
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
* Makes changes in the DOM to be able to test the completion of AJAX in assertWaitOnAjaxRequest.
*/
Drupal
.
behaviors
.
js_webassert_test_wait_for_element
=
{
attach
:
function
(
context
)
{
$
(
'
#js_webassert_test_element_invisible
'
).
show
();
}
};
})(
jQuery
,
Drupal
,
drupalSettings
);
core/modules/system/tests/modules/js_webassert_test/js_webassert_test.info.yml
0 → 100644
View file @
55845022
name
:
'
JS
WebAssert
test
module'
type
:
module
description
:
'
Module
for
the
JSWebAssert
test.'
package
:
Testing
version
:
VERSION
core
:
8.x
core/modules/system/tests/modules/js_webassert_test/js_webassert_test.libraries.yml
0 → 100644
View file @
55845022
wait_for_ajax_request
:
version
:
VERSION
js
:
js/js_webassert_test.wait_for_ajax_request.js
:
{}
dependencies
:
-
core/jquery
-
core/drupal
wait_for_element
:
version
:
VERSION
js
:
js/js_webassert_test.wait_for_element.js
:
{}
dependencies
:
-
core/jquery
-
core/drupal
core/modules/system/tests/modules/js_webassert_test/js_webassert_test.routing.yml
0 → 100644
View file @
55845022
js_webassert_test.js_webassert_test_form
:
path
:
'
/js_webassert_test_form'
defaults
:
_form
:
'
Drupal\js_webassert_test\Form\JsWebAssertTestForm'
_title
:
'
JsWebAssertForm'
requirements
:
_access
:
'
TRUE'
core/modules/system/tests/modules/js_webassert_test/src/Form/JsWebAssertTestForm.php
0 → 100644
View file @
55845022
<?php
namespace
Drupal\js_webassert_test\Form
;
use
Drupal\Core\Form\FormBase
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Url
;
/**
* Test form for JSWebAssert JavaScriptTestBase.
*/
class
JsWebAssertTestForm
extends
FormBase
{
/**
* {@inheritdoc}
*/
public
function
getFormId
()
{
return
'js_webassert_test_form'
;
}
/**
* Form for testing the addition of various types of elements via AJAX.
*/
public
function
buildForm
(
array
$form
,
FormStateInterface
$form_state
)
{
$form
[
'#prefix'
]
=
'<div id="js_webassert_test_form_wrapper">'
;
$form
[
'#suffix'
]
=
'</div>'
;
// Button to test for the waitForButton() assertion.
$form
[
'test_button'
]
=
[
'#type'
=>
'submit'
,
'#value'
=>
$this
->
t
(
'Add button'
),
'#button_type'
=>
'primary'
,
'#ajax'
=>
[
'callback'
=>
'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addButton'
,
'progress'
=>
[
'type'
=>
'throbber'
,
'message'
=>
NULL
,
],
'wrapper'
=>
'js_webassert_test_form_wrapper'
,
],
];
// Button to test for the waitForLink() assertion.
$form
[
'test_link'
]
=
[
'#type'
=>
'submit'
,
'#value'
=>
$this
->
t
(
'Add link'
),
'#button_type'
=>
'primary'
,
'#ajax'
=>
[
'callback'
=>
'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addLink'
,
'progress'
=>
[
'type'
=>
'throbber'
,
'message'
=>
NULL
,
],
'wrapper'
=>
'js_webassert_test_form_wrapper'
,
],
];
// Button to test for the waitForField() assertion.
$form
[
'test_field'
]
=
[
'#type'
=>
'submit'
,
'#value'
=>
$this
->
t
(
'Add field'
),
'#button_type'
=>
'primary'
,
'#ajax'
=>
[
'callback'
=>
'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addField'
,
'progress'
=>
[
'type'
=>
'throbber'
,
'message'
=>
NULL
,
],
'wrapper'
=>
'js_webassert_test_form_wrapper'
,
],
];
// Button to test for the waitForId() assertion.
$form
[
'test_id'
]
=
[
'#type'
=>
'submit'
,
'#value'
=>
$this
->
t
(
'Add ID'
),
'#button_type'
=>
'primary'
,
'#ajax'
=>
[
'callback'
=>
'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addId'
,
'progress'
=>
[
'type'
=>
'throbber'
,
'message'
=>
NULL
,
],
'wrapper'
=>
'js_webassert_test_form_wrapper'
,
],
];
// Button to test the assertWaitOnAjaxRequest() assertion.
$form
[
'test_wait_for_element_visible'
]
=
[
'#type'
=>
'submit'
,
'#value'
=>
$this
->
t
(
'Test waitForElementVisible'
),
'#button_type'
=>
'primary'
,
'#ajax'
=>
[
'callback'
=>
'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addWaitForElementVisible'
,
'progress'
=>
[
'type'
=>
'throbber'
,
'message'
=>
NULL
,
],
'wrapper'
=>
'js_webassert_test_form_wrapper'
,
],
];
// Button to test the assertWaitOnAjaxRequest() assertion.
$form
[
'test_assert_wait_on_ajax_request'
]
=
[
'#type'
=>
'submit'
,
'#value'
=>
$this
->
t
(
'Test assertWaitOnAjaxRequest'
),
'#button_type'
=>
'primary'
,
'#ajax'
=>
[
'callback'
=>
'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addAssertWaitOnAjaxRequest'
,
'progress'
=>
[
'type'
=>
'throbber'
,
'message'
=>
NULL
,
],
'wrapper'
=>
'js_webassert_test_form_wrapper'
,
],
];
return
$form
;
}
/**
* Ajax callback for the "Add button" button.
*/
public
static
function
addButton
(
array
$form
,
FormStateInterface
$form_state
)
{
$form
[
'added_button'
]
=
[
'#type'
=>
'submit'
,
'#value'
=>
'Added button'
,
'#button_type'
=>
'primary'
,
];
return
$form
;
}
/**
* Ajax callback for the "Add link" button.
*/
public
static
function
addLink
(
array
$form
,
FormStateInterface
$form_state
)
{
$form
[
'added_link'
]
=
[
'#title'
=>
'Added link'
,
'#type'
=>
'link'
,
'#url'
=>
Url
::
fromRoute
(
'js_webassert_test.js_webassert_test_form'
)
];
return
$form
;
}
/**
* Ajax callback for the "Add field" button.
*/
public
static
function
addField
(
array
$form
,
FormStateInterface
$form_state
)
{
$form
[
'added_field'
]
=
[
'#type'
=>
'textfield'
,
'#title'
=>
'Added textfield'
,
'#name'
=>
'added_field'
,
];
return
$form
;
}
/**
* Ajax callback for the "Add ID" button.
*/
public
static
function
addId
(
array
$form
,
FormStateInterface
$form_state
)
{
$form
[
'added_id'
]
=
[
'#id'
=>
'js_webassert_test_field_id'
,
'#type'
=>
'submit'
,
'#value'
=>
'Added ID'
,
'#button_type'
=>
'primary'
,
];
return
$form
;
}
/**
* Ajax callback for the "Test waitForAjax" button.
*/
public
static
function
addAssertWaitOnAjaxRequest
(
array
$form
,
FormStateInterface
$form_state
)
{
// Attach the library necessary for this test.
$form
[
'#attached'
][
'library'
][]
=
'js_webassert_test/wait_for_ajax_request'
;
$form
[
'test_assert_wait_on_ajax_input'
]
=
[
'#type'
=>
'textfield'
,
'#name'
=>
'test_assert_wait_on_ajax_input'
,
];
return
$form
;
}
/**
* Ajax callback for the "Test waitForElementVisible" button.
*/
public
static
function
addWaitForElementVisible
(
array
$form
,
FormStateInterface
$form_state
)
{
// Attach the library necessary for this test.
$form
[
'#attached'
][
'library'
][]
=
'js_webassert_test/wait_for_element'
;
$form
[
'element_invisible'
]
=
[
'#id'
=>
'js_webassert_test_element_invisible'
,
'#type'
=>
'submit'
,
'#value'
=>
'Added WaitForElementVisible'
,
'#button_type'
=>
'primary'
,
'#attributes'
=>
[
'style'
=>
[
'display: none;'
],
],
];
return
$form
;
}
/**
* {@inheritdoc}
*/
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
}
}
core/modules/user/config/schema/user.views.schema.yml
View file @
55845022
...
...
@@ -98,3 +98,7 @@ views.filter.user_permissions:
views.filter.user_roles
:
type
:
views.filter.many_to_one
label
:
'
Role'
views.filter_value.user_current
:
type
:
views.filter_value.boolean
label
:
'
Current
user'
core/modules/user/migration_templates/d7_user.yml
View file @
55845022
...
...
@@ -48,6 +48,7 @@ migration_dependencies:
required
:
-
d7_user_role
optional
:
-
d7_field_instance
-
d7_file
-
language
-
default_language
...
...
core/modules/user/src/Plugin/migrate/User.php
View file @
55845022
...
...
@@ -3,19 +3,12 @@
namespace
Drupal\user\Plugin\migrate
;
use
Drupal\migrate\Exception\RequirementsException
;
use
Drupal\migrate\Plugin\Migration
;
use
Drupal\migrate
_drupal
\Plugin\
migrate\Cck
Migration
;
/**
* Plugin class for Drupal 7 user migrations dealing with fields and profiles.
*/
class
User
extends
Migration
{
/**
* Flag indicating whether the CCK data has been filled already.
*
* @var bool
*/
protected
$init
=
FALSE
;
class
User
extends
CckMigration
{
/**
* {@inheritdoc}
...
...
@@ -33,7 +26,21 @@ public function getProcess() {
$field_migration
=
$this
->
migrationPluginManager
->
createStubMigration
(
$definition
);
foreach
(
$field_migration
->
getSourcePlugin
()
as
$row
)
{
$field_name
=
$row
->
getSourceProperty
(
'field_name'
);
$this
->
process
[
$field_name
]
=
$field_name
;
$field_type
=
$row
->
getSourceProperty
(
'type'
);
if
(
empty
(
$field_type
))
{
continue
;
}
if
(
$this
->
cckPluginManager
->
hasDefinition
(
$field_type
))
{
if
(
!
isset
(
$this
->
cckPluginCache
[
$field_type
]))
{
$this
->
cckPluginCache
[
$field_type
]
=
$this
->
cckPluginManager
->
createInstance
(
$field_type
,
[],
$this
);
}
$info
=
$row
->
getSource
();
$this
->
cckPluginCache
[
$field_type
]
->
processCckFieldValues
(
$this
,
$field_name
,
$info
);
}
else
{
$this
->
process
[
$field_name
]
=
$field_name
;
}
}
}
try
{
...
...
core/modules/user/tests/modules/user_test_views/test_views/views.view.test_filter_current_user.yml
0 → 100644
View file @
55845022
langcode
:
en
status
:
true
dependencies
:
module
:
-
user
id
:
test_filter_current_user
label
:
Users
module
:
views
description
:
'
'
tag
:
'
'
base_table
:
users_field_data
base_field
:
uid
core
:
8.x
display
:
default
:
display_plugin
:
default
id
:
default
display_title
:
Master
position
:
0
display_options
:
access
:
type
:
none
cache
:
type
:
tag
query
:
type
:
views_query
options
:
disable_sql_rewrite
:
false
distinct
:
false
replica
:
false
query_comment
:
'
'
exposed_form
:
type
:
basic
options
:
submit_button
:
Filter
reset_button
:
false
reset_button_label
:
Reset
exposed_sorts_label
:
'
Sort
by'
expose_sort_order
:
true
sort_asc_label
:
Asc
sort_desc_label
:
Desc
pager
:
type
:
none
options
:
offset
:
0
style
:
type
:
default
options
:
row_class
:
'
'
default_row_class
:
true
uses_fields
:
false
row
:
type
:
fields
options
:
separator
:
'
'
hide_empty
:
false
default_field_elements
:
true
fields
:
uid
:
id
:
uid
table
:
users
field
:
uid
relationship
:
none
group_type
:
group
admin_label
:
'
'
label
:
'
'
exclude
:
false
filters
:
uid_current
:
id
:
uid_current
table
:
users
field
:
uid_current
relationship
:
none
group_type
:
group
admin_label
:
'
'
operator
:
'
='
value
:
'
1'
group
:
1
exposed
:
false
expose
:
operator_id
:
'
'
label
:
'
'
description
:
'
'
use_operator
:
false
operator
:
'
'
identifier
:
'
'
required
:
false
remember
:
false
multiple
:
false
remember_roles
:
authenticated
:
authenticated
is_grouped
:
false
group_info
:
label
:
'
'
description
:
'
'
identifier
:
'
'
optional
:
true
widget
:
select
multiple
:
false
remember
:
false
default_group
:
All
default_group_multiple
:
{
}
group_items
:
{
}
entity_type
:
user
plugin_id
:
user_current
sorts
:
{
}
header
:
{
}
footer
:
{
}
empty
:
{
}
relationships
:
{
}
arguments
:
{
}
display_extenders
:
{
}
cache_metadata
:
max-age
:
-1
contexts
:
-
'
languages:language_content'
-
'
languages:language_interface'
-
user
tags
:
{
}
core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php
View file @
55845022
...
...
@@ -109,10 +109,12 @@ protected function createType($id) {
* Role IDs the user account is expected to have.
* @param int $field_integer
* The value of the integer field.
* @param int|false $field_file_target_id
* (optional) The target ID of the file field.
* @param bool $has_picture
* Whether the user is expected to have a picture attached.
*
(optional)
Whether the user is expected to have a picture attached.
*/
protected
function
assertEntity
(
$id
,
$label
,
$mail
,
$password
,
$created
,
$access
,
$login
,
$blocked
,
$langcode
,
$timezone
,
$init
,
$roles
,
$field_integer
,
$has_picture
=
FALSE
)
{
protected
function
assertEntity
(
$id
,
$label
,
$mail
,
$password
,
$created
,
$access
,
$login
,
$blocked
,
$langcode
,
$timezone
,
$init
,
$roles
,
$field_integer
,
$field_file_target_id
=
FALSE
,
$has_picture
=
FALSE
)
{
/** @var \Drupal\user\UserInterface $user */
$user
=
User
::
load
(
$id
);
$this
->
assertTrue
(
$user
instanceof
UserInterface
);
...
...
@@ -155,6 +157,10 @@ protected function assertEntity($id, $label, $mail, $password, $created, $access
$this
->
assertTrue
(
$user
->
hasField
(
'field_integer'
));
$this
->
assertEquals
(
$field_integer
[
0
],
$user
->
field_integer
->
value
);
}
if
(
!
empty
(
$field_file_target_id
))
{
$this
->
assertTrue
(
$user
->
hasField
(
'field_file'
));
$this
->
assertSame
(
$field_file_target_id
,
$user
->
field_file
->
target_id
);
}
}
/**
...
...
@@ -190,6 +196,13 @@ public function testUser() {
->
fetchCol
();
$field_integer
=
!
empty
(
$field_integer
)
?
$field_integer
:
NULL
;
$field_file
=
Database
::
getConnection
(
'default'
,
'migrate'
)
->
select
(
'field_data_field_file'
,
'ff'
)
->
fields
(
'ff'
,
[
'field_file_fid'
])
->
condition
(
'ff.entity_id'
,
$source
->
uid
)
->
execute
()
->
fetchField
();
$this
->
assertEntity
(
$source
->
uid
,
$source
->
name
,
...
...
@@ -203,7 +216,8 @@ public function testUser() {
$source
->
timezone
,
$source
->
init
,
$roles
,
$field_integer
$field_integer
,
$field_file
);
// Ensure that the user can authenticate.
...
...
core/modules/user/tests/src/Kernel/Views/HandlerFilterCurrentUserTest.php
0 → 100644
View file @
55845022
<?php
namespace
Drupal\Tests\user\Kernel\Views
;
use
Drupal\views\Views
;
use
Drupal\Core\Session\AnonymousUserSession
;
/**
* Tests the current user filter handler.
*
* @group user
* @see \Drupal\user\Plugin\views\filter\Current
*/
class
HandlerFilterCurrentUserTest
extends
UserKernelTestBase
{
/**
* Views used by this test.
*
* @var array
*/
public
static
$testViews
=
[
'test_filter_current_user'
];
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxy
*/
protected
$currentUser
;
/**
* {@inheritdoc}
*/
protected
function
setUp
(
$import_test_views
=
TRUE
)
{
parent
::
setUp
();
$this
->
currentUser
=
$this
->
container
->
get
(
'current_user'
);
$this
->
setupPermissionTestData
();
}
/**
* Tests the current user filter handler with anonymous user.
*/
public
function
testFilterCurrentUserAsAnonymous
()
{
$column_map
=
[
'uid'
=>
'uid'
];
$this
->
currentUser
->
setAccount
(
new
AnonymousUserSession
());
$view
=
Views
::
getView
(
'test_filter_current_user'
);
$view
->
initHandlers
();
$view
->
filter
[
'uid_current'
]
->
value
=
0
;
$this
->
executeView
(
$view
);
$expected
[]
=
[
'uid'
=>
1
];
$expected
[]
=
[
'uid'
=>
2
];
$expected
[]
=
[
'uid'
=>
3
];
$expected
[]
=
[
'uid'
=>
4
];
$this
->
assertIdenticalResultset
(
$view
,
$expected
,
$column_map
,
'Anonymous account can view all accounts when current filter is FALSE.'
);
$view
->
destroy
();
$view
=
Views
::
getView
(
'test_filter_current_user'
);
$view
->
initHandlers
();
$view
->
filter
[
'uid_current'
]
->
value
=
1
;
$this
->
executeView
(
$view
);
$expected
=
[];
$this
->
assertIdenticalResultset
(
$view
,
$expected
,
$column_map
,
'Anonymous account can view zero accounts when current filter is TRUE.'
);
$view
->
destroy
();
}
/**
* Tests the current user filter handler with logged-in user.
*/
public
function
testFilterCurrentUserAsUser
()
{
$column_map
=
[
'uid'
=>
'uid'
];
$user
=
reset
(
$this
->
users
);
$this
->
currentUser
->
setAccount
(
$user
);
$view
=
Views
::
getView
(
'test_filter_current_user'
);
$view
->
initHandlers
();
$view
->
filter
[
'uid_current'
]
->
value
=
0
;
$this
->
executeView
(
$view
);
$expected
=
[];
$expected
[]
=
[
'uid'
=>
2
];
$expected
[]
=
[
'uid'
=>
3
];
$expected
[]
=
[
'uid'
=>
4
];
$this
->
assertIdenticalResultset
(
$view
,
$expected
,
$column_map
,
'User can view all users except itself when current filter is FALSE.'
);
$view
->
destroy
();
$view
=
Views
::
getView
(
'test_filter_current_user'
);
$view
->
initHandlers
();
$view
->
filter
[
'uid_current'
]
->
value
=
1
;
$this
->
executeView
(
$view
);
$expected
=
[];
$expected
[]
=
[
'uid'
=>
1
];
$this
->
assertIdenticalResultset
(
$view
,
$expected
,
$column_map
,
'User can only view itself when current filter is TRUE.'
);
$view
->
destroy
();
}
}
core/modules/user/user.api.php
View file @
55845022
...
...
@@ -109,13 +109,16 @@ function hook_user_cancel_methods_alter(&$methods) {
* that is displayed. Can be used to ensure user privacy in situations where
* $account->getDisplayName() is too revealing.
*
* @param string $name
* The string that $account->getDisplayName() will return.
*
* @param $account
* The account object the name belongs to.
* @param string|Drupal\Component\Render\MarkupInterface $name
* The username that is displayed for a user. If a hook implementation changes
* this to an object implementing MarkupInterface it is the responsibility of
* the implementation to ensure the user's name is escaped properly. String
* values will be autoescaped.
* @param \Drupal\Core\Session\AccountInterface $account
* The user object on which the operation is being performed.
*
* @see \Drupal\Core\Session\AccountInterface::getDisplayName()
* @see sanitization
*/
function
hook_user_format_name_alter
(
&
$name
,
$account
)
{
// Display the user's uid instead of name.
...
...
core/tests/Drupal/FunctionalJavascriptTests/Dialog/DialogPositionTest.php
0 → 100644
View file @
55845022
<?php
namespace
Drupal\FunctionalJavascriptTests\Dialog
;
use
Drupal\FunctionalJavascriptTests\JavascriptTestBase
;
/**
* Tests the JavaScript functionality of the dialog position.
*
* @group dialog
*/
class
DialogPositionTest
extends
JavascriptTestBase
{
/**
* {@inheritdoc}
*/
public
static
$modules
=
[
'block'
];
/**
* Tests if the dialog UI works properly with block layout page.
*/
public
function
testDialogOpenAndClose
()
{
$admin_user
=
$this
->
drupalCreateUser
([
'administer blocks'
]);
$this
->
drupalLogin
(
$admin_user
);
$this
->
drupalGet
(
'admin/structure/block'
);
$session
=
$this
->
getSession
();
$assert_session
=
$this
->
assertSession
();
$page
=
$session
->
getPage
();
// Open the dialog using the place block link.
$placeBlockLink
=
$page
->
findLink
(
'Place block'
);
$this
->
assertTrue
(
$placeBlockLink
->
isVisible
(),
'Place block button exists.'
);
$placeBlockLink
->
click
();
$assert_session
->
assertWaitOnAjaxRequest
();
$dialog
=
$page
->
find
(
'css'
,
'.ui-dialog'
);
$this
->
assertTrue
(
$dialog
->
isVisible
(),
'Dialog is opened after clicking the Place block button.'
);
// Close the dialog again.
$closeButton
=
$page
->
find
(
'css'
,
'.ui-dialog-titlebar-close'
);
$closeButton
->
click
();
$assert_session
->
assertWaitOnAjaxRequest
();
$dialog
=
$page
->
find
(
'css'
,
'.ui-dialog'
);
$this
->
assertNull
(
$dialog
,
'Dialog is closed after clicking the close button.'
);
// Resize the window. The test should pass after waiting for Javascript to
// finish as no Javascript errors should have been triggered. If there were
// javascript errors the test will fail on that.
$session
->
resizeWindow
(
625
,
625
);
$assert_session
->
assertWaitOnAjaxRequest
();
}
}
core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php
View file @
55845022
...
...
@@ -26,21 +26,149 @@ class JSWebAssert extends WebAssert {
* be displayed.
*/
public
function
assertWaitOnAjaxRequest
(
$timeout
=
10000
,
$message
=
'Unable to complete AJAX request.'
)
{
$result
=
$this
->
session
->
wait
(
$timeout
,
'(typeof(jQuery)=="undefined" || (0 === jQuery.active && 0 === jQuery(\':animated\').length))'
);
$condition
=
<<<JS
(function() {
function isAjaxing(instance) {
return instance && instance.ajaxing === true;
}
return (
// Assert no AJAX request is running (via jQuery or Drupal) and no
// animation is running.
(typeof jQuery === 'undefined' || (jQuery.active === 0 && jQuery(':animated').length === 0)) &&
(typeof Drupal === 'undefined' || typeof Drupal.ajax === 'undefined' || !Drupal.ajax.instances.some(isAjaxing))
);
}());
JS;
$result
=
$this
->
session
->
wait
(
$timeout
,
$condition
);
if
(
!
$result
)
{
throw
new
\RuntimeException
(
$message
);
}
}
/**
* Waits for the specified selector and returns it when available.
*
* @param string $selector
* The selector engine name. See ElementInterface::findAll() for the
* supported selectors.
* @param string|array $locator
* The selector locator.
* @param int $timeout
* (Optional) Timeout in milliseconds, defaults to 10000.
*
* @return \Behat\Mink\Element\NodeElement|null
* The page element node if found, NULL if not.
*
* @see \Behat\Mink\Element\ElementInterface::findAll()
*/
public
function
waitForElement
(
$selector
,
$locator
,
$timeout
=
10000
)
{
$page
=
$this
->
session
->
getPage
();
$result
=
$page
->
waitFor
(
$timeout
/
1000
,
function
()
use
(
$page
,
$selector
,
$locator
)
{
return
$page
->
find
(
$selector
,
$locator
);
});
return
$result
;
}
/**
* Waits for the specified selector and returns it when available and visible.
*
* @param string $selector
* The selector engine name. See ElementInterface::findAll() for the
* supported selectors.
* @param string|array $locator
* The selector locator.
* @param int $timeout
* (Optional) Timeout in milliseconds, defaults to 10000.
*
* @return \Behat\Mink\Element\NodeElement|null
* The page element node if found and visible, NULL if not.
*
* @see \Behat\Mink\Element\ElementInterface::findAll()
*/
public
function
waitForElementVisible
(
$selector
,
$locator
,
$timeout
=
10000
)
{
$page
=
$this
->
session
->
getPage
();
$result
=
$page
->
waitFor
(
$timeout
/
1000
,
function
()
use
(
$page
,
$selector
,
$locator
)
{
$element
=
$page
->
find
(
$selector
,
$locator
);
if
(
!
empty
(
$element
)
&&
$element
->
isVisible
())
{
return
$element
;
}
return
NULL
;
});
return
$result
;
}
/**
* Waits for a button (input[type=submit|image|button|reset], button) with
* specified locator and returns it.
*
* @param string $locator
* The button ID, value or alt string.
* @param int $timeout
* (Optional) Timeout in milliseconds, defaults to 10000.
*
* @return \Behat\Mink\Element\NodeElement|null
* The page element node if found, NULL if not.
*/
public
function
waitForButton
(
$locator
,
$timeout
=
10000
)
{
return
$this
->
waitForElement
(
'named'
,
array
(
'button'
,
$locator
),
$timeout
);
}
/**
* Waits for a link with specified locator and returns it when available.
*
* @param string $locator
* The link ID, title, text or image alt.
* @param int $timeout
* (Optional) Timeout in milliseconds, defaults to 10000.
*
* @return \Behat\Mink\Element\NodeElement|null
* The page element node if found, NULL if not.
*/
public
function
waitForLink
(
$locator
,
$timeout
=
10000
)
{
return
$this
->
waitForElement
(
'named'
,
array
(
'link'
,
$locator
),
$timeout
);
}
/**
* Waits for a field with specified locator and returns it when available.
*
* @param string $locator
* The input ID, name or label for the field (input, textarea, select).
* @param int $timeout
* (Optional) Timeout in milliseconds, defaults to 10000.
*
* @return \Behat\Mink\Element\NodeElement|null
* The page element node if found, NULL if not.
*/
public
function
waitForField
(
$locator
,
$timeout
=
10000
)
{
return
$this
->
waitForElement
(
'named'
,
array
(
'field'
,
$locator
),
$timeout
);
}
/**
* Waits for an element by its id and returns it when available.
*
* @param string $id
* The element ID.
* @param int $timeout
* (Optional) Timeout in milliseconds, defaults to 10000.
*
* @return \Behat\Mink\Element\NodeElement|null
* The page element node if found, NULL if not.
*/
public
function
waitForId
(
$id
,
$timeout
=
10000
)
{
return
$this
->
waitForElement
(
'named'
,
array
(
'id'
,
$id
),
$timeout
);
}
/**
* Waits for the jQuery autocomplete delay duration.
*
* @see https://api.jqueryui.com/autocomplete/#option-delay
*/
public
function
waitOnAutocomplete
()
{
// Drupal is using the default delay value of 300 milliseconds.
$this
->
session
->
wait
(
300
);
$this
->
assertWaitOnAjaxRequest
();
// Wait for the autocomplete to be visible.
return
$this
->
waitForElementVisible
(
'css'
,
'.ui-autocomplete li'
);
}
/**
...
...
core/tests/Drupal/FunctionalJavascriptTests/Tests/JSWebAssertTest.php
0 → 100644
View file @
55845022
<?php
namespace
Drupal\FunctionalJavascriptTests\Tests
;
use
Behat\Mink\Element\NodeElement
;
use
Drupal\FunctionalJavascriptTests\JavascriptTestBase
;
/**
* Tests for the JSWebAssert class.
*
* @group javascript
*/
class
JSWebAssertTest
extends
JavascriptTestBase
{
/**
* Required modules.
*
* @var array
*/
public
static
$modules
=
[
'js_webassert_test'
];
/**
* Tests that JSWebAssert assertions work correctly.
*/
public
function
testJsWebAssert
()
{
$this
->
drupalGet
(
'js_webassert_test_form'
);
$session
=
$this
->
getSession
();
$assert_session
=
$this
->
assertSession
();
$page
=
$session
->
getPage
();
$test_button
=
$page
->
findButton
(
'Add button'
);
$test_link
=
$page
->
findButton
(
'Add link'
);
$test_field
=
$page
->
findButton
(
'Add field'
);
$test_id
=
$page
->
findButton
(
'Add ID'
);
$test_wait_on_ajax
=
$page
->
findButton
(
'Test assertWaitOnAjaxRequest'
);
$test_wait_on_element_visible
=
$page
->
findButton
(
'Test waitForElementVisible'
);
// Test the wait...() methods by first checking the fields aren't available
// and then are available after the wait method.
$result
=
$page
->
findButton
(
'Added button'
);
$this
->
assertEmpty
(
$result
);
$test_button
->
click
();
$result
=
$assert_session
->
waitForButton
(
'Added button'
);
$this
->
assertNotEmpty
(
$result
);
$this
->
assertTrue
(
$result
instanceof
NodeElement
);
$result
=
$page
->
findLink
(
'Added link'
);
$this
->
assertEmpty
(
$result
);
$test_link
->
click
();
$result
=
$assert_session
->
waitForLink
(
'Added link'
);
$this
->
assertNotEmpty
(
$result
);
$this
->
assertTrue
(
$result
instanceof
NodeElement
);
$result
=
$page
->
findField
(
'added_field'
);
$this
->
assertEmpty
(
$result
);
$test_field
->
click
();
$result
=
$assert_session
->
waitForField
(
'added_field'
);
$this
->
assertNotEmpty
(
$result
);
$this
->
assertTrue
(
$result
instanceof
NodeElement
);
$result
=
$page
->
findById
(
'js_webassert_test_field_id'
);
$this
->
assertEmpty
(
$result
);
$test_id
->
click
();
$result
=
$assert_session
->
waitForId
(
'js_webassert_test_field_id'
);
$this
->
assertNotEmpty
(
$result
);
$this
->
assertTrue
(
$result
instanceof
NodeElement
);
// Test waitOnAjaxRequest. Verify the element is available after the wait
// and the behaviors have run on completing by checking the value.
$result
=
$page
->
findField
(
'test_assert_wait_on_ajax_input'
);
$this
->
assertEmpty
(
$result
);
$test_wait_on_ajax
->
click
();
$assert_session
->
assertWaitOnAjaxRequest
();
$result
=
$page
->
findField
(
'test_assert_wait_on_ajax_input'
);
$this
->
assertNotEmpty
(
$result
);
$this
->
assertTrue
(
$result
instanceof
NodeElement
);
$this
->
assertEquals
(
'js_webassert_test'
,
$result
->
getValue
());
$result
=
$page
->
findButton
(
'Added WaitForElementVisible'
);
$this
->
assertEmpty
(
$result
);
$test_wait_on_element_visible
->
click
();
$result
=
$assert_session
->
waitForElementVisible
(
'named'
,
array
(
'button'
,
'Added WaitForElementVisible'
));
$this
->
assertNotEmpty
(
$result
);
$this
->
assertTrue
(
$result
instanceof
NodeElement
);
$this
->
assertEquals
(
TRUE
,
$result
->
isVisible
());
}
}
core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
View file @
55845022
...
...
@@ -113,4 +113,12 @@ public function testLegacyAsserts() {
$this
->
assertText
(
$sanitized
);
}
/**
* Tests the Drupal install done in \Drupal\Tests\BrowserTestBase::setUp().
*/
public
function
testInstall
()
{
$htaccess_filename
=
$this
->
tempFilesDirectory
.
'/.htaccess'
;
$this
->
assertTrue
(
file_exists
(
$htaccess_filename
),
"
$htaccess_filename
exists"
);
}
}
Prev
1
2
3
4
5
Next