| @@ 32-87 (lines=56) @@ | ||
| 29 | use PHPUnit\Framework\TestCase; |
|
| 30 | ||
| 31 | ||
| 32 | class CollectionsControllerTest extends TestCase { |
|
| 33 | ||
| 34 | private $appName; |
|
| 35 | private $collectionsService; |
|
| 36 | private $request; |
|
| 37 | private $controller; |
|
| 38 | ||
| 39 | use \OCA\Tasks\Controller\Response; |
|
| 40 | ||
| 41 | /** |
|
| 42 | * Gets run before each test |
|
| 43 | */ |
|
| 44 | public function setUp(): void { |
|
| 45 | $this->appName = 'tasks'; |
|
| 46 | $this->collectionsService = $this->getMockBuilder(CollectionsService::class) |
|
| 47 | ->disableOriginalConstructor() |
|
| 48 | ->getMock(); |
|
| 49 | $this->request = $this->getMockBuilder(IRequest::class) |
|
| 50 | ->disableOriginalConstructor() |
|
| 51 | ->getMock(); |
|
| 52 | $this->controller = new CollectionsController( |
|
| 53 | $this->appName, |
|
| 54 | $this->request, |
|
| 55 | $this->collectionsService |
|
| 56 | ); |
|
| 57 | } |
|
| 58 | ||
| 59 | public function testgetCollections() { |
|
| 60 | $return = [[], []]; |
|
| 61 | $this->collectionsService->expects($this->once()) |
|
| 62 | ->method('getAll') |
|
| 63 | ->will($this->returnValue($return)); |
|
| 64 | ||
| 65 | $expected = $this->generateResponse(function () use ($return) { |
|
| 66 | return ['collections' => $return]; |
|
| 67 | }); |
|
| 68 | $response = $this->controller->getCollections(); |
|
| 69 | $this->assertEquals($expected, $response); |
|
| 70 | } |
|
| 71 | ||
| 72 | public function testSetVisibility() { |
|
| 73 | $this->collectionsService->expects($this->once()) |
|
| 74 | ->method('setVisibility') |
|
| 75 | ->with( |
|
| 76 | 'starred', |
|
| 77 | $this->equalTo(0) |
|
| 78 | ) |
|
| 79 | ->will($this->returnValue(true)); |
|
| 80 | ||
| 81 | $expected = $this->generateResponse(function () { |
|
| 82 | return true; |
|
| 83 | }); |
|
| 84 | $response = $this->controller->setVisibility('starred', 0); |
|
| 85 | $this->assertEquals($expected, $response); |
|
| 86 | } |
|
| 87 | } |
|
| 88 | ||
| @@ 32-87 (lines=56) @@ | ||
| 29 | use PHPUnit\Framework\TestCase; |
|
| 30 | ||
| 31 | ||
| 32 | class SettingsControllerTest extends TestCase { |
|
| 33 | ||
| 34 | private $appName; |
|
| 35 | private $settingsService; |
|
| 36 | private $request; |
|
| 37 | private $controller; |
|
| 38 | ||
| 39 | use \OCA\Tasks\Controller\Response; |
|
| 40 | ||
| 41 | /** |
|
| 42 | * Gets run before each test |
|
| 43 | */ |
|
| 44 | public function setUp(): void { |
|
| 45 | $this->appName = 'tasks'; |
|
| 46 | $this->settingsService = $this->getMockBuilder(SettingsService::class) |
|
| 47 | ->disableOriginalConstructor() |
|
| 48 | ->getMock(); |
|
| 49 | $this->request = $this->getMockBuilder(IRequest::class) |
|
| 50 | ->disableOriginalConstructor() |
|
| 51 | ->getMock(); |
|
| 52 | $this->controller = new SettingsController( |
|
| 53 | $this->appName, |
|
| 54 | $this->request, |
|
| 55 | $this->settingsService |
|
| 56 | ); |
|
| 57 | } |
|
| 58 | ||
| 59 | public function testGet() { |
|
| 60 | $return = ['sortOrder' => 0]; |
|
| 61 | $this->settingsService->expects($this->once()) |
|
| 62 | ->method('get') |
|
| 63 | ->will($this->returnValue($return)); |
|
| 64 | ||
| 65 | $expected = $this->generateResponse(function () use ($return) { |
|
| 66 | return ['settings' => $return]; |
|
| 67 | }); |
|
| 68 | $response = $this->controller->get(); |
|
| 69 | $this->assertEquals($expected, $response); |
|
| 70 | } |
|
| 71 | ||
| 72 | public function testSet() { |
|
| 73 | $this->settingsService->expects($this->once()) |
|
| 74 | ->method('set') |
|
| 75 | ->with( |
|
| 76 | 'sortOrder', |
|
| 77 | $this->equalTo(0) |
|
| 78 | ) |
|
| 79 | ->will($this->returnValue(true)); |
|
| 80 | ||
| 81 | $expected = $this->generateResponse(function () { |
|
| 82 | return true; |
|
| 83 | }); |
|
| 84 | $response = $this->controller->set('sortOrder', 0); |
|
| 85 | $this->assertEquals($expected, $response); |
|
| 86 | } |
|
| 87 | } |
|
| 88 | ||