extension('flarum-nicknames'); $this->prepareDatabase([ 'users' => [ $this->normalUser(), ], ]); } /** * @test */ public function user_cant_edit_own_nickname_if_not_allowed() { $this->database()->table('group_permission')->where('permission', 'user.editOwnNickname')->where('group_id', Group::MEMBER_ID)->delete(); $response = $this->send( $this->request('PATCH', '/api/users/2', [ 'authenticatedAs' => 2, 'json' => [ 'data' => [ 'attributes' => [ 'nickname' => 'new nickname', ], ], ], ]) ); $this->assertEquals(403, $response->getStatusCode()); } /** * @test */ public function user_can_edit_own_nickname_if_allowed() { $this->prepareDatabase([ 'group_permission' => [ ['permission' => 'user.editOwnNickname', 'group_id' => 2], ] ]); $response = $this->send( $this->request('PATCH', '/api/users/2', [ 'authenticatedAs' => 2, 'json' => [ 'data' => [ 'attributes' => [ 'nickname' => 'new nickname', ], ], ], ]) ); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('new nickname', User::find(2)->nickname); } }