diff --git a/contextual_links_example/tests/src/FunctionalJavascript/ContextualLinksExampleTest.php b/contextual_links_example/tests/src/FunctionalJavascript/ContextualLinksExampleTest.php index aee1794..1958850 100644 --- a/contextual_links_example/tests/src/FunctionalJavascript/ContextualLinksExampleTest.php +++ b/contextual_links_example/tests/src/FunctionalJavascript/ContextualLinksExampleTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\contextual_links_example\FunctionalJavascript; use Drupal\FunctionalJavascriptTests\JavascriptTestBase; -use Drupal\user\Entity\Role; /** * Tests the behavior of the contextual links provided by the module. @@ -22,29 +21,33 @@ class ContextualLinksExampleTest extends JavascriptTestBase { */ public static $modules = [ 'node', - 'contextual_links_example' + 'system', + 'contextual_links_example', + 'views', ]; /** - * The installation profile to use with this test. - * - * This test class requires the "Tools" block. - * - * @var string - */ - protected $profile = 'minimal'; - - /** * {@inheritdoc} */ protected function setUp() { parent::setUp(); + // Create and login an admin user. + $this->drupalLogin($this->createUser([ + 'administer blocks', + 'administer nodes', + 'access contextual links', + ])); + // Place our custom block in sidebar first. $this->placeBlock('cleblock'); - + // Create a content type. + $this->drupalCreateContentType(['type' => 'page']); // Create a node and promote it to the front page. $this->drupalCreateNode(['promote' => 1]); + + // Configure 'node' as front page. + $this->config('system.site')->set('page.front', '/node')->save(); } /** @@ -53,38 +56,21 @@ class ContextualLinksExampleTest extends JavascriptTestBase { public function testContextualLinksExampleBasic() { $assert = $this->assertSession(); - // Create user. - $web_user = $this->drupalCreateUser([ - 'access contextual links', - ]); - // Login the admin user. - $this->drupalLogin($web_user); - - // Grant permissions to use contextual links on blocks. - $this->grantPermissions(Role::load(Role::AUTHENTICATED_ID), [ - 'access contextual links', - 'administer blocks', - ]); - - // We check for a link to the contextual example in the Tools menu. - $this->drupalGet('node'); - $this->assertSession()->linkByHrefExists('examples/contextual-links'); - - $this->drupalGet('examples/contextual-links'); - $this->assertSession()->statusCodeEquals(200); - $this->drupalGet('node'); // Check the presence of contextual link "Edit object" on our block. - $contextualLinks = $this->assertSession()->waitForElement('css', '.contextual-links-exampleconfigure'); + $contextualLinks = $assert->waitForElement('css', '.contextual-links-exampleconfigure'); $this->assertNotEmpty($contextualLinks); // Check the presence of contextual link "Example Action" on our node. - $contextualLinks = $this->assertSession()->waitForElement('css', '.contextual-links-exampleexample-action'); - $this->assertNotEmpty($contextualLinks); + $actionContextualLink = $assert->waitForElement('css', '.contextual-links-exampleexample-action'); + $this->assertNotEmpty($actionContextualLink); + + + $this->drupalGet('examples/contextual-links'); + $assert->statusCodeEquals(200); // Visit our example overview page and check for presence of contextual links. - $this->$this->drupalGet('examples/contextual-links'); - $contextualLinks = $this->assertSession()->waitForElement('css', '.contextual-links-exampleconfigure'); + $contextualLinks = $assert->waitForElement('css', '.contextual-links-exampleconfigure'); $this->assertNotEmpty($contextualLinks); }