Issue #2181855 by Cottser: Don't let ViewTestBase hog the useful assertBlockAppears and assertNoBlockAppears methods.
parent
f7e9c1578e
commit
048cd4512a
|
@ -18,6 +18,7 @@ use Drupal\Core\Session\AccountInterface;
|
|||
use Drupal\Core\Session\UserSession;
|
||||
use Drupal\Core\StreamWrapper\PublicStream;
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\block\Entity\Block;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
|
@ -385,6 +386,41 @@ abstract class WebTestBase extends TestBase {
|
|||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see whether a block appears on the page.
|
||||
*
|
||||
* @param \Drupal\block\Entity\Block $block
|
||||
* The block entity to find on the page.
|
||||
*/
|
||||
protected function assertBlockAppears(Block $block) {
|
||||
$result = $this->findBlockInstance($block);
|
||||
$this->assertTrue(!empty($result), format_string('Ensure the block @id appears on the page', array('@id' => $block->id())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see whether a block does not appears on the page.
|
||||
*
|
||||
* @param \Drupal\block\Entity\Block $block
|
||||
* The block entity to find on the page.
|
||||
*/
|
||||
protected function assertNoBlockAppears(Block $block) {
|
||||
$result = $this->findBlockInstance($block);
|
||||
$this->assertFalse(!empty($result), format_string('Ensure the block @id does not appear on the page', array('@id' => $block->id())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a block instance on the page.
|
||||
*
|
||||
* @param \Drupal\block\Entity\Block $block
|
||||
* The block entity to find on the page.
|
||||
*
|
||||
* @return array
|
||||
* The result from the xpath query.
|
||||
*/
|
||||
protected function findBlockInstance(Block $block) {
|
||||
return $this->xpath('//div[@id = :id]', array(':id' => 'block-' . $block->id()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list files that can be used in tests.
|
||||
*
|
||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\views\Tests;
|
|||
use Drupal\Core\Database\Query\SelectInterface;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\views\ViewExecutable;
|
||||
use Drupal\block\Entity\Block;
|
||||
|
||||
/**
|
||||
* Defines a base class for Views testing in the full web test environment.
|
||||
|
@ -239,41 +238,6 @@ abstract class ViewTestBase extends WebTestBase {
|
|||
$this->verbose($verbose_message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see whether a block appears on the page.
|
||||
*
|
||||
* @param \Drupal\block\Entity\Block $block
|
||||
* The block entity to find on the page.
|
||||
*/
|
||||
protected function assertBlockAppears(Block $block) {
|
||||
$result = $this->findBlockInstance($block);
|
||||
$this->assertTrue(!empty($result), format_string('Ensure the block @id appears on the page', array('@id' => $block->id())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see whether a block does not appears on the page.
|
||||
*
|
||||
* @param \Drupal\block\Entity\Block $block
|
||||
* The block entity to find on the page.
|
||||
*/
|
||||
protected function assertNoBlockAppears(Block $block) {
|
||||
$result = $this->findBlockInstance($block);
|
||||
$this->assertFalse(!empty($result), format_string('Ensure the block @id does not appear on the page', array('@id' => $block->id())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a block instance on the page.
|
||||
*
|
||||
* @param \Drupal\block\Entity\Block $block
|
||||
* The block entity to find on the page.
|
||||
*
|
||||
* @return array
|
||||
* The result from the xpath query.
|
||||
*/
|
||||
protected function findBlockInstance(Block $block) {
|
||||
return $this->xpath('//div[@id = :id]', array(':id' => 'block-' . $block->id()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the schema definition.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue