protected function UserTest::setUp in Freelinking 8.3
Same name and namespace in other branches
- 4.0.x tests/src/Unit/Plugin/freelinking/UserTest.php \Drupal\Tests\freelinking\Unit\Plugin\freelinking\UserTest::setUp()
Overrides UnitTestCase::setUp
File
- tests/
src/ Unit/ Plugin/ freelinking/ UserTest.php, line 36
Class
- UserTest
- Tests the user plugin.
Namespace
Drupal\Tests\freelinking\Unit\Plugin\freelinkingCode
protected function setUp() {
// Mock string translation interface.
$tProphet = $this
->prophesize('\\Drupal\\Core\\StringTranslation\\TranslationInterface');
$tProphet
->translateString(Argument::any())
->willReturn('Click 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(TRUE);
// Mock user account entity.
$userProphet = $this
->prophesize('\\Drupal\\user\\Entity\\User');
$userProphet
->id()
->willReturn(1);
$userProphet
->getDisplayName()
->willReturn('admin');
// Mock user storage interface.
$userStorageProphet = $this
->prophesize('\\Drupal\\user\\UserStorageInterface');
$userStorageProphet
->load(1)
->willReturn($userProphet
->reveal());
$userStorageProphet
->load(2)
->willReturn(NULL);
$userStorageProphet
->loadByProperties([
'name' => 'admin',
])
->willReturn([
$userProphet
->reveal(),
]);
// Mock entity type manager.
$entityManagerProphet = $this
->prophesize('\\Drupal\\Core\\Entity\\EntityTypeManagerInterface');
$entityManagerProphet
->getStorage('user')
->willReturn($userStorageProphet
->reveal());
$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',
'hidden' => FALSE,
'weight' => 0,
'settings' => [],
];
$this->plugin = User::create($container, [], 'user', $plugin_definition);
}