Skip to content

Instantly share code, notes, and snippets.

@jhedstrom
Created October 15, 2014 21:34
Show Gist options
  • Save jhedstrom/c5f39c71f99ad5a8451c to your computer and use it in GitHub Desktop.
Save jhedstrom/c5f39c71f99ad5a8451c to your computer and use it in GitHub Desktop.
Gherkin as an abstraction to complex tests
Given I am viewing an "Article" with the title "My article"
Then I should see the "Revisions" link
And I should see the "Edit" link
And I should see the "View" link
<?php
/**
* @file
* Contains \Drupal\node\Tests\NodeViewTest.
*/
namespace Drupal\node\Tests;
/**
* Tests the node/{node} page.
*
* @group node
* @see \Drupal\node\Controller\NodeController
*/
class NodeViewTest extends NodeTestBase {
/**
* Tests the html head links.
*/
public function testHtmlHeadLinks() {
$node = $this->drupalCreateNode();
$this->drupalGet($node->getSystemPath());
$result = $this->xpath('//link[@rel = "version-history"]');
$this->assertEqual($result[0]['href'], _url("node/{$node->id()}/revisions"));
$result = $this->xpath('//link[@rel = "edit-form"]');
$this->assertEqual($result[0]['href'], _url("node/{$node->id()}/edit"));
$result = $this->xpath('//link[@rel = "canonical"]');
$this->assertEqual($result[0]['href'], _url("node/{$node->id()}"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment