Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit postSetEnabled for user #26984

Merged
merged 4 commits into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/private/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
use OCP\IConfig;
use OCP\UserInterface;
use \OCP\IUserBackend;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\GenericEvent;

class User implements IUser {
/** @var string $uid */
Expand Down Expand Up @@ -71,17 +73,24 @@ class User implements IUser {
/** @var IURLGenerator */
private $urlGenerator;

/** @var EventDispatcher */
private $eventDispatcher;

/**
* @param string $uid
* @param UserInterface $backend
* @param \OC\Hooks\Emitter $emitter
* @param IConfig|null $config
* @param IURLGenerator $urlGenerator
* @param EventDispatcher $eventDispatcher
*/
public function __construct($uid, $backend, $emitter = null, IConfig $config = null, $urlGenerator = null) {
public function __construct($uid, $backend, $emitter = null, IConfig $config = null,
$urlGenerator = null, EventDispatcher $eventDispatcher = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is $eventDispatcher ever passed into this ctor?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VicDeo ^^^

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DeepDiver1975 passed now.

) {
$this->uid = $uid;
$this->backend = $backend;
$this->emitter = $emitter;
$this->eventDispatcher = $eventDispatcher;
if(is_null($config)) {
$config = \OC::$server->getConfig();
}
Expand Down Expand Up @@ -337,6 +346,10 @@ public function setEnabled($enabled) {
$this->enabled = $enabled;
$enabled = ($enabled) ? 'true' : 'false';
$this->config->setUserValue($this->uid, 'core', 'enabled', $enabled);

if ($this->eventDispatcher){
$this->eventDispatcher->dispatch(self::class . '::postSetEnabled', new GenericEvent($this));
}
}

/**
Expand Down
30 changes: 30 additions & 0 deletions tests/lib/User/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use OC\User\Database;
use OC\User\User;
use OCP\IConfig;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\GenericEvent;
use Test\TestCase;
use Test\Util\User\Dummy;

Expand Down Expand Up @@ -502,6 +504,34 @@ public function testDeleteHooks() {
$this->assertEquals(2, $hooksCalled);
}

public function testSetEnabledHook(){
/**
* @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
$backend = $this->createMock(Dummy::class);
$eventDispatcherMock = $this->createMock(EventDispatcher::class);

$expectations = [true, false];
$eventDispatcherMock->expects($this->exactly(2))
->method('dispatch')
->with(
$this->callback(
function($eventName){
if ($eventName === User::class . '::postSetEnabled' ){
return true;
}
return false;
}
),
$this->anything()
)
;

$user = new User('foo', $backend, null, null, null, $eventDispatcherMock);
$user->setEnabled(false);
$user->setEnabled(true);
}

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