From f340fbc6b1f714fc095ee38945a89339a957c764 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Fri, 22 May 2015 09:22:22 +0200 Subject: [PATCH] also update content when calling create api route --- controller/notescontroller.php | 10 ++++++++-- phpunit.integration.xml | 2 +- .../controller/NotesApiControllerTest.php | 17 ++++++++++++----- tests/unit/controller/NotesControllerTest.php | 12 ++++++++++-- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/controller/notescontroller.php b/controller/notescontroller.php index a4b2768b..71e27c4d 100644 --- a/controller/notescontroller.php +++ b/controller/notescontroller.php @@ -79,9 +79,15 @@ public function get($id) { /** * @NoAdminRequired + * + * @param string $content */ - public function create() { - return new DataResponse($this->notesService->create($this->userId)); + public function create($content) { + $note = $this->notesService->create($this->userId); + $note = $this->notesService->update( + $note->getId(), $content, $this->userId + ); + return new DataResponse($note); } diff --git a/phpunit.integration.xml b/phpunit.integration.xml index 17747640..c49bb106 100644 --- a/phpunit.integration.xml +++ b/phpunit.integration.xml @@ -1,6 +1,6 @@ - + ./tests/integration diff --git a/tests/integration/controller/NotesApiControllerTest.php b/tests/integration/controller/NotesApiControllerTest.php index 448b8238..2e6dc190 100644 --- a/tests/integration/controller/NotesApiControllerTest.php +++ b/tests/integration/controller/NotesApiControllerTest.php @@ -11,21 +11,22 @@ namespace OCA\Notes\Controller; +use PHPUnit_Framework_TestCase; + use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\App; use OCP\Files\File; -use Test\TestCase; -class NotesApiControllerTest extends TestCase { + +class NotesApiControllerTest extends PHPUnit_Framework_TestCase { private $controller; private $mapper; private $userId = 'test'; + private $notesFolder = '/test/notes'; private $fs; public function setUp() { - parent::setUp(); - $app = new App('notes'); $container = $app->getContainer(); $container->registerService('UserId', function($c) { @@ -38,6 +39,7 @@ public function setUp() { $this->fs = $this->controller = $container->query( 'OCP\Files\IRootFolder' ); + $this->fs->newFolder(); } @@ -54,10 +56,15 @@ public function testUpdate() { $this->assertCount(1, $notes); $this->assertEquals('test2', $notes[0]->getContent()); - $file = $this->fs->get('/' . $userId . '/notes/test2.txt'); + $file = $this->fs->get($this->notesFolder . '/test2.txt'); $this->assertTrue($file instanceof File); } + public function tearDown() { + $this->fs->get($this->notesFolder)->delete(); + } + + } \ No newline at end of file diff --git a/tests/unit/controller/NotesControllerTest.php b/tests/unit/controller/NotesControllerTest.php index 6567ddb4..6397c0b2 100644 --- a/tests/unit/controller/NotesControllerTest.php +++ b/tests/unit/controller/NotesControllerTest.php @@ -18,6 +18,7 @@ use OCP\AppFramework\Http; use OCA\Notes\Service\NoteDoesNotExistException; +use OCA\Notes\Db\Note; class NotesControllerTest extends PHPUnit_Framework_TestCase { @@ -157,14 +158,21 @@ public function testSetConfig(){ * POST /notes */ public function testCreate(){ - $expected = ['hi']; + $created = new Note(); + $created->setId(3); + + $expected = new Note(); $this->service->expects($this->once()) ->method('create') ->with($this->equalTo($this->userId)) + ->will($this->returnValue($created)); + $this->service->expects($this->once()) + ->method('update') + ->with(3, 'hi', $this->userId) ->will($this->returnValue($expected)); - $response = $this->controller->create(); + $response = $this->controller->create('hi'); $this->assertEquals($expected, $response->getData()); $this->assertTrue($response instanceof DataResponse);