Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
user.module
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
9 Jun 2013 at 19:06 UTC
Updated:
29 Jul 2014 at 22:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
dawehnerIt turned out that both adding and removing roles is broken. Working on tests now.
Comment #2
berdirAs mentioned in IRC, I'd be +1 to a addRole() and removeRole() method. Doesn't need to happen here but might not be much more work to put that code in methods. Would simplify quite a few places (mostly in tests) where we remove and add roles.
Comment #3
dawehnerAdded addRole/removeRole and introduced some unit tests for the plugins.
Comment #4
dawehner.
Comment #5
berdirWhy @inheritdoc on one of them and not the others?
As in the other issue, why not use the interface, then you don't need to mess with the constructor?
And nice that the methods now allow to test the actions without messing with entity internals, I'm starting to like this stuff ;)
However, there's an untested blackbox now, and that's those methods.
So I think we also need actual test coverage for them, which can't be a unit test yet, as sad as this is ;)
Comment #6
fubhy commentedLooks good!
Weird indentation.
Could just be return $this->get('roles') ?: array();
Should we use ->set() now? ->getRoles() uses $this->get().
Not that it matters (as it's the BC decorator) but should be {@inheritdoc}.
Comment #7
dawehnerYeah sadly you can't mock interfaces at least it really breaks here.
Nope, see $role->value...
Let's add a proper test for user as well.
Comment #9
dawehner#7: user-2015721-7.patch queued for re-testing.
Comment #10
berdirDouble post.
Comment #11
berdirI see, "PHP Fatal error: Class Mock_UserInterface_f482d180 must implement interface Traversable as part of either Iterator or IteratorAggregate in Unknown on line 0", that's what you get when you try to mock that interface. Almost sounds like a PHPUnit bug to me?
Anyway, let's go with User then :)
Comment #12
berdirI know you really want to to that but we could add that to every single test we write :)
The language stuff shouldn't be necessary, array('roles' => array('test_role_one')) should work too.
Not sure about using random roles here, we might want to use real ones (that we create first), to avoid issues later on with validation or something like that.
Comment #13
berdirOpened #2015937: Use addRole() and removeRole() whenever a user role is added or removed as a nice follow-up.
Comment #14
dawehnerOkay let's fix those.
Comment #15
dawehnerAdded a hasRole method.
Comment #17
dawehnerLet's fix the unit tests. Once you start to mock you have all kind of different problems.
Comment #19
berdir#17: user-2015721-17.patch queued for re-testing.
Comment #21
berdir#17: user-2015721-17.patch queued for re-testing.
Comment #23
dawehner#17: user-2015721-17.patch queued for re-testing.
Comment #24
ParisLiakos commentedYou could do this in setUp and store account in a property, so you dont have to repeat it on every test.
i guess we are just executing it to watch for fatal errors, but would be cool if we could assert something..is anything available that we could use?
Comment #25
berdirThe assertions happens through the mock classes that verify that the correct methods were called on the user entity, the execute() method doesn't return anything that could be verified, so I think that's fine.
Comment #26
dawehnerWe have mocked everything else, so I don't see anything we can test.
Comment #27
damiankloip commentedI guess you meant to remove this in the test methods and just leave it in setUp?
Comment #28
dawehnerOh.
Comment #29
berdirShouldn't this be a user_add_role_action or something like that?
Comment #31
dawehnerGood catch! I admit, this was a copy and paste problem.
This needed a rerole as getRoles went in somewhere.
Comment #32
tim.plunkettI got VERY VERY angry last night while working on #1851086: Replace admin/people with a View for this, so thank you.
RTBC if green.
Comment #33
alexpottCommitted bf5c0ae and pushed to 8.x. Thanks!
I think we need to have a change notice for the new methods...
Comment #34
tim.plunkettComment #35
dawehnerHere is one: https://drupal.org/node/2020821
Comment #36
xatoo commentedNice, change notice is clear to me.
I suggest we move on with #2015937: Use addRole() and removeRole() whenever a user role is added or removed
Comment #37
berdirYes, looks good.
@xatoo: When a change notice is done, the issue can be set to fixed and restored to the old values of the title, priority, category and the tag can be removed.