public function testGetGroups() { $groups = []; $id = $this->getUniqueID(); for ($i = 0; $i < 10; $i++) { $groups[] = $this->groupManager->createGroup($id . '_' . $i); } $_GET = []; $result = $this->api->getGroups([]); $this->assertInstanceOf('OC_OCS_Result', $result); $this->assertTrue($result->succeeded()); $this->assertCount(count($this->groupManager->search('')), $result->getData()['groups']); $this->assertContains('admin', $result->getData()['groups']); foreach ($groups as $group) { $this->assertContains($group->getGID(), $result->getData()['groups']); } $_GET = ['search' => $id, 'limit' => 5, 'offset' => 2]; $result = $this->api->getGroups([]); $this->assertInstanceOf('OC_OCS_Result', $result); $this->assertTrue($result->succeeded()); $this->assertCount(5, $result->getData()['groups']); foreach (array_splice($groups, 2, 5) as $group) { $this->assertContains($group->getGID(), $result->getData()['groups']); } foreach ($groups as $group) { $group->delete(); } }
/** * @dataProvider dataGetGroups */ public function testGetGroups($search, $limit, $offset) { $this->request->expects($this->exactly(3))->method('getParam')->will($this->returnValueMap([['search', '', $search], ['limit', null, $limit], ['offset', null, $offset]])); $groups = [$this->createGroup('group1'), $this->createGroup('group2')]; $search = $search === null ? '' : $search; $this->groupManager->expects($this->once())->method('search')->with($search, $limit, $offset)->willReturn($groups); $result = $this->api->getGroups([]); $this->assertInstanceOf('OC_OCS_Result', $result); $this->assertTrue($result->succeeded()); $this->assertEquals(['group1', 'group2'], $result->getData()['groups']); }