1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
<?php
/**
* ownCloud - News
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Alessandro Cosentino <cosenal@gmail.com>
* @author Bernhard Posselt <dev@bernhard-posselt.com>
* @copyright Alessandro Cosentino 2012
* @copyright Bernhard Posselt 2012, 2014
*/
namespace OCA\News\Controller;
use \OCP\AppFramework\Http;
use \OCA\News\Http\TextDownloadResponse;
use \OCA\News\Utility\OPMLExporter;
use \OCA\News\Db\Item;
use \OCA\News\Db\Feed;
require_once(__DIR__ . "/../../classloader.php");
class ExportControllerTest extends \PHPUnit_Framework_TestCase {
private $appName;
private $request;
private $controller;
private $user;
private $feedBusinessLayer;
private $folderBusinessLayer;
private $itemBusinessLayer;
private $opmlExporter;
/**
* Gets run before each test
*/
public function setUp(){
$this->appName = 'news';
$this->user = 'john';
$this->itemBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\ItemBusinessLayer')
->disableOriginalConstructor()
->getMock();
$this->feedBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FeedBusinessLayer')
->disableOriginalConstructor()
->getMock();
$this->folderBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FolderBusinessLayer')
->disableOriginalConstructor()
->getMock();
$this->request = $this->getMockBuilder('\OCP\IRequest')
->disableOriginalConstructor()
->getMock();
$this->opmlExporter = new OPMLExporter();
$this->controller = new ExportController($this->appName, $this->request,
$this->feedBusinessLayer, $this->folderBusinessLayer,
$this->itemBusinessLayer, $this->opmlExporter, $this->user);
}
public function testOpmlExportNoFeeds(){
$opml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
"<opml version=\"2.0\">\n" .
" <head>\n" .
" <title>Subscriptions</title>\n" .
" </head>\n" .
" <body/>\n" .
"</opml>\n";
$this->feedBusinessLayer->expects($this->once())
->method('findAll')
->with($this->equalTo($this->user))
->will($this->returnValue(array()));
$this->folderBusinessLayer->expects($this->once())
->method('findAll')
->with($this->equalTo($this->user))
->will($this->returnValue(array()));
$return = $this->controller->opml();
$this->assertTrue($return instanceof TextDownloadResponse);
$this->assertEquals($opml, $return->render());
}
public function testGetAllArticles(){
$item1 = new Item();
$item1->setFeedId(3);
$item2 = new Item();
$item2->setFeedId(5);
$feed1 = new Feed();
$feed1->setId(3);
$feed1->setLink('http://goo');
$feed2 = new Feed();
$feed2->setId(5);
$feed2->setLink('http://gee');
$feeds = array($feed1, $feed2);
$articles = array(
$item1, $item2
);
$this->feedBusinessLayer->expects($this->once())
->method('findAll')
->with($this->equalTo($this->user))
->will($this->returnValue($feeds));
$this->itemBusinessLayer->expects($this->once())
->method('getUnreadOrStarred')
->with($this->equalTo($this->user))
->will($this->returnValue($articles));
$return = $this->controller->articles();
$headers = $return->getHeaders();
$this->assertEquals('attachment; filename="articles.json"', $headers ['Content-Disposition']);
$this->assertEquals('[{"guid":null,"url":null,"title":null,' .
'"author":null,"pubDate":null,"body":null,"enclosureMime":null,' .
'"enclosureLink":null,"unread":false,"starred":false,' .
'"feedLink":"http:\/\/goo"},{"guid":null,"url":null,"title":null,' .
'"author":null,"pubDate":null,"body":null,"enclosureMime":null,' .
'"enclosureLink":null,"unread":false,"starred":false,' .
'"feedLink":"http:\/\/gee"}]', $return->render());
}
}
|