File tree Expand file tree Collapse file tree 4 files changed +31
-10
lines changed Expand file tree Collapse file tree 4 files changed +31
-10
lines changed Original file line number Diff line number Diff line change @@ -79,9 +79,15 @@ public function get($id) {
7979
8080 /**
8181 * @NoAdminRequired
82+ *
83+ * @param string $content
8284 */
83- public function create () {
84- return new DataResponse ($ this ->notesService ->create ($ this ->userId ));
85+ public function create ($ content ) {
86+ $ note = $ this ->notesService ->create ($ this ->userId );
87+ $ note = $ this ->notesService ->update (
88+ $ note ->getId (), $ content , $ this ->userId
89+ );
90+ return new DataResponse ($ note );
8591 }
8692
8793
Original file line number Diff line number Diff line change 11<phpunit bootstrap =" ../../lib/base.php" >
22 <testsuites >
3- <testsuite name =" unit " >
3+ <testsuite name =" integration " >
44 <directory >./tests/integration</directory >
55 </testsuite >
66 </testsuites >
Original file line number Diff line number Diff line change 1111
1212namespace OCA \Notes \Controller ;
1313
14+ use PHPUnit_Framework_TestCase ;
15+
1416use OCP \AppFramework \Http \DataResponse ;
1517use OCP \AppFramework \App ;
1618use OCP \Files \File ;
17- use Test \TestCase ;
1819
19- class NotesApiControllerTest extends TestCase {
20+
21+ class NotesApiControllerTest extends PHPUnit_Framework_TestCase {
2022
2123 private $ controller ;
2224 private $ mapper ;
2325 private $ userId = 'test ' ;
26+ private $ notesFolder = '/test/notes ' ;
2427 private $ fs ;
2528
2629 public function setUp () {
27- parent ::setUp ();
28-
2930 $ app = new App ('notes ' );
3031 $ container = $ app ->getContainer ();
3132 $ container ->registerService ('UserId ' , function ($ c ) {
@@ -38,6 +39,7 @@ public function setUp() {
3839 $ this ->fs = $ this ->controller = $ container ->query (
3940 'OCP\Files\IRootFolder '
4041 );
42+ $ this ->fs ->newFolder ();
4143 }
4244
4345
@@ -54,10 +56,15 @@ public function testUpdate() {
5456 $ this ->assertCount (1 , $ notes );
5557 $ this ->assertEquals ('test2 ' , $ notes [0 ]->getContent ());
5658
57- $ file = $ this ->fs ->get (' / ' . $ userId . '/notes /test2.txt ' );
59+ $ file = $ this ->fs ->get ($ this -> notesFolder . '/test2.txt ' );
5860
5961 $ this ->assertTrue ($ file instanceof File);
6062 }
6163
6264
65+ public function tearDown () {
66+ $ this ->fs ->get ($ this ->notesFolder )->delete ();
67+ }
68+
69+
6370}
Original file line number Diff line number Diff line change 1818use OCP \AppFramework \Http ;
1919
2020use OCA \Notes \Service \NoteDoesNotExistException ;
21+ use OCA \Notes \Db \Note ;
2122
2223
2324class NotesControllerTest extends PHPUnit_Framework_TestCase {
@@ -157,14 +158,21 @@ public function testSetConfig(){
157158 * POST /notes
158159 */
159160 public function testCreate (){
160- $ expected = ['hi ' ];
161+ $ created = new Note ();
162+ $ created ->setId (3 );
163+
164+ $ expected = new Note ();
161165
162166 $ this ->service ->expects ($ this ->once ())
163167 ->method ('create ' )
164168 ->with ($ this ->equalTo ($ this ->userId ))
169+ ->will ($ this ->returnValue ($ created ));
170+ $ this ->service ->expects ($ this ->once ())
171+ ->method ('update ' )
172+ ->with (3 , 'hi ' , $ this ->userId )
165173 ->will ($ this ->returnValue ($ expected ));
166174
167- $ response = $ this ->controller ->create ();
175+ $ response = $ this ->controller ->create (' hi ' );
168176
169177 $ this ->assertEquals ($ expected , $ response ->getData ());
170178 $ this ->assertTrue ($ response instanceof DataResponse);
You can’t perform that action at this time.
0 commit comments