Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
2a317f41
Commit
2a317f41
authored
Jul 04, 2015
by
Jess
Browse files
Issue
#2511584
by jhedstrom, rpayanm: Move NodeFormButtonsTest::assertButtons() to a trait
parent
e0e935b7
Changes
2
Hide whitespace changes
Inline
Side-by-side
core/modules/node/src/Tests/AssertButtonsTrait.php
0 → 100644
View file @
2a317f41
<?php
/**
* @file
* Contains \Drupal\node\Tests\AssertButtonsTrait.
*/
namespace
Drupal\node\Tests
;
/**
* Asserts that buttons are present on a page.
*/
trait
AssertButtonsTrait
{
/**
* Assert method to verify the buttons in the dropdown element.
*
* @param array $buttons
* A collection of buttons to assert for on the page.
* @param bool $dropbutton
* Whether to check if the buttons are in a dropbutton widget or not.
*/
public
function
assertButtons
(
$buttons
,
$dropbutton
=
TRUE
)
{
// Try to find a Save button.
$save_button
=
$this
->
xpath
(
'//input[@type="submit"][@value="Save"]'
);
// Verify that the number of buttons passed as parameters is
// available in the dropbutton widget.
if
(
$dropbutton
)
{
$i
=
0
;
$count
=
count
(
$buttons
);
// Assert there is no save button.
$this
->
assertTrue
(
empty
(
$save_button
));
// Dropbutton elements.
$elements
=
$this
->
xpath
(
'//div[@class="dropbutton-wrapper"]//input[@type="submit"]'
);
$this
->
assertEqual
(
$count
,
count
(
$elements
));
foreach
(
$elements
as
$element
)
{
$value
=
isset
(
$element
[
'value'
])
?
(
string
)
$element
[
'value'
]
:
''
;
$this
->
assertEqual
(
$buttons
[
$i
],
$value
);
$i
++
;
}
}
else
{
// Assert there is a save button.
$this
->
assertTrue
(
!
empty
(
$save_button
));
$this
->
assertNoRaw
(
'dropbutton-wrapper'
);
}
}
}
core/modules/node/src/Tests/NodeFormButtonsTest.php
View file @
2a317f41
...
...
@@ -14,6 +14,8 @@
*/
class
NodeFormButtonsTest
extends
NodeTestBase
{
use
AssertButtonsTrait
;
/**
* A normal logged in user.
*
...
...
@@ -134,42 +136,4 @@ function testNodeFormButtons() {
$node_3
=
$node_storage
->
load
(
3
);
$this
->
assertFalse
(
$node_3
->
isPublished
(),
'Node is unpublished'
);
}
/**
* Assert method to verify the buttons in the dropdown element.
*
* @param array $buttons
* A collection of buttons to assert for on the page.
* @param bool $dropbutton
* Whether to check if the buttons are in a dropbutton widget or not.
*/
public
function
assertButtons
(
$buttons
,
$dropbutton
=
TRUE
)
{
// Try to find a Save button.
$save_button
=
$this
->
xpath
(
'//input[@type="submit"][@value="Save"]'
);
// Verify that the number of buttons passed as parameters is
// available in the dropbutton widget.
if
(
$dropbutton
)
{
$i
=
0
;
$count
=
count
(
$buttons
);
// Assert there is no save button.
$this
->
assertTrue
(
empty
(
$save_button
));
// Dropbutton elements.
$elements
=
$this
->
xpath
(
'//div[@class="dropbutton-wrapper"]//input[@type="submit"]'
);
$this
->
assertEqual
(
$count
,
count
(
$elements
));
foreach
(
$elements
as
$element
)
{
$value
=
isset
(
$element
[
'value'
])
?
(
string
)
$element
[
'value'
]
:
''
;
$this
->
assertEqual
(
$buttons
[
$i
],
$value
);
$i
++
;
}
}
else
{
// Assert there is a save button.
$this
->
assertTrue
(
!
empty
(
$save_button
));
$this
->
assertNoRaw
(
'dropbutton-wrapper'
);
}
}
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment