Skip to content

Instantly share code, notes, and snippets.

@pasankg
Last active June 22, 2017 00:26
Show Gist options
  • Save pasankg/f777808dade16a96100d963dbd617729 to your computer and use it in GitHub Desktop.
Save pasankg/f777808dade16a96100d963dbd617729 to your computer and use it in GitHub Desktop.
<?php
use Drupal\Tests\bravo_testing\Functional\BravoFunctionalTestBase;
/**
* Tests for the custom block.
*/
class CustomBlockFunctionalTest extends BravoFunctionalTestBase {
/**
* Data Provider.
*/
public function addDataProvider() {
return [
'block 1' => ['fc4970c1-ed11-4ea9-adb9-47f40b37aff9', 'Edit Title-1'],
'block 2' => ['57eb1eb6-e3f2-4314-963a-cf19afc957d0', 'Edit Title-2'],
];
}
/**
* Test for custom blocks.
*
* @param string $uuid
* For block uuid.
* @param string $title
* For title of the block.
*
* @dataProvider addDataProvider
*/
public function testBlockContent($uuid, $title) {
$entityRepository = $this->container->get('entity.repository');
$block = $entityRepository->loadEntityByUuid('block_content', $uuid);
$this->drupalGet('<front>');
$page = $this->getSession()->getPage();
$this->assertTrue($page->hasContent($block->label()), 'Title mismatch -1 ' . $page->hasContent($block->label()));
$block->setInfo($title);
$block->save();
$this->drupalGet('<front>');
$page = $this->getSession()->getPage();
$this->assertTrue($page->hasContent($title), 'Title mismatch -2 ' . $block->label() . ' ' . $title);
}
}
@pasankg
Copy link
Author

pasankg commented Jun 22, 2017

if the content before the first test are different the test fails and gives

There was 1 failure:

  1. CustomBlockFunctionalTest::testBlockContent with data set "block 1" ('fc4970c1-ed11-4ea9-adb9-47f40b37aff9', 'Edit Title-1')
    Title mismatch -2 Edit Title-1 Edit Title-1
    Failed asserting that false is true.

But if I run the test again, it passes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment