Пример #1
0
 /**
  * An event listener alters username before attempting to load user.
  *
  * @covers ::loginToDrupal
  */
 public function testEventListenerChangesCasUsername()
 {
     $cas_login = $this->getMockBuilder('Drupal\\cas\\Service\\CasLogin')->setMethods(array('userLoadByName', 'userLoginFinalize', 'storeLoginSessionData'))->setConstructorArgs(array($this->getConfigFactoryStub(), $this->entityManager, $this->session, $this->connection, $this->eventDispatcher))->getMock();
     $this->eventDispatcher->method('dispatch')->willReturnCallback(function ($event_type, $event) {
         if ($event instanceof CasUserLoadEvent) {
             $event->getCasPropertyBag()->setUsername('foobar');
         }
     });
     $account = $this->getMockBuilder('Drupal\\user\\UserInterface')->disableOriginalConstructor()->getMock();
     $cas_login->method('userLoadByName')->with('foobar')->willReturn($account);
     $cas_login->expects($this->once())->method('userLoginFinalize');
     $cas_login->expects($this->once())->method('storeLoginSessionData');
     $cas_login->loginToDrupal(new CasPropertyBag('test'), 'ticket');
 }