public function SimplesamlphpDrupalAuthTest::testSynchronizeUserAttributes in simpleSAMLphp Authentication 8.3
Test user attribute syncing.
@covers ::synchronizeUserAttributes
File
- tests/
src/ Unit/ Service/ SimplesamlphpDrupalAuthTest.php, line 356
Class
- SimplesamlphpDrupalAuthTest
- SimplesamlphpDrupalAuth unit tests.
Namespace
Drupal\Tests\simplesamlphp_auth\Unit\ServiceCode
public function testSynchronizeUserAttributes() {
// Create a Mock SimplesamlphpAuthManager object.
$simplesaml = $this
->getMockBuilder('\\Drupal\\simplesamlphp_auth\\Service\\SimplesamlphpAuthManager')
->disableOriginalConstructor()
->setMethods([
'getDefaultName',
'getDefaultEmail',
])
->getMock();
// Mock the getDefaultName() & getDefaultEmail methods.
$simplesaml
->expects($this
->once())
->method('getDefaultName')
->will($this
->returnValue("Test name"));
$simplesaml
->expects($this
->once())
->method('getDefaultEmail')
->will($this
->returnValue("test@example.com"));
// Mock the User storage layer.
$entity_storage = $this
->createMock('Drupal\\Core\\Entity\\EntityStorageInterface');
// Expect the entity storage to return no existing user.
$entity_storage
->expects($this
->any())
->method('loadByProperties')
->will($this
->returnValue([]));
$this->entityTypeManager
->expects($this
->any())
->method('getStorage')
->will($this
->returnValue($entity_storage));
// Get a Mock User object to test the user attribute syncing.
$this->entityAccount
->expects($this
->once())
->method('setUsername')
->with($this
->equalTo("Test name"));
$this->entityAccount
->expects($this
->once())
->method('setEmail')
->with($this
->equalTo("test@example.com"));
$this->entityAccount
->expects($this
->once())
->method('save');
$simplesaml_drupalauth = new SimplesamlphpDrupalAuth($simplesaml, $this->configFactory, $this->entityTypeManager, $this->logger, $this->externalauth, $this->entityAccount, $this->messenger, $this->moduleHandler);
$simplesaml_drupalauth
->synchronizeUserAttributes($this->entityAccount, TRUE);
}