Avoid duplicate users in collections moderators list
This commit is contained in:
parent
167b021a9d
commit
e778fc5532
|
@ -601,7 +601,11 @@ class Collection extends Entity {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function set_moderators_ids( $value ) {
|
function set_moderators_ids( array $value ) {
|
||||||
|
|
||||||
|
// make sure you never have duplicated moderators
|
||||||
|
$value = array_unique($value);
|
||||||
|
|
||||||
$this->set_mapped_property( 'moderators_ids', $value );
|
$this->set_mapped_property( 'moderators_ids', $value );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,39 @@ class Collections extends TAINACAN_UnitTestCase {
|
||||||
// now he can edit
|
// now he can edit
|
||||||
$this->assertFalse(user_can($new_user, $collection_test_moderator->cap->edit_post, $collection_test_moderator->WP_Post->ID));
|
$this->assertFalse(user_can($new_user, $collection_test_moderator->cap->edit_post, $collection_test_moderator->WP_Post->ID));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_avoid_duplicated_moderator () {
|
||||||
|
$collection_test = $this->tainacan_entity_factory->create_entity(
|
||||||
|
'collection',
|
||||||
|
array(
|
||||||
|
'name' => 'testeCaps',
|
||||||
|
'description' => 'adasdasdsa',
|
||||||
|
'default_order' => 'DESC'
|
||||||
|
),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
$new_user = $this->factory()->user->create(array( 'role' => 'subscriber' ));
|
||||||
|
wp_set_current_user($new_user);
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
$this->assertEquals($new_user, $user_id);
|
||||||
|
|
||||||
|
$autor1 = $this->factory()->user->create(array( 'role' => 'author' ));
|
||||||
|
wp_set_current_user($autor1);
|
||||||
|
$autor1_id = get_current_user_id();
|
||||||
|
|
||||||
|
$moderators_ids = [
|
||||||
|
$user_id,
|
||||||
|
$autor1_id,
|
||||||
|
$user_id,
|
||||||
|
$autor1_id,
|
||||||
|
];
|
||||||
|
|
||||||
|
$collection_test->set_moderators_ids($moderators_ids);
|
||||||
|
|
||||||
|
$this->assertEquals(2, sizeof( $collection_test->get_moderators_ids() ));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function debug_meta($user = false)
|
function debug_meta($user = false)
|
||||||
|
|
Loading…
Reference in New Issue