Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ocsclienttest.php 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  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', self::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([8, 1, 0, 7]));
  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' => 20,
  100. 'query' => ['version' => '8x1x0x7'],
  101. ]
  102. )
  103. ->will($this->throwException(new \Exception('TheErrorMessage')));
  104. $this->clientService
  105. ->expects($this->once())
  106. ->method('newClient')
  107. ->will($this->returnValue($client));
  108. $this->logger
  109. ->expects($this->once())
  110. ->method('error')
  111. ->with(
  112. 'Could not get categories: TheErrorMessage',
  113. [
  114. 'app' => 'core',
  115. ]
  116. );
  117. $this->assertNull($this->ocsClient->getCategories([8, 1, 0, 7]));
  118. }
  119. public function testGetCategoriesParseError() {
  120. $this->config
  121. ->expects($this->at(0))
  122. ->method('getSystemValue')
  123. ->with('appstoreenabled', true)
  124. ->will($this->returnValue(true));
  125. $this->config
  126. ->expects($this->at(1))
  127. ->method('getSystemValue')
  128. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  129. ->will($this->returnValue('https://api.owncloud.com/v1'));
  130. $response = $this->getMock('\OCP\Http\Client\IResponse');
  131. $response
  132. ->expects($this->once())
  133. ->method('getBody')
  134. ->will($this->returnValue('MyInvalidXml'));
  135. $client = $this->getMock('\OCP\Http\Client\IClient');
  136. $client
  137. ->expects($this->once())
  138. ->method('get')
  139. ->with(
  140. 'https://api.owncloud.com/v1/content/categories',
  141. [
  142. 'timeout' => 20,
  143. 'query' => ['version' => '8x1x0x7'],
  144. ]
  145. )
  146. ->will($this->returnValue($response));
  147. $this->clientService
  148. ->expects($this->once())
  149. ->method('newClient')
  150. ->will($this->returnValue($client));
  151. $this->logger
  152. ->expects($this->once())
  153. ->method('error')
  154. ->with(
  155. 'Could not get categories, content was no valid XML',
  156. [
  157. 'app' => 'core',
  158. ]
  159. );
  160. $this->assertNull($this->ocsClient->getCategories([8, 1, 0, 7]));
  161. }
  162. public function testGetCategoriesSuccessful() {
  163. $this->config
  164. ->expects($this->at(0))
  165. ->method('getSystemValue')
  166. ->with('appstoreenabled', true)
  167. ->will($this->returnValue(true));
  168. $this->config
  169. ->expects($this->at(1))
  170. ->method('getSystemValue')
  171. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  172. ->will($this->returnValue('https://api.owncloud.com/v1'));
  173. $response = $this->getMock('\OCP\Http\Client\IResponse');
  174. $response
  175. ->expects($this->once())
  176. ->method('getBody')
  177. ->will($this->returnValue('<?xml version="1.0"?>
  178. <ocs>
  179. <meta>
  180. <status>ok</status>
  181. <statuscode>100</statuscode>
  182. <message></message>
  183. <totalitems>6</totalitems>
  184. </meta>
  185. <data>
  186. <category>
  187. <id>920</id>
  188. <name>ownCloud Multimedia</name>
  189. </category>
  190. <category>
  191. <id>921</id>
  192. <name>ownCloud PIM</name>
  193. </category>
  194. <category>
  195. <id>922</id>
  196. <name>ownCloud Productivity</name>
  197. </category>
  198. <category>
  199. <id>923</id>
  200. <name>ownCloud Game</name>
  201. </category>
  202. <category>
  203. <id>924</id>
  204. <name>ownCloud Tool</name>
  205. </category>
  206. <category>
  207. <id>925</id>
  208. <name>ownCloud other</name>
  209. </category>
  210. </data>
  211. </ocs>
  212. '));
  213. $client = $this->getMock('\OCP\Http\Client\IClient');
  214. $client
  215. ->expects($this->once())
  216. ->method('get')
  217. ->with(
  218. 'https://api.owncloud.com/v1/content/categories',
  219. [
  220. 'timeout' => 20,
  221. 'query' => ['version' => '8x1x0x7'],
  222. ]
  223. )
  224. ->will($this->returnValue($response));
  225. $this->clientService
  226. ->expects($this->once())
  227. ->method('newClient')
  228. ->will($this->returnValue($client));
  229. $expected = [
  230. 920 => 'ownCloud Multimedia',
  231. 921 => 'ownCloud PIM',
  232. 922 => 'ownCloud Productivity',
  233. 923 => 'ownCloud Game',
  234. 924 => 'ownCloud Tool',
  235. 925 => 'ownCloud other',
  236. ];
  237. $this->assertSame($expected, $this->ocsClient->getCategories([8, 1, 0, 7]));
  238. }
  239. public function testGetApplicationsDisabledAppStore() {
  240. $this->config
  241. ->expects($this->once())
  242. ->method('getSystemValue')
  243. ->with('appstoreenabled', true)
  244. ->will($this->returnValue(false));
  245. $this->assertSame([], $this->ocsClient->getApplications([], 1, 'approved', [8, 1, 0, 7]));
  246. }
  247. public function testGetApplicationsExceptionClient() {
  248. $this->config
  249. ->expects($this->at(0))
  250. ->method('getSystemValue')
  251. ->with('appstoreenabled', true)
  252. ->will($this->returnValue(true));
  253. $this->config
  254. ->expects($this->at(1))
  255. ->method('getSystemValue')
  256. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  257. ->will($this->returnValue('https://api.owncloud.com/v1'));
  258. $client = $this->getMock('\OCP\Http\Client\IClient');
  259. $client
  260. ->expects($this->once())
  261. ->method('get')
  262. ->with(
  263. 'https://api.owncloud.com/v1/content/data',
  264. [
  265. 'timeout' => 20,
  266. 'query' => [
  267. 'version' => implode('x', [8, 1, 0, 7]),
  268. 'filter' => 'approved',
  269. 'categories' => '815x1337',
  270. 'sortmode' => 'new',
  271. 'page' => 1,
  272. 'pagesize' => 100,
  273. 'approved' => 'approved',
  274. ],
  275. ]
  276. )
  277. ->will($this->throwException(new \Exception('TheErrorMessage')));
  278. $this->clientService
  279. ->expects($this->once())
  280. ->method('newClient')
  281. ->will($this->returnValue($client));
  282. $this->logger
  283. ->expects($this->once())
  284. ->method('error')
  285. ->with(
  286. 'Could not get applications: TheErrorMessage',
  287. [
  288. 'app' => 'core',
  289. ]
  290. );
  291. $this->assertSame([], $this->ocsClient->getApplications([815, 1337], 1, 'approved', [8, 1, 0, 7]));
  292. }
  293. public function testGetApplicationsParseError() {
  294. $this->config
  295. ->expects($this->at(0))
  296. ->method('getSystemValue')
  297. ->with('appstoreenabled', true)
  298. ->will($this->returnValue(true));
  299. $this->config
  300. ->expects($this->at(1))
  301. ->method('getSystemValue')
  302. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  303. ->will($this->returnValue('https://api.owncloud.com/v1'));
  304. $response = $this->getMock('\OCP\Http\Client\IResponse');
  305. $response
  306. ->expects($this->once())
  307. ->method('getBody')
  308. ->will($this->returnValue('MyInvalidXml'));
  309. $client = $this->getMock('\OCP\Http\Client\IClient');
  310. $client
  311. ->expects($this->once())
  312. ->method('get')
  313. ->with(
  314. 'https://api.owncloud.com/v1/content/data',
  315. [
  316. 'timeout' => 20,
  317. 'query' => [
  318. 'version' => implode('x', [8, 1, 0, 7]),
  319. 'filter' => 'approved',
  320. 'categories' => '815x1337',
  321. 'sortmode' => 'new',
  322. 'page' => 1,
  323. 'pagesize' => 100,
  324. 'approved' => 'approved',
  325. ],
  326. ]
  327. )
  328. ->will($this->returnValue($response));
  329. $this->clientService
  330. ->expects($this->once())
  331. ->method('newClient')
  332. ->will($this->returnValue($client));
  333. $this->logger
  334. ->expects($this->once())
  335. ->method('error')
  336. ->with(
  337. 'Could not get applications, content was no valid XML',
  338. [
  339. 'app' => 'core',
  340. ]
  341. );
  342. $this->assertSame([], $this->ocsClient->getApplications([815, 1337], 1, 'approved', [8, 1, 0, 7]));
  343. }
  344. public function testGetApplicationsSuccessful() {
  345. $this->config
  346. ->expects($this->at(0))
  347. ->method('getSystemValue')
  348. ->with('appstoreenabled', true)
  349. ->will($this->returnValue(true));
  350. $this->config
  351. ->expects($this->at(1))
  352. ->method('getSystemValue')
  353. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  354. ->will($this->returnValue('https://api.owncloud.com/v1'));
  355. $response = $this->getMock('\OCP\Http\Client\IResponse');
  356. $response
  357. ->expects($this->once())
  358. ->method('getBody')
  359. ->will($this->returnValue('<?xml version="1.0"?>
  360. <ocs>
  361. <meta>
  362. <status>ok</status>
  363. <statuscode>100</statuscode>
  364. <message></message>
  365. <totalitems>2</totalitems>
  366. <itemsperpage>100</itemsperpage>
  367. </meta>
  368. <data>
  369. <content details="summary">
  370. <id>168707</id>
  371. <name>Calendar 8.0</name>
  372. <version>0.6.4</version>
  373. <label>recommended</label>
  374. <changed>2015-02-09T15:23:56+01:00</changed>
  375. <created>2015-01-26T04:35:19+01:00</created>
  376. <typeid>921</typeid>
  377. <typename>ownCloud PIM</typename>
  378. <language></language>
  379. <personid>owncloud</personid>
  380. <profilepage>http://opendesktop.org/usermanager/search.php?username=owncloud</profilepage>
  381. <downloads>5393</downloads>
  382. <score>60</score>
  383. <description>Calendar App for ownCloud</description>
  384. <comments>7</comments>
  385. <fans>10</fans>
  386. <licensetype>16</licensetype>
  387. <approved>0</approved>
  388. <category>1</category>
  389. <license>AGPL</license>
  390. <preview1></preview1>
  391. <detailpage>https://apps.owncloud.com/content/show.php?content=168707</detailpage>
  392. <downloadtype1></downloadtype1>
  393. <downloadway1>0</downloadway1>
  394. <downloadprice1>0</downloadprice1>
  395. <downloadlink1>http://apps.owncloud.com/content/download.php?content=168707&amp;id=1</downloadlink1>
  396. <downloadgpgsignature1></downloadgpgsignature1>
  397. <downloadgpgfingerprint1></downloadgpgfingerprint1>
  398. <downloadpackagename1></downloadpackagename1>
  399. <downloadrepository1></downloadrepository1>
  400. <downloadname1></downloadname1>
  401. <downloadsize1>885</downloadsize1>
  402. </content>
  403. <content details="summary">
  404. <id>168708</id>
  405. <name>Contacts 8.0</name>
  406. <version>0.3.0.18</version>
  407. <label>recommended</label>
  408. <changed>2015-02-09T15:18:58+01:00</changed>
  409. <created>2015-01-26T04:45:17+01:00</created>
  410. <typeid>921</typeid>
  411. <typename>ownCloud PIM</typename>
  412. <language></language>
  413. <personid>owncloud</personid>
  414. <profilepage>http://opendesktop.org/usermanager/search.php?username=owncloud</profilepage>
  415. <downloads>4237</downloads>
  416. <score>58</score>
  417. <description></description>
  418. <comments>3</comments>
  419. <fans>6</fans>
  420. <licensetype>16</licensetype>
  421. <approved>200</approved>
  422. <category>1</category>
  423. <license>AGPL</license>
  424. <preview1></preview1>
  425. <detailpage>https://apps.owncloud.com/content/show.php?content=168708</detailpage>
  426. <downloadtype1></downloadtype1>
  427. <downloadway1>0</downloadway1>
  428. <downloadprice1>0</downloadprice1>
  429. <downloadlink1>http://apps.owncloud.com/content/download.php?content=168708&amp;id=1</downloadlink1>
  430. <downloadgpgsignature1></downloadgpgsignature1>
  431. <downloadgpgfingerprint1></downloadgpgfingerprint1>
  432. <downloadpackagename1></downloadpackagename1>
  433. <downloadrepository1></downloadrepository1>
  434. <downloadname1></downloadname1>
  435. <downloadsize1>1409</downloadsize1>
  436. </content>
  437. </data>
  438. </ocs> '));
  439. $client = $this->getMock('\OCP\Http\Client\IClient');
  440. $client
  441. ->expects($this->once())
  442. ->method('get')
  443. ->with(
  444. 'https://api.owncloud.com/v1/content/data',
  445. [
  446. 'timeout' => 20,
  447. 'query' => [
  448. 'version' => implode('x', [8, 1, 0, 7]),
  449. 'filter' => 'approved',
  450. 'categories' => '815x1337',
  451. 'sortmode' => 'new',
  452. 'page' => 1,
  453. 'pagesize' => 100,
  454. 'approved' => 'approved',
  455. ],
  456. ]
  457. )
  458. ->will($this->returnValue($response));
  459. $this->clientService
  460. ->expects($this->once())
  461. ->method('newClient')
  462. ->will($this->returnValue($client));
  463. $expected = [
  464. [
  465. 'id' => '168707',
  466. 'name' => 'Calendar 8.0',
  467. 'label' => 'recommended',
  468. 'version' => '0.6.4',
  469. 'type' => '921',
  470. 'typename' => 'ownCloud PIM',
  471. 'personid' => 'owncloud',
  472. 'license' => 'AGPL',
  473. 'detailpage' => 'https://apps.owncloud.com/content/show.php?content=168707',
  474. 'preview' => '',
  475. 'preview-full' => '',
  476. 'changed' => 1423491836,
  477. 'description' => 'Calendar App for ownCloud',
  478. 'score' => '60',
  479. 'downloads' => 5393,
  480. 'level' => 0,
  481. 'profilepage' => 'http://opendesktop.org/usermanager/search.php?username=owncloud',
  482. ],
  483. [
  484. 'id' => '168708',
  485. 'name' => 'Contacts 8.0',
  486. 'label' => 'recommended',
  487. 'version' => '0.3.0.18',
  488. 'type' => '921',
  489. 'typename' => 'ownCloud PIM',
  490. 'personid' => 'owncloud',
  491. 'license' => 'AGPL',
  492. 'detailpage' => 'https://apps.owncloud.com/content/show.php?content=168708',
  493. 'preview' => '',
  494. 'preview-full' => '',
  495. 'changed' => 1423491538,
  496. 'description' => '',
  497. 'score' => '58',
  498. 'downloads' => 4237,
  499. 'level' => 200,
  500. 'profilepage' => 'http://opendesktop.org/usermanager/search.php?username=owncloud',
  501. ],
  502. ];
  503. $this->assertEquals($expected, $this->ocsClient->getApplications([815, 1337], 1, 'approved', [8, 1, 0, 7]));
  504. }
  505. public function tesGetApplicationDisabledAppStore() {
  506. $this->config
  507. ->expects($this->once())
  508. ->method('getSystemValue')
  509. ->with('appstoreenabled', true)
  510. ->will($this->returnValue(false));
  511. $this->assertNull($this->ocsClient->getApplication('MyId', [8, 1, 0, 7]));
  512. }
  513. public function testGetApplicationExceptionClient() {
  514. $this->config
  515. ->expects($this->at(0))
  516. ->method('getSystemValue')
  517. ->with('appstoreenabled', true)
  518. ->will($this->returnValue(true));
  519. $this->config
  520. ->expects($this->at(1))
  521. ->method('getSystemValue')
  522. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  523. ->will($this->returnValue('https://api.owncloud.com/v1'));
  524. $client = $this->getMock('\OCP\Http\Client\IClient');
  525. $client
  526. ->expects($this->once())
  527. ->method('get')
  528. ->with(
  529. 'https://api.owncloud.com/v1/content/data/MyId',
  530. [
  531. 'timeout' => 20,
  532. 'query' => ['version' => '8x1x0x7'],
  533. ]
  534. )
  535. ->will($this->throwException(new \Exception('TheErrorMessage')));
  536. $this->clientService
  537. ->expects($this->once())
  538. ->method('newClient')
  539. ->will($this->returnValue($client));
  540. $this->logger
  541. ->expects($this->once())
  542. ->method('error')
  543. ->with(
  544. 'Could not get application: TheErrorMessage',
  545. [
  546. 'app' => 'core',
  547. ]
  548. );
  549. $this->assertNull($this->ocsClient->getApplication('MyId', [8, 1, 0, 7]));
  550. }
  551. public function testGetApplicationParseError() {
  552. $this->config
  553. ->expects($this->at(0))
  554. ->method('getSystemValue')
  555. ->with('appstoreenabled', true)
  556. ->will($this->returnValue(true));
  557. $this->config
  558. ->expects($this->at(1))
  559. ->method('getSystemValue')
  560. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  561. ->will($this->returnValue('https://api.owncloud.com/v1'));
  562. $response = $this->getMock('\OCP\Http\Client\IResponse');
  563. $response
  564. ->expects($this->once())
  565. ->method('getBody')
  566. ->will($this->returnValue('MyInvalidXml'));
  567. $client = $this->getMock('\OCP\Http\Client\IClient');
  568. $client
  569. ->expects($this->once())
  570. ->method('get')
  571. ->with(
  572. 'https://api.owncloud.com/v1/content/data/MyId',
  573. [
  574. 'timeout' => 20,
  575. 'query' => ['version' => '8x1x0x7'],
  576. ]
  577. )
  578. ->will($this->returnValue($response));
  579. $this->clientService
  580. ->expects($this->once())
  581. ->method('newClient')
  582. ->will($this->returnValue($client));
  583. $this->logger
  584. ->expects($this->once())
  585. ->method('error')
  586. ->with(
  587. 'Could not get application, content was no valid XML',
  588. [
  589. 'app' => 'core',
  590. ]
  591. );
  592. $this->assertNull($this->ocsClient->getApplication('MyId', [8, 1, 0, 7]));
  593. }
  594. public function testGetApplicationSuccessful() {
  595. $this->config
  596. ->expects($this->at(0))
  597. ->method('getSystemValue')
  598. ->with('appstoreenabled', true)
  599. ->will($this->returnValue(true));
  600. $this->config
  601. ->expects($this->at(1))
  602. ->method('getSystemValue')
  603. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  604. ->will($this->returnValue('https://api.owncloud.com/v1'));
  605. $response = $this->getMock('\OCP\Http\Client\IResponse');
  606. $response
  607. ->expects($this->once())
  608. ->method('getBody')
  609. ->will($this->returnValue('<?xml version="1.0"?>
  610. <ocs>
  611. <meta>
  612. <status>ok</status>
  613. <statuscode>100</statuscode>
  614. <message></message>
  615. </meta>
  616. <data>
  617. <content details="full">
  618. <id>166053</id>
  619. <name>Versioning</name>
  620. <version>0.0.1</version>
  621. <label>recommended</label>
  622. <typeid>925</typeid>
  623. <typename>ownCloud other</typename>
  624. <language></language>
  625. <personid>owncloud</personid>
  626. <profilepage>http://opendesktop.org/usermanager/search.php?username=owncloud</profilepage>
  627. <created>2014-07-07T16:34:40+02:00</created>
  628. <changed>2014-07-07T16:34:40+02:00</changed>
  629. <downloads>140</downloads>
  630. <score>50</score>
  631. <description>Placeholder for future updates</description>
  632. <summary></summary>
  633. <feedbackurl></feedbackurl>
  634. <changelog></changelog>
  635. <homepage></homepage>
  636. <homepagetype></homepagetype>
  637. <homepage2></homepage2>
  638. <homepagetype2></homepagetype2>
  639. <homepage3></homepage3>
  640. <homepagetype3></homepagetype3>
  641. <homepage4></homepage4>
  642. <homepagetype4></homepagetype4>
  643. <homepage5></homepage5>
  644. <homepagetype5></homepagetype5>
  645. <homepage6></homepage6>
  646. <homepagetype6></homepagetype6>
  647. <homepage7></homepage7>
  648. <homepagetype7></homepagetype7>
  649. <homepage8></homepage8>
  650. <homepagetype8></homepagetype8>
  651. <homepage9></homepage9>
  652. <homepagetype9></homepagetype9>
  653. <homepage10></homepage10>
  654. <homepagetype10></homepagetype10>
  655. <licensetype>16</licensetype>
  656. <license>AGPL</license>
  657. <donationpage></donationpage>
  658. <comments>0</comments>
  659. <commentspage>http://apps.owncloud.com/content/show.php?content=166053</commentspage>
  660. <fans>0</fans>
  661. <fanspage>http://apps.owncloud.com/content/show.php?action=fan&amp;content=166053</fanspage>
  662. <knowledgebaseentries>0</knowledgebaseentries>
  663. <knowledgebasepage>http://apps.owncloud.com/content/show.php?action=knowledgebase&amp;content=166053</knowledgebasepage>
  664. <depend>ownCloud 7</depend>
  665. <preview1></preview1>
  666. <preview2></preview2>
  667. <preview3></preview3>
  668. <previewpic1></previewpic1>
  669. <previewpic2></previewpic2>
  670. <previewpic3></previewpic3>
  671. <picsmall1></picsmall1>
  672. <picsmall2></picsmall2>
  673. <picsmall3></picsmall3>
  674. <detailpage>https://apps.owncloud.com/content/show.php?content=166053</detailpage>
  675. <downloadtype1></downloadtype1>
  676. <downloadprice1>0</downloadprice1>
  677. <downloadlink1>http://apps.owncloud.com/content/download.php?content=166053&amp;id=1</downloadlink1>
  678. <downloadname1></downloadname1>
  679. <downloadgpgfingerprint1></downloadgpgfingerprint1>
  680. <downloadgpgsignature1></downloadgpgsignature1>
  681. <downloadpackagename1></downloadpackagename1>
  682. <downloadrepository1></downloadrepository1>
  683. <downloadsize1>1</downloadsize1>
  684. <approved>200</approved>
  685. </content>
  686. </data>
  687. </ocs>
  688. '));
  689. $client = $this->getMock('\OCP\Http\Client\IClient');
  690. $client
  691. ->expects($this->once())
  692. ->method('get')
  693. ->with(
  694. 'https://api.owncloud.com/v1/content/data/166053',
  695. [
  696. 'timeout' => 20,
  697. 'query' => ['version' => '8x1x0x7'],
  698. ]
  699. )
  700. ->will($this->returnValue($response));
  701. $this->clientService
  702. ->expects($this->once())
  703. ->method('newClient')
  704. ->will($this->returnValue($client));
  705. $expected = [
  706. 'id' => 166053,
  707. 'name' => 'Versioning',
  708. 'version' => '0.0.1',
  709. 'type' => '925',
  710. 'label' => 'recommended',
  711. 'typename' => 'ownCloud other',
  712. 'personid' => 'owncloud',
  713. 'profilepage' => 'http://opendesktop.org/usermanager/search.php?username=owncloud',
  714. 'detailpage' => 'https://apps.owncloud.com/content/show.php?content=166053',
  715. 'preview1' => '',
  716. 'preview2' => '',
  717. 'preview3' => '',
  718. 'changed' => 1404743680,
  719. 'description' => 'Placeholder for future updates',
  720. 'score' => 50,
  721. 'level' => 200,
  722. ];
  723. $this->assertSame($expected, $this->ocsClient->getApplication(166053, [8, 1, 0, 7]));
  724. }
  725. public function testGetApplicationSuccessfulWithOldId() {
  726. $this->config
  727. ->expects($this->at(0))
  728. ->method('getSystemValue')
  729. ->with('appstoreenabled', true)
  730. ->will($this->returnValue(true));
  731. $this->config
  732. ->expects($this->at(1))
  733. ->method('getSystemValue')
  734. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  735. ->will($this->returnValue('https://api.owncloud.com/v1'));
  736. $response = $this->getMock('\OCP\Http\Client\IResponse');
  737. $response
  738. ->expects($this->once())
  739. ->method('getBody')
  740. ->will($this->returnValue('<?xml version="1.0"?>
  741. <ocs>
  742. <meta>
  743. <status>ok</status>
  744. <statuscode>100</statuscode>
  745. <message></message>
  746. </meta>
  747. <data>
  748. <content details="full">
  749. <id>1337</id>
  750. <name>Versioning</name>
  751. <version>0.0.1</version>
  752. <label>recommended</label>
  753. <typeid>925</typeid>
  754. <typename>ownCloud other</typename>
  755. <language></language>
  756. <personid>owncloud</personid>
  757. <profilepage>http://opendesktop.org/usermanager/search.php?username=owncloud</profilepage>
  758. <created>2014-07-07T16:34:40+02:00</created>
  759. <changed>2014-07-07T16:34:40+02:00</changed>
  760. <downloads>140</downloads>
  761. <score>50</score>
  762. <description>Placeholder for future updates</description>
  763. <summary></summary>
  764. <feedbackurl></feedbackurl>
  765. <changelog></changelog>
  766. <homepage></homepage>
  767. <homepagetype></homepagetype>
  768. <homepage2></homepage2>
  769. <homepagetype2></homepagetype2>
  770. <homepage3></homepage3>
  771. <homepagetype3></homepagetype3>
  772. <homepage4></homepage4>
  773. <homepagetype4></homepagetype4>
  774. <homepage5></homepage5>
  775. <homepagetype5></homepagetype5>
  776. <homepage6></homepage6>
  777. <homepagetype6></homepagetype6>
  778. <homepage7></homepage7>
  779. <homepagetype7></homepagetype7>
  780. <homepage8></homepage8>
  781. <homepagetype8></homepagetype8>
  782. <homepage9></homepage9>
  783. <homepagetype9></homepagetype9>
  784. <homepage10></homepage10>
  785. <homepagetype10></homepagetype10>
  786. <licensetype>16</licensetype>
  787. <license>AGPL</license>
  788. <donationpage></donationpage>
  789. <comments>0</comments>
  790. <commentspage>http://apps.owncloud.com/content/show.php?content=166053</commentspage>
  791. <fans>0</fans>
  792. <fanspage>http://apps.owncloud.com/content/show.php?action=fan&amp;content=166053</fanspage>
  793. <knowledgebaseentries>0</knowledgebaseentries>
  794. <knowledgebasepage>http://apps.owncloud.com/content/show.php?action=knowledgebase&amp;content=166053</knowledgebasepage>
  795. <depend>ownCloud 7</depend>
  796. <preview1></preview1>
  797. <preview2></preview2>
  798. <preview3></preview3>
  799. <previewpic1></previewpic1>
  800. <previewpic2></previewpic2>
  801. <previewpic3></previewpic3>
  802. <picsmall1></picsmall1>
  803. <picsmall2></picsmall2>
  804. <picsmall3></picsmall3>
  805. <detailpage>https://apps.owncloud.com/content/show.php?content=166053</detailpage>
  806. <downloadtype1></downloadtype1>
  807. <downloadprice1>0</downloadprice1>
  808. <downloadlink1>http://apps.owncloud.com/content/download.php?content=166053&amp;id=1</downloadlink1>
  809. <downloadname1></downloadname1>
  810. <downloadgpgfingerprint1></downloadgpgfingerprint1>
  811. <downloadgpgsignature1></downloadgpgsignature1>
  812. <downloadpackagename1></downloadpackagename1>
  813. <downloadrepository1></downloadrepository1>
  814. <downloadsize1>1</downloadsize1>
  815. <approved>200</approved>
  816. </content>
  817. </data>
  818. </ocs>
  819. '));
  820. $client = $this->getMock('\OCP\Http\Client\IClient');
  821. $client
  822. ->expects($this->once())
  823. ->method('get')
  824. ->with(
  825. 'https://api.owncloud.com/v1/content/data/166053',
  826. [
  827. 'timeout' => 20,
  828. 'query' => ['version' => '8x1x0x7'],
  829. ]
  830. )
  831. ->will($this->returnValue($response));
  832. $this->clientService
  833. ->expects($this->once())
  834. ->method('newClient')
  835. ->will($this->returnValue($client));
  836. $expected = [
  837. 'id' => 166053,
  838. 'name' => 'Versioning',
  839. 'version' => '0.0.1',
  840. 'type' => '925',
  841. 'label' => 'recommended',
  842. 'typename' => 'ownCloud other',
  843. 'personid' => 'owncloud',
  844. 'profilepage' => 'http://opendesktop.org/usermanager/search.php?username=owncloud',
  845. 'detailpage' => 'https://apps.owncloud.com/content/show.php?content=166053',
  846. 'preview1' => '',
  847. 'preview2' => '',
  848. 'preview3' => '',
  849. 'changed' => 1404743680,
  850. 'description' => 'Placeholder for future updates',
  851. 'score' => 50,
  852. 'level' => 200,
  853. ];
  854. $this->assertSame($expected, $this->ocsClient->getApplication(166053, [8, 1, 0, 7]));
  855. }
  856. public function testGetApplicationEmptyXml() {
  857. $this->config
  858. ->expects($this->at(0))
  859. ->method('getSystemValue')
  860. ->with('appstoreenabled', true)
  861. ->will($this->returnValue(true));
  862. $this->config
  863. ->expects($this->at(1))
  864. ->method('getSystemValue')
  865. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  866. ->will($this->returnValue('https://api.owncloud.com/v1'));
  867. $response = $this->getMock('\OCP\Http\Client\IResponse');
  868. $response
  869. ->expects($this->once())
  870. ->method('getBody')
  871. ->will($this->returnValue('<?xml version="1.0"?>
  872. <ocs>
  873. <meta>
  874. <status>ok</status>
  875. <statuscode>100</statuscode>
  876. <message></message>
  877. </meta>
  878. </ocs>
  879. '));
  880. $client = $this->getMock('\OCP\Http\Client\IClient');
  881. $client
  882. ->expects($this->once())
  883. ->method('get')
  884. ->with(
  885. 'https://api.owncloud.com/v1/content/data/MyId',
  886. [
  887. 'timeout' => 20,
  888. 'query' => ['version' => '8x1x0x7'],
  889. ]
  890. )
  891. ->will($this->returnValue($response));
  892. $this->clientService
  893. ->expects($this->once())
  894. ->method('newClient')
  895. ->will($this->returnValue($client));
  896. $this->assertSame(null, $this->ocsClient->getApplication('MyId', [8, 1, 0, 7]));
  897. }
  898. public function testGetApplicationDownloadDisabledAppStore() {
  899. $this->config
  900. ->expects($this->once())
  901. ->method('getSystemValue')
  902. ->with('appstoreenabled', true)
  903. ->will($this->returnValue(false));
  904. $this->assertNull($this->ocsClient->getApplicationDownload('MyId', [8, 1, 0, 7]));
  905. }
  906. public function testGetApplicationDownloadExceptionClient() {
  907. $this->config
  908. ->expects($this->at(0))
  909. ->method('getSystemValue')
  910. ->with('appstoreenabled', true)
  911. ->will($this->returnValue(true));
  912. $this->config
  913. ->expects($this->at(1))
  914. ->method('getSystemValue')
  915. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  916. ->will($this->returnValue('https://api.owncloud.com/v1'));
  917. $client = $this->getMock('\OCP\Http\Client\IClient');
  918. $client
  919. ->expects($this->once())
  920. ->method('get')
  921. ->with(
  922. 'https://api.owncloud.com/v1/content/download/MyId/1',
  923. [
  924. 'timeout' => 20,
  925. 'query' => ['version' => '8x1x0x7'],
  926. ]
  927. )
  928. ->will($this->throwException(new \Exception('TheErrorMessage')));
  929. $this->clientService
  930. ->expects($this->once())
  931. ->method('newClient')
  932. ->will($this->returnValue($client));
  933. $this->logger
  934. ->expects($this->once())
  935. ->method('error')
  936. ->with(
  937. 'Could not get application download URL: TheErrorMessage',
  938. [
  939. 'app' => 'core',
  940. ]
  941. );
  942. $this->assertNull($this->ocsClient->getApplicationDownload('MyId', [8, 1, 0, 7]));
  943. }
  944. public function testGetApplicationDownloadParseError() {
  945. $this->config
  946. ->expects($this->at(0))
  947. ->method('getSystemValue')
  948. ->with('appstoreenabled', true)
  949. ->will($this->returnValue(true));
  950. $this->config
  951. ->expects($this->at(1))
  952. ->method('getSystemValue')
  953. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  954. ->will($this->returnValue('https://api.owncloud.com/v1'));
  955. $response = $this->getMock('\OCP\Http\Client\IResponse');
  956. $response
  957. ->expects($this->once())
  958. ->method('getBody')
  959. ->will($this->returnValue('MyInvalidXml'));
  960. $client = $this->getMock('\OCP\Http\Client\IClient');
  961. $client
  962. ->expects($this->once())
  963. ->method('get')
  964. ->with(
  965. 'https://api.owncloud.com/v1/content/download/MyId/1',
  966. [
  967. 'timeout' => 20,
  968. 'query' => ['version' => '8x1x0x7'],
  969. ]
  970. )
  971. ->will($this->returnValue($response));
  972. $this->clientService
  973. ->expects($this->once())
  974. ->method('newClient')
  975. ->will($this->returnValue($client));
  976. $this->logger
  977. ->expects($this->once())
  978. ->method('error')
  979. ->with(
  980. 'Could not get application download URL, content was no valid XML',
  981. [
  982. 'app' => 'core',
  983. ]
  984. );
  985. $this->assertNull($this->ocsClient->getApplicationDownload('MyId', [8, 1, 0, 7]));
  986. }
  987. public function testGetApplicationDownloadUrlSuccessful() {
  988. $this->config
  989. ->expects($this->at(0))
  990. ->method('getSystemValue')
  991. ->with('appstoreenabled', true)
  992. ->will($this->returnValue(true));
  993. $this->config
  994. ->expects($this->at(1))
  995. ->method('getSystemValue')
  996. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  997. ->will($this->returnValue('https://api.owncloud.com/v1'));
  998. $response = $this->getMock('\OCP\Http\Client\IResponse');
  999. $response
  1000. ->expects($this->once())
  1001. ->method('getBody')
  1002. ->will($this->returnValue('<?xml version="1.0"?>
  1003. <ocs>
  1004. <meta>
  1005. <status>ok</status>
  1006. <statuscode>100</statuscode>
  1007. <message></message>
  1008. </meta>
  1009. <data>
  1010. <content details="download">
  1011. <downloadlink>https://apps.owncloud.com/CONTENT/content-files/166052-files_trashbin.zip</downloadlink>
  1012. <mimetype>application/zip</mimetype>
  1013. <gpgfingerprint></gpgfingerprint>
  1014. <gpgsignature></gpgsignature>
  1015. <packagename></packagename>
  1016. <repository></repository>
  1017. </content>
  1018. </data>
  1019. </ocs>
  1020. '));
  1021. $client = $this->getMock('\OCP\Http\Client\IClient');
  1022. $client
  1023. ->expects($this->once())
  1024. ->method('get')
  1025. ->with(
  1026. 'https://api.owncloud.com/v1/content/download/MyId/1',
  1027. [
  1028. 'timeout' => 20,
  1029. 'query' => ['version' => '8x1x0x7'],
  1030. ]
  1031. )
  1032. ->will($this->returnValue($response));
  1033. $this->clientService
  1034. ->expects($this->once())
  1035. ->method('newClient')
  1036. ->will($this->returnValue($client));
  1037. $expected = [
  1038. 'downloadlink' => 'https://apps.owncloud.com/CONTENT/content-files/166052-files_trashbin.zip',
  1039. ];
  1040. $this->assertSame($expected, $this->ocsClient->getApplicationDownload('MyId', [8, 1, 0, 7]));
  1041. }
  1042. }