ocsclienttest.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  1. <?php
  2. /**
  3. * @author Lukas Reschke <lukas@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2015, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. use OC\OCSClient;
  22. use OCP\Http\Client\IClientService;
  23. use OCP\IConfig;
  24. use OCP\ILogger;
  25. /**
  26. * Class OCSClientTest
  27. */
  28. class OCSClientTest extends \Test\TestCase {
  29. /** @var OCSClient */
  30. private $ocsClient;
  31. /** @var IConfig */
  32. private $config;
  33. /** @var IClientService */
  34. private $clientService;
  35. /** @var ILogger */
  36. private $logger;
  37. public function setUp() {
  38. parent::setUp();
  39. $this->config = $this->getMockBuilder('\OCP\IConfig')
  40. ->disableOriginalConstructor()->getMock();
  41. $this->clientService = $this->getMock('\OCP\Http\Client\IClientService');
  42. $this->logger = $this->getMock('\OCP\ILogger');
  43. $this->ocsClient = new OCSClient(
  44. $this->clientService,
  45. $this->config,
  46. $this->logger
  47. );
  48. }
  49. public function testIsAppStoreEnabledSuccess() {
  50. $this->config
  51. ->expects($this->once())
  52. ->method('getSystemValue')
  53. ->with('appstoreenabled', true)
  54. ->will($this->returnValue(true));
  55. $this->assertTrue($this->ocsClient->isAppStoreEnabled());
  56. }
  57. public function testIsAppStoreEnabledFail() {
  58. $this->config
  59. ->expects($this->once())
  60. ->method('getSystemValue')
  61. ->with('appstoreenabled', true)
  62. ->will($this->returnValue(false));
  63. $this->assertFalse($this->ocsClient->isAppStoreEnabled());
  64. }
  65. public function testGetAppStoreUrl() {
  66. $this->config
  67. ->expects($this->once())
  68. ->method('getSystemValue')
  69. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  70. ->will($this->returnValue('https://api.owncloud.com/v1'));
  71. $this->assertSame('https://api.owncloud.com/v1', Test_Helper::invokePrivate($this->ocsClient, 'getAppStoreUrl'));
  72. }
  73. public function testGetCategoriesDisabledAppStore() {
  74. $this->config
  75. ->expects($this->once())
  76. ->method('getSystemValue')
  77. ->with('appstoreenabled', true)
  78. ->will($this->returnValue(false));
  79. $this->assertNull($this->ocsClient->getCategories());
  80. }
  81. public function testGetCategoriesExceptionClient() {
  82. $this->config
  83. ->expects($this->at(0))
  84. ->method('getSystemValue')
  85. ->with('appstoreenabled', true)
  86. ->will($this->returnValue(true));
  87. $this->config
  88. ->expects($this->at(1))
  89. ->method('getSystemValue')
  90. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  91. ->will($this->returnValue('https://api.owncloud.com/v1'));
  92. $client = $this->getMock('\OCP\Http\Client\IClient');
  93. $client
  94. ->expects($this->once())
  95. ->method('get')
  96. ->with(
  97. 'https://api.owncloud.com/v1/content/categories',
  98. [
  99. 'timeout' => 5,
  100. ]
  101. )
  102. ->will($this->throwException(new \Exception('TheErrorMessage')));
  103. $this->clientService
  104. ->expects($this->once())
  105. ->method('newClient')
  106. ->will($this->returnValue($client));
  107. $this->logger
  108. ->expects($this->once())
  109. ->method('error')
  110. ->with(
  111. 'Could not get categories: TheErrorMessage',
  112. [
  113. 'app' => 'core',
  114. ]
  115. );
  116. $this->assertNull($this->ocsClient->getCategories());
  117. }
  118. public function testGetCategoriesParseError() {
  119. $this->config
  120. ->expects($this->at(0))
  121. ->method('getSystemValue')
  122. ->with('appstoreenabled', true)
  123. ->will($this->returnValue(true));
  124. $this->config
  125. ->expects($this->at(1))
  126. ->method('getSystemValue')
  127. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  128. ->will($this->returnValue('https://api.owncloud.com/v1'));
  129. $response = $this->getMock('\OCP\Http\Client\IResponse');
  130. $response
  131. ->expects($this->once())
  132. ->method('getBody')
  133. ->will($this->returnValue('MyInvalidXml'));
  134. $client = $this->getMock('\OCP\Http\Client\IClient');
  135. $client
  136. ->expects($this->once())
  137. ->method('get')
  138. ->with(
  139. 'https://api.owncloud.com/v1/content/categories',
  140. [
  141. 'timeout' => 5,
  142. ]
  143. )
  144. ->will($this->returnValue($response));
  145. $this->clientService
  146. ->expects($this->once())
  147. ->method('newClient')
  148. ->will($this->returnValue($client));
  149. $this->logger
  150. ->expects($this->once())
  151. ->method('error')
  152. ->with(
  153. 'Could not get categories, content was no valid XML',
  154. [
  155. 'app' => 'core',
  156. ]
  157. );
  158. $this->assertNull($this->ocsClient->getCategories());
  159. }
  160. public function testGetCategoriesSuccessful() {
  161. $this->config
  162. ->expects($this->at(0))
  163. ->method('getSystemValue')
  164. ->with('appstoreenabled', true)
  165. ->will($this->returnValue(true));
  166. $this->config
  167. ->expects($this->at(1))
  168. ->method('getSystemValue')
  169. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  170. ->will($this->returnValue('https://api.owncloud.com/v1'));
  171. $response = $this->getMock('\OCP\Http\Client\IResponse');
  172. $response
  173. ->expects($this->once())
  174. ->method('getBody')
  175. ->will($this->returnValue('<?xml version="1.0"?>
  176. <ocs>
  177. <meta>
  178. <status>ok</status>
  179. <statuscode>100</statuscode>
  180. <message></message>
  181. <totalitems>6</totalitems>
  182. </meta>
  183. <data>
  184. <category>
  185. <id>920</id>
  186. <name>ownCloud Multimedia</name>
  187. </category>
  188. <category>
  189. <id>921</id>
  190. <name>ownCloud PIM</name>
  191. </category>
  192. <category>
  193. <id>922</id>
  194. <name>ownCloud Productivity</name>
  195. </category>
  196. <category>
  197. <id>923</id>
  198. <name>ownCloud Game</name>
  199. </category>
  200. <category>
  201. <id>924</id>
  202. <name>ownCloud Tool</name>
  203. </category>
  204. <category>
  205. <id>925</id>
  206. <name>ownCloud other</name>
  207. </category>
  208. </data>
  209. </ocs>
  210. '));
  211. $client = $this->getMock('\OCP\Http\Client\IClient');
  212. $client
  213. ->expects($this->once())
  214. ->method('get')
  215. ->with(
  216. 'https://api.owncloud.com/v1/content/categories',
  217. [
  218. 'timeout' => 5,
  219. ]
  220. )
  221. ->will($this->returnValue($response));
  222. $this->clientService
  223. ->expects($this->once())
  224. ->method('newClient')
  225. ->will($this->returnValue($client));
  226. $expected = [
  227. 920 => 'ownCloud Multimedia',
  228. 921 => 'ownCloud PIM',
  229. 922 => 'ownCloud Productivity',
  230. 923 => 'ownCloud Game',
  231. 924 => 'ownCloud Tool',
  232. 925 => 'ownCloud other',
  233. ];
  234. $this->assertSame($expected, $this->ocsClient->getCategories());
  235. }
  236. public function testGetApplicationsDisabledAppStore() {
  237. $this->config
  238. ->expects($this->once())
  239. ->method('getSystemValue')
  240. ->with('appstoreenabled', true)
  241. ->will($this->returnValue(false));
  242. $this->assertSame([], $this->ocsClient->getApplications([], 1, 'approved'));
  243. }
  244. public function testGetApplicationsExceptionClient() {
  245. $this->config
  246. ->expects($this->at(0))
  247. ->method('getSystemValue')
  248. ->with('appstoreenabled', true)
  249. ->will($this->returnValue(true));
  250. $this->config
  251. ->expects($this->at(1))
  252. ->method('getSystemValue')
  253. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  254. ->will($this->returnValue('https://api.owncloud.com/v1'));
  255. $client = $this->getMock('\OCP\Http\Client\IClient');
  256. $client
  257. ->expects($this->once())
  258. ->method('get')
  259. ->with(
  260. 'https://api.owncloud.com/v1/content/data',
  261. [
  262. 'timeout' => 5,
  263. 'query' => [
  264. 'version' => implode('x', \OC_Util::getVersion()),
  265. 'filter' => 'approved',
  266. 'categories' => '815x1337',
  267. 'sortmode' => 'new',
  268. 'page' => 1,
  269. 'pagesize' => 100,
  270. 'approved' => 'approved',
  271. ],
  272. ]
  273. )
  274. ->will($this->throwException(new \Exception('TheErrorMessage')));
  275. $this->clientService
  276. ->expects($this->once())
  277. ->method('newClient')
  278. ->will($this->returnValue($client));
  279. $this->logger
  280. ->expects($this->once())
  281. ->method('error')
  282. ->with(
  283. 'Could not get applications: TheErrorMessage',
  284. [
  285. 'app' => 'core',
  286. ]
  287. );
  288. $this->assertSame([], $this->ocsClient->getApplications([815, 1337], 1, 'approved'));
  289. }
  290. public function testGetApplicationsParseError() {
  291. $this->config
  292. ->expects($this->at(0))
  293. ->method('getSystemValue')
  294. ->with('appstoreenabled', true)
  295. ->will($this->returnValue(true));
  296. $this->config
  297. ->expects($this->at(1))
  298. ->method('getSystemValue')
  299. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  300. ->will($this->returnValue('https://api.owncloud.com/v1'));
  301. $response = $this->getMock('\OCP\Http\Client\IResponse');
  302. $response
  303. ->expects($this->once())
  304. ->method('getBody')
  305. ->will($this->returnValue('MyInvalidXml'));
  306. $client = $this->getMock('\OCP\Http\Client\IClient');
  307. $client
  308. ->expects($this->once())
  309. ->method('get')
  310. ->with(
  311. 'https://api.owncloud.com/v1/content/data',
  312. [
  313. 'timeout' => 5,
  314. 'query' => [
  315. 'version' => implode('x', \OC_Util::getVersion()),
  316. 'filter' => 'approved',
  317. 'categories' => '815x1337',
  318. 'sortmode' => 'new',
  319. 'page' => 1,
  320. 'pagesize' => 100,
  321. 'approved' => 'approved',
  322. ],
  323. ]
  324. )
  325. ->will($this->returnValue($response));
  326. $this->clientService
  327. ->expects($this->once())
  328. ->method('newClient')
  329. ->will($this->returnValue($client));
  330. $this->logger
  331. ->expects($this->once())
  332. ->method('error')
  333. ->with(
  334. 'Could not get applications, content was no valid XML',
  335. [
  336. 'app' => 'core',
  337. ]
  338. );
  339. $this->assertSame([], $this->ocsClient->getApplications([815, 1337], 1, 'approved'));
  340. }
  341. public function testGetApplicationsSuccessful() {
  342. $this->config
  343. ->expects($this->at(0))
  344. ->method('getSystemValue')
  345. ->with('appstoreenabled', true)
  346. ->will($this->returnValue(true));
  347. $this->config
  348. ->expects($this->at(1))
  349. ->method('getSystemValue')
  350. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  351. ->will($this->returnValue('https://api.owncloud.com/v1'));
  352. $response = $this->getMock('\OCP\Http\Client\IResponse');
  353. $response
  354. ->expects($this->once())
  355. ->method('getBody')
  356. ->will($this->returnValue('<?xml version="1.0"?>
  357. <ocs>
  358. <meta>
  359. <status>ok</status>
  360. <statuscode>100</statuscode>
  361. <message></message>
  362. <totalitems>2</totalitems>
  363. <itemsperpage>100</itemsperpage>
  364. </meta>
  365. <data>
  366. <content details="summary">
  367. <id>168707</id>
  368. <name>Calendar 8.0</name>
  369. <version>0.6.4</version>
  370. <label>recommended</label>
  371. <changed>2015-02-09T15:23:56+01:00</changed>
  372. <created>2015-01-26T04:35:19+01:00</created>
  373. <typeid>921</typeid>
  374. <typename>ownCloud PIM</typename>
  375. <language></language>
  376. <personid>owncloud</personid>
  377. <profilepage>http://opendesktop.org/usermanager/search.php?username=owncloud</profilepage>
  378. <downloads>5393</downloads>
  379. <score>60</score>
  380. <description>Calendar App for ownCloud</description>
  381. <comments>7</comments>
  382. <fans>10</fans>
  383. <licensetype>16</licensetype>
  384. <approved>0</approved>
  385. <category>1</category>
  386. <license>AGPL</license>
  387. <preview1></preview1>
  388. <detailpage>https://apps.owncloud.com/content/show.php?content=168707</detailpage>
  389. <downloadtype1></downloadtype1>
  390. <downloadway1>0</downloadway1>
  391. <downloadprice1>0</downloadprice1>
  392. <downloadlink1>http://apps.owncloud.com/content/download.php?content=168707&amp;id=1</downloadlink1>
  393. <downloadgpgsignature1></downloadgpgsignature1>
  394. <downloadgpgfingerprint1></downloadgpgfingerprint1>
  395. <downloadpackagename1></downloadpackagename1>
  396. <downloadrepository1></downloadrepository1>
  397. <downloadname1></downloadname1>
  398. <downloadsize1>885</downloadsize1>
  399. </content>
  400. <content details="summary">
  401. <id>168708</id>
  402. <name>Contacts 8.0</name>
  403. <version>0.3.0.18</version>
  404. <label>recommended</label>
  405. <changed>2015-02-09T15:18:58+01:00</changed>
  406. <created>2015-01-26T04:45:17+01:00</created>
  407. <typeid>921</typeid>
  408. <typename>ownCloud PIM</typename>
  409. <language></language>
  410. <personid>owncloud</personid>
  411. <profilepage>http://opendesktop.org/usermanager/search.php?username=owncloud</profilepage>
  412. <downloads>4237</downloads>
  413. <score>58</score>
  414. <description></description>
  415. <comments>3</comments>
  416. <fans>6</fans>
  417. <licensetype>16</licensetype>
  418. <approved>200</approved>
  419. <category>1</category>
  420. <license>AGPL</license>
  421. <preview1></preview1>
  422. <detailpage>https://apps.owncloud.com/content/show.php?content=168708</detailpage>
  423. <downloadtype1></downloadtype1>
  424. <downloadway1>0</downloadway1>
  425. <downloadprice1>0</downloadprice1>
  426. <downloadlink1>http://apps.owncloud.com/content/download.php?content=168708&amp;id=1</downloadlink1>
  427. <downloadgpgsignature1></downloadgpgsignature1>
  428. <downloadgpgfingerprint1></downloadgpgfingerprint1>
  429. <downloadpackagename1></downloadpackagename1>
  430. <downloadrepository1></downloadrepository1>
  431. <downloadname1></downloadname1>
  432. <downloadsize1>1409</downloadsize1>
  433. </content>
  434. </data>
  435. </ocs> '));
  436. $client = $this->getMock('\OCP\Http\Client\IClient');
  437. $client
  438. ->expects($this->once())
  439. ->method('get')
  440. ->with(
  441. 'https://api.owncloud.com/v1/content/data',
  442. [
  443. 'timeout' => 5,
  444. 'query' => [
  445. 'version' => implode('x', \OC_Util::getVersion()),
  446. 'filter' => 'approved',
  447. 'categories' => '815x1337',
  448. 'sortmode' => 'new',
  449. 'page' => 1,
  450. 'pagesize' => 100,
  451. 'approved' => 'approved',
  452. ],
  453. ]
  454. )
  455. ->will($this->returnValue($response));
  456. $this->clientService
  457. ->expects($this->once())
  458. ->method('newClient')
  459. ->will($this->returnValue($client));
  460. $expected = [
  461. [
  462. 'id' => '168707',
  463. 'name' => 'Calendar 8.0',
  464. 'label' => 'recommended',
  465. 'version' => '0.6.4',
  466. 'type' => '921',
  467. 'typename' => 'ownCloud PIM',
  468. 'personid' => 'owncloud',
  469. 'license' => 'AGPL',
  470. 'detailpage' => 'https://apps.owncloud.com/content/show.php?content=168707',
  471. 'preview' => '',
  472. 'preview-full' => '',
  473. 'changed' => 1423491836,
  474. 'description' => 'Calendar App for ownCloud',
  475. 'score' => '60',
  476. 'downloads' => 5393,
  477. 'level' => 0,
  478. 'profilepage' => 'http://opendesktop.org/usermanager/search.php?username=owncloud',
  479. ],
  480. [
  481. 'id' => '168708',
  482. 'name' => 'Contacts 8.0',
  483. 'label' => 'recommended',
  484. 'version' => '0.3.0.18',
  485. 'type' => '921',
  486. 'typename' => 'ownCloud PIM',
  487. 'personid' => 'owncloud',
  488. 'license' => 'AGPL',
  489. 'detailpage' => 'https://apps.owncloud.com/content/show.php?content=168708',
  490. 'preview' => '',
  491. 'preview-full' => '',
  492. 'changed' => 1423491538,
  493. 'description' => '',
  494. 'score' => '58',
  495. 'downloads' => 4237,
  496. 'level' => 200,
  497. 'profilepage' => 'http://opendesktop.org/usermanager/search.php?username=owncloud',
  498. ],
  499. ];
  500. $this->assertEquals($expected, $this->ocsClient->getApplications([815, 1337], 1, 'approved'));
  501. }
  502. public function tesGetApplicationDisabledAppStore() {
  503. $this->config
  504. ->expects($this->once())
  505. ->method('getSystemValue')
  506. ->with('appstoreenabled', true)
  507. ->will($this->returnValue(false));
  508. $this->assertNull($this->ocsClient->getApplication('MyId'));
  509. }
  510. public function testGetApplicationExceptionClient() {
  511. $this->config
  512. ->expects($this->at(0))
  513. ->method('getSystemValue')
  514. ->with('appstoreenabled', true)
  515. ->will($this->returnValue(true));
  516. $this->config
  517. ->expects($this->at(1))
  518. ->method('getSystemValue')
  519. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  520. ->will($this->returnValue('https://api.owncloud.com/v1'));
  521. $client = $this->getMock('\OCP\Http\Client\IClient');
  522. $client
  523. ->expects($this->once())
  524. ->method('get')
  525. ->with(
  526. 'https://api.owncloud.com/v1/content/data/MyId',
  527. [
  528. 'timeout' => 5,
  529. ]
  530. )
  531. ->will($this->throwException(new \Exception('TheErrorMessage')));
  532. $this->clientService
  533. ->expects($this->once())
  534. ->method('newClient')
  535. ->will($this->returnValue($client));
  536. $this->logger
  537. ->expects($this->once())
  538. ->method('error')
  539. ->with(
  540. 'Could not get application: TheErrorMessage',
  541. [
  542. 'app' => 'core',
  543. ]
  544. );
  545. $this->assertNull($this->ocsClient->getApplication('MyId'));
  546. }
  547. public function testGetApplicationParseError() {
  548. $this->config
  549. ->expects($this->at(0))
  550. ->method('getSystemValue')
  551. ->with('appstoreenabled', true)
  552. ->will($this->returnValue(true));
  553. $this->config
  554. ->expects($this->at(1))
  555. ->method('getSystemValue')
  556. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  557. ->will($this->returnValue('https://api.owncloud.com/v1'));
  558. $response = $this->getMock('\OCP\Http\Client\IResponse');
  559. $response
  560. ->expects($this->once())
  561. ->method('getBody')
  562. ->will($this->returnValue('MyInvalidXml'));
  563. $client = $this->getMock('\OCP\Http\Client\IClient');
  564. $client
  565. ->expects($this->once())
  566. ->method('get')
  567. ->with(
  568. 'https://api.owncloud.com/v1/content/data/MyId',
  569. [
  570. 'timeout' => 5,
  571. ]
  572. )
  573. ->will($this->returnValue($response));
  574. $this->clientService
  575. ->expects($this->once())
  576. ->method('newClient')
  577. ->will($this->returnValue($client));
  578. $this->logger
  579. ->expects($this->once())
  580. ->method('error')
  581. ->with(
  582. 'Could not get application, content was no valid XML',
  583. [
  584. 'app' => 'core',
  585. ]
  586. );
  587. $this->assertNull($this->ocsClient->getApplication('MyId'));
  588. }
  589. public function testGetApplicationSuccessful() {
  590. $this->config
  591. ->expects($this->at(0))
  592. ->method('getSystemValue')
  593. ->with('appstoreenabled', true)
  594. ->will($this->returnValue(true));
  595. $this->config
  596. ->expects($this->at(1))
  597. ->method('getSystemValue')
  598. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  599. ->will($this->returnValue('https://api.owncloud.com/v1'));
  600. $response = $this->getMock('\OCP\Http\Client\IResponse');
  601. $response
  602. ->expects($this->once())
  603. ->method('getBody')
  604. ->will($this->returnValue('<?xml version="1.0"?>
  605. <ocs>
  606. <meta>
  607. <status>ok</status>
  608. <statuscode>100</statuscode>
  609. <message></message>
  610. </meta>
  611. <data>
  612. <content details="full">
  613. <id>166053</id>
  614. <name>Versioning</name>
  615. <version>0.0.1</version>
  616. <label>recommended</label>
  617. <typeid>925</typeid>
  618. <typename>ownCloud other</typename>
  619. <language></language>
  620. <personid>owncloud</personid>
  621. <profilepage>http://opendesktop.org/usermanager/search.php?username=owncloud</profilepage>
  622. <created>2014-07-07T16:34:40+02:00</created>
  623. <changed>2014-07-07T16:34:40+02:00</changed>
  624. <downloads>140</downloads>
  625. <score>50</score>
  626. <description>Placeholder for future updates</description>
  627. <summary></summary>
  628. <feedbackurl></feedbackurl>
  629. <changelog></changelog>
  630. <homepage></homepage>
  631. <homepagetype></homepagetype>
  632. <homepage2></homepage2>
  633. <homepagetype2></homepagetype2>
  634. <homepage3></homepage3>
  635. <homepagetype3></homepagetype3>
  636. <homepage4></homepage4>
  637. <homepagetype4></homepagetype4>
  638. <homepage5></homepage5>
  639. <homepagetype5></homepagetype5>
  640. <homepage6></homepage6>
  641. <homepagetype6></homepagetype6>
  642. <homepage7></homepage7>
  643. <homepagetype7></homepagetype7>
  644. <homepage8></homepage8>
  645. <homepagetype8></homepagetype8>
  646. <homepage9></homepage9>
  647. <homepagetype9></homepagetype9>
  648. <homepage10></homepage10>
  649. <homepagetype10></homepagetype10>
  650. <licensetype>16</licensetype>
  651. <license>AGPL</license>
  652. <donationpage></donationpage>
  653. <comments>0</comments>
  654. <commentspage>http://apps.owncloud.com/content/show.php?content=166053</commentspage>
  655. <fans>0</fans>
  656. <fanspage>http://apps.owncloud.com/content/show.php?action=fan&amp;content=166053</fanspage>
  657. <knowledgebaseentries>0</knowledgebaseentries>
  658. <knowledgebasepage>http://apps.owncloud.com/content/show.php?action=knowledgebase&amp;content=166053</knowledgebasepage>
  659. <depend>ownCloud 7</depend>
  660. <preview1></preview1>
  661. <preview2></preview2>
  662. <preview3></preview3>
  663. <previewpic1></previewpic1>
  664. <previewpic2></previewpic2>
  665. <previewpic3></previewpic3>
  666. <picsmall1></picsmall1>
  667. <picsmall2></picsmall2>
  668. <picsmall3></picsmall3>
  669. <detailpage>https://apps.owncloud.com/content/show.php?content=166053</detailpage>
  670. <downloadtype1></downloadtype1>
  671. <downloadprice1>0</downloadprice1>
  672. <downloadlink1>http://apps.owncloud.com/content/download.php?content=166053&amp;id=1</downloadlink1>
  673. <downloadname1></downloadname1>
  674. <downloadgpgfingerprint1></downloadgpgfingerprint1>
  675. <downloadgpgsignature1></downloadgpgsignature1>
  676. <downloadpackagename1></downloadpackagename1>
  677. <downloadrepository1></downloadrepository1>
  678. <downloadsize1>1</downloadsize1>
  679. </content>
  680. </data>
  681. </ocs>
  682. '));
  683. $client = $this->getMock('\OCP\Http\Client\IClient');
  684. $client
  685. ->expects($this->once())
  686. ->method('get')
  687. ->with(
  688. 'https://api.owncloud.com/v1/content/data/MyId',
  689. [
  690. 'timeout' => 5,
  691. ]
  692. )
  693. ->will($this->returnValue($response));
  694. $this->clientService
  695. ->expects($this->once())
  696. ->method('newClient')
  697. ->will($this->returnValue($client));
  698. $expected = [
  699. 'id' => 166053,
  700. 'name' => 'Versioning',
  701. 'version' => '0.0.1',
  702. 'type' => '925',
  703. 'label' => 'recommended',
  704. 'typename' => 'ownCloud other',
  705. 'personid' => 'owncloud',
  706. 'profilepage' => 'http://opendesktop.org/usermanager/search.php?username=owncloud',
  707. 'detailpage' => 'https://apps.owncloud.com/content/show.php?content=166053',
  708. 'preview1' => '',
  709. 'preview2' => '',
  710. 'preview3' => '',
  711. 'changed' => 1404743680,
  712. 'description' => 'Placeholder for future updates',
  713. 'score' => 50,
  714. ];
  715. $this->assertSame($expected, $this->ocsClient->getApplication('MyId'));
  716. }
  717. public function testGetApplicationEmptyXml() {
  718. $this->config
  719. ->expects($this->at(0))
  720. ->method('getSystemValue')
  721. ->with('appstoreenabled', true)
  722. ->will($this->returnValue(true));
  723. $this->config
  724. ->expects($this->at(1))
  725. ->method('getSystemValue')
  726. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  727. ->will($this->returnValue('https://api.owncloud.com/v1'));
  728. $response = $this->getMock('\OCP\Http\Client\IResponse');
  729. $response
  730. ->expects($this->once())
  731. ->method('getBody')
  732. ->will($this->returnValue('<?xml version="1.0"?>
  733. <ocs>
  734. <meta>
  735. <status>ok</status>
  736. <statuscode>100</statuscode>
  737. <message></message>
  738. </meta>
  739. </ocs>
  740. '));
  741. $client = $this->getMock('\OCP\Http\Client\IClient');
  742. $client
  743. ->expects($this->once())
  744. ->method('get')
  745. ->with(
  746. 'https://api.owncloud.com/v1/content/data/MyId',
  747. [
  748. 'timeout' => 5,
  749. ]
  750. )
  751. ->will($this->returnValue($response));
  752. $this->clientService
  753. ->expects($this->once())
  754. ->method('newClient')
  755. ->will($this->returnValue($client));
  756. $this->assertSame(null, $this->ocsClient->getApplication('MyId'));
  757. }
  758. public function testGetApplicationDownloadDisabledAppStore() {
  759. $this->config
  760. ->expects($this->once())
  761. ->method('getSystemValue')
  762. ->with('appstoreenabled', true)
  763. ->will($this->returnValue(false));
  764. $this->assertNull($this->ocsClient->getApplicationDownload('MyId'));
  765. }
  766. public function testGetApplicationDownloadExceptionClient() {
  767. $this->config
  768. ->expects($this->at(0))
  769. ->method('getSystemValue')
  770. ->with('appstoreenabled', true)
  771. ->will($this->returnValue(true));
  772. $this->config
  773. ->expects($this->at(1))
  774. ->method('getSystemValue')
  775. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  776. ->will($this->returnValue('https://api.owncloud.com/v1'));
  777. $client = $this->getMock('\OCP\Http\Client\IClient');
  778. $client
  779. ->expects($this->once())
  780. ->method('get')
  781. ->with(
  782. 'https://api.owncloud.com/v1/content/download/MyId/1',
  783. [
  784. 'timeout' => 5,
  785. ]
  786. )
  787. ->will($this->throwException(new \Exception('TheErrorMessage')));
  788. $this->clientService
  789. ->expects($this->once())
  790. ->method('newClient')
  791. ->will($this->returnValue($client));
  792. $this->logger
  793. ->expects($this->once())
  794. ->method('error')
  795. ->with(
  796. 'Could not get application download URL: TheErrorMessage',
  797. [
  798. 'app' => 'core',
  799. ]
  800. );
  801. $this->assertNull($this->ocsClient->getApplicationDownload('MyId'));
  802. }
  803. public function testGetApplicationDownloadParseError() {
  804. $this->config
  805. ->expects($this->at(0))
  806. ->method('getSystemValue')
  807. ->with('appstoreenabled', true)
  808. ->will($this->returnValue(true));
  809. $this->config
  810. ->expects($this->at(1))
  811. ->method('getSystemValue')
  812. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  813. ->will($this->returnValue('https://api.owncloud.com/v1'));
  814. $response = $this->getMock('\OCP\Http\Client\IResponse');
  815. $response
  816. ->expects($this->once())
  817. ->method('getBody')
  818. ->will($this->returnValue('MyInvalidXml'));
  819. $client = $this->getMock('\OCP\Http\Client\IClient');
  820. $client
  821. ->expects($this->once())
  822. ->method('get')
  823. ->with(
  824. 'https://api.owncloud.com/v1/content/download/MyId/1',
  825. [
  826. 'timeout' => 5,
  827. ]
  828. )
  829. ->will($this->returnValue($response));
  830. $this->clientService
  831. ->expects($this->once())
  832. ->method('newClient')
  833. ->will($this->returnValue($client));
  834. $this->logger
  835. ->expects($this->once())
  836. ->method('error')
  837. ->with(
  838. 'Could not get application download URL, content was no valid XML',
  839. [
  840. 'app' => 'core',
  841. ]
  842. );
  843. $this->assertNull($this->ocsClient->getApplicationDownload('MyId'));
  844. }
  845. public function testGetApplicationDownloadUrlSuccessful() {
  846. $this->config
  847. ->expects($this->at(0))
  848. ->method('getSystemValue')
  849. ->with('appstoreenabled', true)
  850. ->will($this->returnValue(true));
  851. $this->config
  852. ->expects($this->at(1))
  853. ->method('getSystemValue')
  854. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  855. ->will($this->returnValue('https://api.owncloud.com/v1'));
  856. $response = $this->getMock('\OCP\Http\Client\IResponse');
  857. $response
  858. ->expects($this->once())
  859. ->method('getBody')
  860. ->will($this->returnValue('<?xml version="1.0"?>
  861. <ocs>
  862. <meta>
  863. <status>ok</status>
  864. <statuscode>100</statuscode>
  865. <message></message>
  866. </meta>
  867. <data>
  868. <content details="download">
  869. <downloadlink>https://apps.owncloud.com/CONTENT/content-files/166052-files_trashbin.zip</downloadlink>
  870. <mimetype>application/zip</mimetype>
  871. <gpgfingerprint></gpgfingerprint>
  872. <gpgsignature></gpgsignature>
  873. <packagename></packagename>
  874. <repository></repository>
  875. </content>
  876. </data>
  877. </ocs>
  878. '));
  879. $client = $this->getMock('\OCP\Http\Client\IClient');
  880. $client
  881. ->expects($this->once())
  882. ->method('get')
  883. ->with(
  884. 'https://api.owncloud.com/v1/content/download/MyId/1',
  885. [
  886. 'timeout' => 5,
  887. ]
  888. )
  889. ->will($this->returnValue($response));
  890. $this->clientService
  891. ->expects($this->once())
  892. ->method('newClient')
  893. ->will($this->returnValue($client));
  894. $expected = [
  895. 'downloadlink' => 'https://apps.owncloud.com/CONTENT/content-files/166052-files_trashbin.zip',
  896. ];
  897. $this->assertSame($expected, $this->ocsClient->getApplicationDownload('MyId'));
  898. }
  899. }