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) {
79
79
80
80
/**
81
81
* @NoAdminRequired
82
+ *
83
+ * @param string $content
82
84
*/
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 );
85
91
}
86
92
87
93
Original file line number Diff line number Diff line change 1
1
<phpunit bootstrap =" ../../lib/base.php" >
2
2
<testsuites >
3
- <testsuite name =" unit " >
3
+ <testsuite name =" integration " >
4
4
<directory >./tests/integration</directory >
5
5
</testsuite >
6
6
</testsuites >
Original file line number Diff line number Diff line change 11
11
12
12
namespace OCA \Notes \Controller ;
13
13
14
+ use PHPUnit_Framework_TestCase ;
15
+
14
16
use OCP \AppFramework \Http \DataResponse ;
15
17
use OCP \AppFramework \App ;
16
18
use OCP \Files \File ;
17
- use Test \TestCase ;
18
19
19
- class NotesApiControllerTest extends TestCase {
20
+
21
+ class NotesApiControllerTest extends PHPUnit_Framework_TestCase {
20
22
21
23
private $ controller ;
22
24
private $ mapper ;
23
25
private $ userId = 'test ' ;
26
+ private $ notesFolder = '/test/notes ' ;
24
27
private $ fs ;
25
28
26
29
public function setUp () {
27
- parent ::setUp ();
28
-
29
30
$ app = new App ('notes ' );
30
31
$ container = $ app ->getContainer ();
31
32
$ container ->registerService ('UserId ' , function ($ c ) {
@@ -38,6 +39,7 @@ public function setUp() {
38
39
$ this ->fs = $ this ->controller = $ container ->query (
39
40
'OCP\Files\IRootFolder '
40
41
);
42
+ $ this ->fs ->newFolder ();
41
43
}
42
44
43
45
@@ -54,10 +56,15 @@ public function testUpdate() {
54
56
$ this ->assertCount (1 , $ notes );
55
57
$ this ->assertEquals ('test2 ' , $ notes [0 ]->getContent ());
56
58
57
- $ file = $ this ->fs ->get (' / ' . $ userId . '/notes /test2.txt ' );
59
+ $ file = $ this ->fs ->get ($ this -> notesFolder . '/test2.txt ' );
58
60
59
61
$ this ->assertTrue ($ file instanceof File);
60
62
}
61
63
62
64
65
+ public function tearDown () {
66
+ $ this ->fs ->get ($ this ->notesFolder )->delete ();
67
+ }
68
+
69
+
63
70
}
Original file line number Diff line number Diff line change 18
18
use OCP \AppFramework \Http ;
19
19
20
20
use OCA \Notes \Service \NoteDoesNotExistException ;
21
+ use OCA \Notes \Db \Note ;
21
22
22
23
23
24
class NotesControllerTest extends PHPUnit_Framework_TestCase {
@@ -157,14 +158,21 @@ public function testSetConfig(){
157
158
* POST /notes
158
159
*/
159
160
public function testCreate (){
160
- $ expected = ['hi ' ];
161
+ $ created = new Note ();
162
+ $ created ->setId (3 );
163
+
164
+ $ expected = new Note ();
161
165
162
166
$ this ->service ->expects ($ this ->once ())
163
167
->method ('create ' )
164
168
->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 )
165
173
->will ($ this ->returnValue ($ expected ));
166
174
167
- $ response = $ this ->controller ->create ();
175
+ $ response = $ this ->controller ->create (' hi ' );
168
176
169
177
$ this ->assertEquals ($ expected , $ response ->getData ());
170
178
$ this ->assertTrue ($ response instanceof DataResponse);
You can’t perform that action at this time.
0 commit comments