public function ContentEntityExampleTest::testPaths in Examples for Developers 8
Same name and namespace in other branches
- 3.x modules/content_entity_example/tests/src/Functional/ContentEntityExampleTest.php \Drupal\Tests\content_entity_example\Functional\ContentEntityExampleTest::testPaths()
 
Test all paths exposed by the module, by permission.
File
- content_entity_example/
tests/ src/ Functional/ ContentEntityExampleTest.php, line 118  
Class
- ContentEntityExampleTest
 - Tests the basic functions of the Content Entity Example module.
 
Namespace
Drupal\Tests\content_entity_example\FunctionalCode
public function testPaths() {
  $assert = $this
    ->assertSession();
  // Generate a contact so that we can test the paths against it.
  $contact = Contact::create([
    'name' => 'somename',
    'first_name' => 'Joe',
    'role' => 'administrator',
  ]);
  $contact
    ->save();
  // Gather the test data.
  $data = $this
    ->providerTestPaths($contact
    ->id());
  // Run the tests.
  foreach ($data as $datum) {
    // drupalCreateUser() doesn't know what to do with an empty permission
    // array, so we help it out.
    if ($datum[2]) {
      $user = $this
        ->drupalCreateUser([
        $datum[2],
      ]);
      $this
        ->drupalLogin($user);
    }
    else {
      $user = $this
        ->drupalCreateUser();
      $this
        ->drupalLogin($user);
    }
    $this
      ->drupalGet($datum[1]);
    $assert
      ->statusCodeEquals($datum[0]);
  }
}