You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

991 lines
28 KiB

  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' => 5,
  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' => 5,
  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' => 5,
  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' => 5,
  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' => 5,
  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' => 5,
  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' => 5,
  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' => 5,
  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/MyId',
  695. [
  696. 'timeout' => 5,
  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('MyId', [8, 1, 0, 7]));
  724. }
  725. public function testGetApplicationEmptyXml() {
  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. </ocs>
  748. '));
  749. $client = $this->getMock('\OCP\Http\Client\IClient');
  750. $client
  751. ->expects($this->once())
  752. ->method('get')
  753. ->with(
  754. 'https://api.owncloud.com/v1/content/data/MyId',
  755. [
  756. 'timeout' => 5,
  757. 'query' => ['version' => '8x1x0x7'],
  758. ]
  759. )
  760. ->will($this->returnValue($response));
  761. $this->clientService
  762. ->expects($this->once())
  763. ->method('newClient')
  764. ->will($this->returnValue($client));
  765. $this->assertSame(null, $this->ocsClient->getApplication('MyId', [8, 1, 0, 7]));
  766. }
  767. public function testGetApplicationDownloadDisabledAppStore() {
  768. $this->config
  769. ->expects($this->once())
  770. ->method('getSystemValue')
  771. ->with('appstoreenabled', true)
  772. ->will($this->returnValue(false));
  773. $this->assertNull($this->ocsClient->getApplicationDownload('MyId', [8, 1, 0, 7]));
  774. }
  775. public function testGetApplicationDownloadExceptionClient() {
  776. $this->config
  777. ->expects($this->at(0))
  778. ->method('getSystemValue')
  779. ->with('appstoreenabled', true)
  780. ->will($this->returnValue(true));
  781. $this->config
  782. ->expects($this->at(1))
  783. ->method('getSystemValue')
  784. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  785. ->will($this->returnValue('https://api.owncloud.com/v1'));
  786. $client = $this->getMock('\OCP\Http\Client\IClient');
  787. $client
  788. ->expects($this->once())
  789. ->method('get')
  790. ->with(
  791. 'https://api.owncloud.com/v1/content/download/MyId/1',
  792. [
  793. 'timeout' => 5,
  794. 'query' => ['version' => '8x1x0x7'],
  795. ]
  796. )
  797. ->will($this->throwException(new \Exception('TheErrorMessage')));
  798. $this->clientService
  799. ->expects($this->once())
  800. ->method('newClient')
  801. ->will($this->returnValue($client));
  802. $this->logger
  803. ->expects($this->once())
  804. ->method('error')
  805. ->with(
  806. 'Could not get application download URL: TheErrorMessage',
  807. [
  808. 'app' => 'core',
  809. ]
  810. );
  811. $this->assertNull($this->ocsClient->getApplicationDownload('MyId', [8, 1, 0, 7]));
  812. }
  813. public function testGetApplicationDownloadParseError() {
  814. $this->config
  815. ->expects($this->at(0))
  816. ->method('getSystemValue')
  817. ->with('appstoreenabled', true)
  818. ->will($this->returnValue(true));
  819. $this->config
  820. ->expects($this->at(1))
  821. ->method('getSystemValue')
  822. ->with('appstoreurl', 'https://api.owncloud.com/v1')
  823. ->will($this->returnValue('https://api.owncloud.com/v1'));
  824. $response = $this->getMock('\OCP\Http\Client\IResponse');
  825. $response
  826. ->expects($this->once())
  827. ->method('getBody')
  828. ->will($this->returnValue('MyInvalidXml'));
  829. $client = $this->getMock('\OCP\Http\Client\IClient');
  830. $client
  831. ->expects($this->once())
  832. ->method('get')
  833. ->with(
  834. 'https://api.owncloud.com/v1/content/download/MyId/1',
  835. [
  836. 'timeout' => 5,
  837. 'query' => ['version' => '8x1x0x7'],
  838. ]
  839. )
  840. ->will($this->returnValue($response));
  841. $this->clientService
  842. ->expects($this->once())
  843. ->method('newClient')
  844. ->will($this->returnValue($client));
  845. $this->logger
  846. ->expects($this->once())
  847. ->method('error')
  848. ->with(
  849. 'Could not get application download URL, content was no valid XML',
  850. [
  851. 'app' => 'core',
  852. ]
  853. );
  854. $this->assertNull($this->ocsClient->getApplicationDownload('MyId', [8, 1, 0, 7]));
  855. }
  856. public function testGetApplicationDownloadUrlSuccessful() {
  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. <data>
  879. <content details="download">
  880. <downloadlink>https://apps.owncloud.com/CONTENT/content-files/166052-files_trashbin.zip</downloadlink>
  881. <mimetype>application/zip</mimetype>
  882. <gpgfingerprint></gpgfingerprint>
  883. <gpgsignature></gpgsignature>
  884. <packagename></packagename>
  885. <repository></repository>
  886. </content>
  887. </data>
  888. </ocs>
  889. '));
  890. $client = $this->getMock('\OCP\Http\Client\IClient');
  891. $client
  892. ->expects($this->once())
  893. ->method('get')
  894. ->with(
  895. 'https://api.owncloud.com/v1/content/download/MyId/1',
  896. [
  897. 'timeout' => 5,
  898. 'query' => ['version' => '8x1x0x7'],
  899. ]
  900. )
  901. ->will($this->returnValue($response));
  902. $this->clientService
  903. ->expects($this->once())
  904. ->method('newClient')
  905. ->will($this->returnValue($client));
  906. $expected = [
  907. 'downloadlink' => 'https://apps.owncloud.com/CONTENT/content-files/166052-files_trashbin.zip',
  908. ];
  909. $this->assertSame($expected, $this->ocsClient->getApplicationDownload('MyId', [8, 1, 0, 7]));
  910. }
  911. }