public function testBuildForm()
 {
     $builder = m::mock('Symfony\\Component\\Form\\FormBuilderInterface');
     $input = array('buttons' => array('save' => array('type' => 'submit', 'options' => array('label' => 'button.save')), 'cancel' => array('type' => 'button', 'options' => array('label' => 'button.cancel'))));
     $buttonBuilder = new ButtonBuilder('name');
     $builder->shouldReceive('add')->with(m::anyOf('save', 'cancel'), m::anyOf('submit', 'button'), m::hasKey('label'))->twice()->andReturn($buttonBuilder);
     $this->type = new FormActionsType();
     $this->type->buildForm($builder, $input);
 }
 public function testCreate()
 {
     Sentry::shouldReceive('createGroup')->once()->andThrow('Cartalyst\\Sentry\\Groups\\NameRequiredException');
     $this->assertFalse($this->groups->create(array()));
     Sentry::shouldReceive('createGroup')->once()->with(array('name' => 'Admin'))->andThrow('Cartalyst\\Sentry\\Groups\\GroupExistsException');
     $this->assertFalse($this->groups->create(array('name' => 'Admin')));
     $this->assertNotNull($this->groups->getError());
     Sentry::shouldReceive('createGroup')->once()->with(m::hasKey('name'))->andReturn(true);
     $this->assertTrue($this->groups->create(array('name' => '')));
     $this->assertNotNull($this->groups->getError());
 }
Exemplo n.º 3
0
 /**
  * @expectedException \Mockery\Exception
  */
 public function testHasKeyConstraintThrowsExceptionWhenConstraintUnmatched()
 {
     $this->mock->shouldReceive('foo')->with(Mockery::hasKey('c'))->once();
     $this->mock->foo(array('a' => 1, 'b' => 3));
     $this->container->mockery_verify();
 }
Exemplo n.º 4
0
 public function testUnbanUser()
 {
     // Mock the Event::fire() calls
     $this->dispatcherMock->shouldReceive('fire')->with('sentinel.user.banned', \Mockery::hasKey('userId'))->once();
     $this->dispatcherMock->shouldReceive('fire')->with('sentinel.user.unbanned', \Mockery::hasKey('userId'))->once();
     // Find the user we are going to suspend
     $user = $this->sentry->findUserByLogin('*****@*****.**');
     // Prepare the Throttle Provider
     $throttleProvider = $this->sentry->getThrottleProvider();
     // Ban the user
     $this->repo->ban($user->id);
     // This is the code we are testing
     $result = $this->repo->unban($user->id);
     // Ask the Throttle Provider to gather information for this user
     $throttle = $throttleProvider->findByUserId($user->id);
     // Check the throttle status.  This should do nothing.
     $throttle->check();
     // Assertions
     $this->assertTrue($result['success']);
 }
Exemplo n.º 5
0
 public function testExecuteEmailChangeDoesNotChangeOthers()
 {
     $this->userManager->shouldReceive('getAllCampusIds')->with(false, false)->andReturn(['abc']);
     $fakeDirectoryUser = ['firstName' => 'new-first', 'lastName' => 'new-last', 'email' => 'new-email', 'telephoneNumber' => 'new-phone', 'campusId' => 'abc', 'username' => 'new-abc123'];
     $this->directory->shouldReceive('findByCampusIds')->with(['abc'])->andReturn([$fakeDirectoryUser]);
     $authentication = m::mock('Ilios\\CoreBundle\\Entity\\AuthenticationInterface')->shouldReceive('getUsername')->andReturn('abc123')->mock();
     $user = m::mock('Ilios\\CoreBundle\\Entity\\UserInterface')->shouldReceive('getId')->andReturn(42)->shouldReceive('getFirstAndLastName')->andReturn('first last')->shouldReceive('getFirstName')->andReturn('first')->shouldReceive('getLastName')->andReturn('last')->shouldReceive('getEmail')->andReturn('email')->shouldReceive('getPhone')->andReturn('phone')->shouldReceive('getCampusId')->andReturn('abc')->shouldReceive('getAuthentication')->andReturn($authentication)->shouldReceive('setExamined')->with(true)->mock();
     $this->userManager->shouldReceive('findUsersBy')->with(array('campusId' => 'abc', 'enabled' => true, 'userSyncIgnore' => false))->andReturn([$user])->once();
     $this->userManager->shouldReceive('findUsersBy')->with(m::hasKey('examined'), m::any())->andReturn([])->andReturn([])->once();
     $this->userManager->shouldReceive('updateUser')->with($user, false)->once();
     $update = m::mock('Ilios\\CoreBundle\\Entity\\PendingUserUpdate')->shouldReceive('setType')->with('emailMismatch')->once()->shouldReceive('setProperty')->with('email')->once()->shouldReceive('setValue')->with('new-email')->once()->shouldReceive('setUser')->with($user)->once()->mock();
     $this->pendingUserUpdateManager->shouldReceive('createPendingUserUpdate')->andReturn($update)->once();
     $this->pendingUserUpdateManager->shouldReceive('updatePendingUserUpdate')->with($update, false)->once();
     $this->em->shouldReceive('flush')->twice();
     $this->em->shouldReceive('clear')->once();
     $this->commandTester->execute(array('command' => self::COMMAND_NAME));
     $output = $this->commandTester->getDisplay();
     $this->assertRegExp('/Completed sync process 1 users found in the directory; 0 users updated./', $output);
 }
Exemplo n.º 6
0
 public function testDeleteProperlyDeletesModelWhenSoftDeleting()
 {
     $model = $this->getMock('LMongo\\Eloquent\\Model', array('newQuery', 'updateTimestamps', 'touchOwners'));
     $model->setSoftDeleting(true);
     $query = m::mock('stdClass');
     $query->shouldReceive('where')->once()->with('_id', 'MongoID')->andReturn($query);
     $query->shouldReceive('update')->once()->with(m::hasKey('deleted_at'));
     $model->expects($this->once())->method('newQuery')->will($this->returnValue($query));
     $model->expects($this->once())->method('touchOwners');
     $model->exists = true;
     $model->_id = '500000000000000000000000';
     $model->delete();
 }