本文整理汇总了PHP中UserTestHelper::createBasicUserWithManager方法的典型用法代码示例。如果您正苦于以下问题:PHP UserTestHelper::createBasicUserWithManager方法的具体用法?PHP UserTestHelper::createBasicUserWithManager怎么用?PHP UserTestHelper::createBasicUserWithManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserTestHelper
的用法示例。
在下文中一共展示了UserTestHelper::createBasicUserWithManager方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBasicSearchUsers
/**
* @depends testUnprivilegedUserViewUpdateDeleteUsers
*/
public function testBasicSearchUsers()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$authenticationData = $this->login();
$headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
$manager = User::getByUsername('smith45');
UserTestHelper::createBasicUser('First');
UserTestHelper::createBasicUser('Second');
UserTestHelper::createBasicUser('Third');
UserTestHelper::createBasicUser('Forth');
UserTestHelper::createBasicUserWithManager('Fifth', $manager);
$searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('username' => ''), 'sort' => 'username');
$searchParamsQuery = http_build_query($searchParams);
$response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers);
$response = json_decode($response, true);
$this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
$this->assertEquals(3, count($response['data']['items']));
$this->assertEquals(8, $response['data']['totalCount']);
$this->assertEquals(1, $response['data']['currentPage']);
$this->assertEquals('fifth', $response['data']['items'][0]['username']);
$this->assertEquals('first', $response['data']['items'][1]['username']);
$this->assertEquals('forth', $response['data']['items'][2]['username']);
// Second page
$searchParams['pagination']['page'] = 2;
$searchParamsQuery = http_build_query($searchParams);
$response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers);
$response = json_decode($response, true);
$this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
$this->assertEquals(3, count($response['data']['items']));
$this->assertEquals(8, $response['data']['totalCount']);
$this->assertEquals(2, $response['data']['currentPage']);
$this->assertEquals('second', $response['data']['items'][0]['username']);
$this->assertEquals('smith45', $response['data']['items'][1]['username']);
$this->assertEquals('steven', $response['data']['items'][2]['username']);
// Search by name
$searchParams['pagination']['page'] = 1;
$searchParams['search']['username'] = 'first';
$searchParamsQuery = http_build_query($searchParams);
$response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers);
$response = json_decode($response, true);
$this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
$this->assertEquals(1, count($response['data']['items']));
$this->assertEquals(1, $response['data']['totalCount']);
$this->assertEquals(1, $response['data']['currentPage']);
$this->assertEquals('first', $response['data']['items'][0]['username']);
// No results
$searchParams['pagination']['page'] = 1;
$searchParams['search']['username'] = 'first2';
$searchParamsQuery = http_build_query($searchParams);
$response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers);
$response = json_decode($response, true);
$this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
$this->assertEquals(0, $response['data']['totalCount']);
$this->assertFalse(isset($response['data']['items']));
// Search by name desc.
$searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('username' => ''), 'sort' => 'username.desc');
$searchParamsQuery = http_build_query($searchParams);
$response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers);
$response = json_decode($response, true);
$this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
$this->assertEquals(3, count($response['data']['items']));
$this->assertEquals(8, $response['data']['totalCount']);
$this->assertEquals(1, $response['data']['currentPage']);
$this->assertEquals('third', $response['data']['items'][0]['username']);
$this->assertEquals('super', $response['data']['items'][1]['username']);
$this->assertEquals('steven', $response['data']['items'][2]['username']);
// Second page
$searchParams['pagination']['page'] = 2;
$searchParamsQuery = http_build_query($searchParams);
$response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers);
$response = json_decode($response, true);
$this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
$this->assertEquals(3, count($response['data']['items']));
$this->assertEquals(8, $response['data']['totalCount']);
$this->assertEquals(2, $response['data']['currentPage']);
$this->assertEquals('smith45', $response['data']['items'][0]['username']);
$this->assertEquals('second', $response['data']['items'][1]['username']);
$this->assertEquals('forth', $response['data']['items'][2]['username']);
// Search by custom fields, order by name desc
$searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('manager' => array('id' => $manager->id)), 'sort' => 'username');
$searchParamsQuery = http_build_query($searchParams);
$response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers);
$response = json_decode($response, true);
$this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
$this->assertEquals(1, count($response['data']['items']));
$this->assertEquals(1, $response['data']['totalCount']);
$this->assertEquals(1, $response['data']['currentPage']);
$this->assertEquals('fifth', $response['data']['items'][0]['username']);
}