Skip to content

Commit

Permalink
Emit postSetEnabled. Closes #23970
Browse files Browse the repository at this point in the history
  • Loading branch information
VicDeo committed Jan 20, 2017
1 parent 1adc983 commit d4f79f5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/private/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ public function setEnabled($enabled) {
$this->enabled = $enabled;
$enabled = ($enabled) ? 'true' : 'false';
$this->config->setUserValue($this->uid, 'core', 'enabled', $enabled);
if ($this->emitter) {
$this->emitter->emit('\OC\User', 'postSetEnabled', [$this, $enabled]);
}
}

/**
Expand Down
29 changes: 29 additions & 0 deletions tests/lib/User/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,35 @@ public function testDeleteHooks() {
$this->assertEquals(2, $hooksCalled);
}

public function testSetEnabledHook(){
$hooksCalled = 0;
$test = $this;

/**
* @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
$backend = $this->createMock(Dummy::class);

/**
* @param User $user
* @param bool $enabled
*/
$hook = function ($user, $enabled) use ($test, &$hooksCalled) {
$hooksCalled++;
$expectedState = ($user->isEnabled()) ? 'true' : 'false';
$test->assertEquals($expectedState, $enabled);
$test->assertEquals('foo', $user->getUID());
};

$emitter = new PublicEmitter();
$emitter->listen('\OC\User', 'postSetEnabled', $hook);

$user = new User('foo', $backend, $emitter);
$user->setEnabled(true);
$user->setEnabled(false);
$this->assertEquals(2, $hooksCalled);
}

public function testGetCloudId() {
/**
* @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
Expand Down

0 comments on commit d4f79f5

Please sign in to comment.