You are here

LinkedinAuthTest.php in Social Auth LinkedIn 8

File

tests/src/Functional/LinkedinAuthTest.php
View source
<?php

namespace Drupal\Tests\social_auth_linkedin\Functional;

use Drupal\Tests\BrowserTestBase;

/**
 * Test the user-facing auth button generated by social_auth_linkedin.
 *
 * @group social_auth_linkedin
 * @group social_auth
 *
 * @ingroup social_auth_linkedin
 */
class LinkedinAuthTest extends BrowserTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = [
    'social_auth',
    'social_auth_linkedin',
  ];

  /**
   * The installation profile to use with this test.
   *
   * This test class requires the "Tools" block.
   *
   * @var string
   */
  protected $profile = 'minimal';

  /**
   * Tests configuration page.
   *
   * @throws \Behat\Mink\Exception\ElementNotFoundException
   */
  public function testConfigPage() {
    $assert = $this
      ->assertSession();

    // Verify that permissions are applied to the various defined paths.
    // Define some paths. Since the Marvin entity is defined, we can use it
    // in our management paths.
    $forbidden_paths = [
      '/admin/config/social-api/social-auth/linkedin',
    ];

    // Check each of the paths to make sure we don't have access. At this point
    // we haven't logged in any users, so the client is anonymous.
    foreach ($forbidden_paths as $path) {
      $this
        ->drupalGet($path);
      $assert
        ->statusCodeEquals(403);
    }

    // Create a user with no permissions.
    $noperms_user = $this
      ->drupalCreateUser();
    $this
      ->drupalLogin($noperms_user);

    // Should be the same result for forbidden paths, since the user needs
    // special permissions for these paths.
    foreach ($forbidden_paths as $path) {
      $this
        ->drupalGet($path);
      $assert
        ->statusCodeEquals(403);
    }

    // Create a user who can administer social api auth.
    $admin_user = $this
      ->drupalCreateUser([
      'administer social api authentication',
    ]);
    $this
      ->drupalLogin($admin_user);

    // Forbidden paths aren't forbidden any more.
    foreach ($forbidden_paths as $unforbidden) {
      $this
        ->drupalGet($unforbidden);
      $assert
        ->statusCodeEquals(200);
    }

    // Now that we have the admin user logged in, check the menu links.
    $this
      ->drupalGet('/admin/config/social-api/social-auth/linkedin');
    $assert
      ->pageTextContains('LINKEDIN CLIENT SETTINGS');
    $assert
      ->fieldExists('client_id');
  }

}

Classes

Namesort descending Description
LinkedinAuthTest Test the user-facing auth button generated by social_auth_linkedin.