1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
OC_App::loadApp('bookmarks'); |
4
|
|
|
|
5
|
|
|
use \OCA\Bookmarks\Controller\Rest\PublicController; |
6
|
|
|
use OCA\Bookmarks\Controller\Lib\Bookmarks; |
7
|
|
|
|
8
|
|
|
class Test_PublicController_Bookmarks extends PHPUnit_Framework_TestCase { |
9
|
|
|
|
10
|
|
|
private $userid; |
11
|
|
|
private $request; |
12
|
|
|
private $db; |
13
|
|
|
private $userManager; |
14
|
|
|
private $publicController; |
15
|
|
|
|
16
|
|
|
protected function setUp() { |
17
|
|
|
$this->userid = "testuser"; |
18
|
|
|
$this->request = \OC::$server->getRequest(); |
19
|
|
|
$this->db = \OC::$server->getDb(); |
20
|
|
|
$this->userManager = \OC::$server->getUserManager(); |
21
|
|
|
$this->publicController = new PublicController("bookmarks", $this->request, $this->db, $this->userManager); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
View Code Duplication |
function testPublicQueryNoUser() { |
|
|
|
|
25
|
|
|
$output = $this->publicController->returnAsJson(null, "apassword", null); |
26
|
|
|
$data = $output->getData(); |
27
|
|
|
$status = $data['status']; |
28
|
|
|
$this->assertEquals($status, 'error'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
View Code Duplication |
function testPublicQueryWrongUser() { |
|
|
|
|
32
|
|
|
$output = $this->publicController->returnAsJson("cqc43dr4rx3x4xatr4", "apassword", null); |
33
|
|
|
$data = $output->getData(); |
34
|
|
|
$status = $data['status']; |
35
|
|
|
$this->assertEquals($status, 'error'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function testPublicQuery() { |
|
|
|
|
39
|
|
|
|
40
|
|
|
Bookmarks::addBookmark($this->userid, $this->db, "http://www.golem.de", "Golem", array("four"), "PublicNoTag", true); |
41
|
|
|
Bookmarks::addBookmark($this->userid, $this->db, "http://www.9gag.com", "9gag", array("two", "three"), "PublicTag", true); |
42
|
|
|
|
43
|
|
|
$output = $this->publicController->returnAsJson($this->userid); |
44
|
|
|
$data = $output->getData(); |
45
|
|
|
$this->assertEquals(2, count($data)); |
46
|
|
|
|
47
|
|
|
$this->cleanDB(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
function cleanDB() { |
|
|
|
|
51
|
|
|
$query1 = OC_DB::prepare('DELETE FROM *PREFIX*bookmarks'); |
52
|
|
|
$query1->execute(); |
53
|
|
|
$query2 = OC_DB::prepare('DELETE FROM *PREFIX*bookmarks_tags'); |
54
|
|
|
$query2->execute(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.