public function ModerationDashboardPersonalizedComponentsTest::testModerationElement in Moderation Dashboard 8
Same name and namespace in other branches
- 2.0.x tests/src/Functional/ModerationDashboardPersonalizedComponentsTest.php \Drupal\Tests\moderation_dashboard\Functional\ModerationDashboardPersonalizedComponentsTest::testModerationElement()
Tests that blocks and other elements exist on the user dashboard.
File
- tests/
src/ Functional/ ModerationDashboardPersonalizedComponentsTest.php, line 89
Class
- ModerationDashboardPersonalizedComponentsTest
- Tests personalized moderation dashboard components.
Namespace
Drupal\Tests\moderation_dashboard\FunctionalCode
public function testModerationElement() {
$users = [
$this->user,
$this->moderatorUser,
$this->regularUser,
];
foreach ($users as $delta => $user) {
$this
->drupalGet('/user/' . $user
->id() . '/moderation/dashboard');
// Iterating over personailzed elements.
foreach ($this->personalizedModerationElements as $selector => $asserts) {
$moderation_element = $this
->assertSession()
->elementExists('css', $selector);
$moderation_element_text = $moderation_element
->getText();
if (!empty($asserts['empty'])) {
$this
->assertSame(FALSE, strpos($moderation_element_text, $asserts['empty']));
}
if (!empty($asserts['contains'])) {
foreach ($asserts['contains'] as $pattern_to_find) {
$this
->assertNotSame(FALSE, strpos($moderation_element_text, sprintf($pattern_to_find, $user
->getDisplayName())));
}
}
if (!empty($asserts['not_contains'])) {
foreach ($asserts['not_contains'] as $pattern_shoud_not_find) {
$this
->assertSame(FALSE, strpos($moderation_element_text, sprintf($pattern_shoud_not_find, $user
->getDisplayName())));
}
}
$other_users = $users;
unset($other_users[$delta]);
foreach ($other_users as $other_user) {
$this
->assertSame(FALSE, strpos($moderation_element
->getText(), sprintf('%s', $other_user
->getDisplayName())));
}
}
}
$user_without_content = $this
->createUser([
'access content',
'use moderation dashboard',
]);
// Check user's dashboard who does not own node revisions at all.
$this
->drupalGet('/user/' . $user_without_content
->id() . '/moderation/dashboard');
// Verify that every personalized component shows the expected empty
// message.
foreach ($this->personalizedModerationElements as $selector => $asserts) {
$moderation_element = $this
->assertSession()
->elementExists('css', $selector);
if (!empty($asserts['empty'])) {
$this
->assertNotSame(FALSE, strpos($moderation_element
->getText(), $asserts['empty']));
}
}
}