Skip to content

Commit

Permalink
also update content when calling create api route
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Posselt committed May 22, 2015
1 parent 3c41c91 commit f340fbc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
10 changes: 8 additions & 2 deletions controller/notescontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
2 changes: 1 addition & 1 deletion phpunit.integration.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<phpunit bootstrap="../../lib/base.php">
<testsuites>
<testsuite name="unit">
<testsuite name="integration">
<directory>./tests/integration</directory>
</testsuite>
</testsuites>
Expand Down
17 changes: 12 additions & 5 deletions tests/integration/controller/NotesApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -38,6 +39,7 @@ public function setUp() {
$this->fs = $this->controller = $container->query(
'OCP\Files\IRootFolder'
);
$this->fs->newFolder();
}


Expand All @@ -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();
}


}
12 changes: 10 additions & 2 deletions tests/unit/controller/NotesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCP\AppFramework\Http;

use OCA\Notes\Service\NoteDoesNotExistException;
use OCA\Notes\Db\Note;


class NotesControllerTest extends PHPUnit_Framework_TestCase {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f340fbc

Please sign in to comment.