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.

1130 lines
32 KiB

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