class UserUnauthorizedTest in Freelinking 8.3
Same name and namespace in other branches
- 4.0.x tests/src/Unit/Plugin/freelinking/UserUnauthorizedTest.php \Drupal\Tests\freelinking\Unit\Plugin\freelinking\UserUnauthorizedTest
Tests the user plugin when the current user does not have access.
@group freelinking
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\freelinking\Unit\Plugin\freelinking\UserUnauthorizedTest
Expanded class hierarchy of UserUnauthorizedTest
File
- tests/
src/ Unit/ Plugin/ freelinking/ UserUnauthorizedTest.php, line 16
Namespace
Drupal\Tests\freelinking\Unit\Plugin\freelinkingView source
class UserUnauthorizedTest extends UnitTestCase {
/**
* The translation interface.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface
*/
protected $translationInterfaceMock;
/**
* The plugin to test.
*
* @var \Drupal\freelinking\Plugin\freelinking\Node
*/
protected $plugin;
/**
* {@inheritdoc}
*/
protected function setUp() {
// Mock string translation interface.
$tProphet = $this
->prophesize('\\Drupal\\Core\\StringTranslation\\TranslationInterface');
$tProphet
->translateString(Argument::any())
->willReturn('Unauthorized to view user profile.');
$this->translationInterfaceMock = $tProphet
->reveal();
// Mock current user interface.
$currentUserProphet = $this
->prophesize('\\Drupal\\Core\\Session\\AccountProxyInterface');
$currentUserProphet
->hasPermission('access user profiles')
->willReturn(FALSE);
// Mock entity type manager;
$entityManagerProphet = $this
->prophesize('\\Drupal\\Core\\Entity\\EntityTypeManagerInterface');
$container = new ContainerBuilder();
$container
->set('entity_type.manager', $entityManagerProphet
->reveal());
$container
->set('string_translation', $this->translationInterfaceMock);
$container
->set('current_user', $currentUserProphet
->reveal());
\Drupal::setContainer($container);
$this->container = $container;
$plugin_definition = [
'id' => 'user',
'title' => 'User',
'weight' => 0,
'hidden' => FALSE,
'settings' => [],
];
$this->plugin = User::create($container, [], 'user', $plugin_definition);
}
/**
* Assert the buildLink method returns correct render array.
*/
public function testBuildLink() {
$expected = [
'#theme' => 'freelink_error',
'#plugin' => 'user',
'#message' => new TranslatableMarkup('Unauthorized to view user profile.', [], [], $this->translationInterfaceMock),
];
$target = [
'target' => 'uid:2|Some user',
'dest' => '2',
'language' => NULL,
];
$this
->assertEquals($expected, $this->plugin
->buildLink($target));
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UserUnauthorizedTest:: |
protected | property | The plugin to test. | |
UserUnauthorizedTest:: |
protected | property | The translation interface. | |
UserUnauthorizedTest:: |
protected | function |
Overrides UnitTestCase:: |
|
UserUnauthorizedTest:: |
public | function | Assert the buildLink method returns correct render array. |