public function SimpleFbConnectUserManagerTest::testCreateUser in Simple FB Connect 8.3
Same name and namespace in other branches
- 8.2 tests/src/Unit/SimpleFbConnectUserManagerTest.php \Drupal\Tests\simple_fb_connect\Unit\SimpleFbConnectUserManagerTest::testCreateUser()
Tests createUser method when user creation is allowed.
@covers ::createUser @covers ::registrationBlocked
File
- tests/
src/ Unit/ SimpleFbConnectUserManagerTest.php, line 217
Class
- SimpleFbConnectUserManagerTest
- @coversDefaultClass Drupal\simple_fb_connect\SimpleFbConnectUserManager @group simple_fb_connect
Namespace
Drupal\Tests\simple_fb_connect\UnitCode
public function testCreateUser() {
// User object that will be created in this test.
$user = $this
->getMockBuilder('Drupal\\user\\Entity\\User')
->disableOriginalConstructor()
->getMock();
// Storage object that will be created in this test.
$storage = $this
->getMockBuilder('Drupal\\Core\\Entity\\EntityStorageInterface')
->getMock();
// Language object that will be created in this test.
$language = $this
->getMockBuilder('Drupal\\Core\\Language\\LanguageInterface')
->getMock();
// Called when we're generating an unique username.
$storage
->expects($this
->once())
->method('loadByProperties')
->willReturn([]);
// Called when user is created.
$storage
->expects($this
->once())
->method('create')
->willReturn($user);
// EntityTypeManager that will return $storage.
$this->entityTypeManager
->expects($this
->any())
->method('getStorage')
->with('user')
->willReturn($storage);
// Called when current UI language is detected.
$language
->expects($this
->once())
->method('getId')
->willReturn('fi');
// LanguageManager that will return $language.
$this->languageManager
->expects($this
->once())
->method('getCurrentLanguage')
->willReturn($language);
$logger_channel = $this
->getMockBuilder('Drupal\\Core\\Logger\\LoggerChannel')
->disableOriginalConstructor()
->getMock();
$this->loggerFactory
->expects($this
->any())
->method('get')
->with('simple_fb_connect')
->willReturn($logger_channel);
$fb_profile_pic = $this
->getMockBuilder('Facebook\\GraphNodes\\GraphNode')
->disableOriginalConstructor()
->getMock();
$this
->assertInstanceOf('Drupal\\user\\Entity\\User', $this->userManager
->createUser('Firstname Lastname', 'foo@example.com', 12345, $fb_profile_pic));
}