diff --git a/lib/private/User/User.php b/lib/private/User/User.php index c161f64b2977..406920f605d3 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -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]); + } } /** diff --git a/tests/lib/User/UserTest.php b/tests/lib/User/UserTest.php index b25f390df136..ccbfcd6ebd35 100644 --- a/tests/lib/User/UserTest.php +++ b/tests/lib/User/UserTest.php @@ -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