1
0

ReleaseMetadataTest.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-only
  5. */
  6. namespace Test\Updater;
  7. use OC\Updater\ReleaseMetadata;
  8. use OCP\Http\Client\IClient;
  9. use OCP\Http\Client\IClientService;
  10. use OCP\Http\Client\IResponse;
  11. use PHPUnit\Framework\MockObject\MockObject;
  12. class ReleaseMetadataTest extends \Test\TestCase {
  13. private IClientService|MockObject $clientService;
  14. protected function setUp(): void {
  15. parent::setUp();
  16. $this->clientService = $this->getMockBuilder(IClientService::class)
  17. ->disableOriginalConstructor()
  18. ->getMock();
  19. }
  20. public function testDownloadMetadata(): void {
  21. $client = $this->createMock(IClient::class);
  22. $response = $this->createMock(IResponse::class);
  23. $this->clientService->expects($this->once())
  24. ->method('newClient')
  25. ->with()
  26. ->willReturn($client);
  27. $client->expects($this->once())
  28. ->method('get')
  29. ->willReturn($response);
  30. $response->expects($this->once())
  31. ->method('getBody')
  32. ->with()
  33. ->willReturn($this->resultRequest());
  34. $releaseMetadata = new ReleaseMetadata($this->clientService);
  35. $this->assertSame($this->resultRequestArray(), $releaseMetadata->downloadMetadata('ouila'));
  36. }
  37. /**
  38. * @dataProvider getMetadataUrlProvider
  39. *
  40. * @param string $version
  41. * @param string $url
  42. */
  43. public function testGetMetadata(string $version, string $url): void {
  44. $client = $this->createMock(IClient::class);
  45. $response = $this->createMock(IResponse::class);
  46. $this->clientService->expects($this->once())
  47. ->method('newClient')
  48. ->with()
  49. ->willReturn($client);
  50. $client->expects($this->once())
  51. ->method('get')
  52. ->with($url)
  53. ->willReturn($response);
  54. $response->expects($this->once())
  55. ->method('getBody')
  56. ->with()
  57. ->willReturn('{}');
  58. $releaseMetadata = new ReleaseMetadata($this->clientService);
  59. $releaseMetadata->getMetadata($version);
  60. }
  61. /**
  62. * @return array
  63. */
  64. public function getMetadataUrlProvider(): array {
  65. return [
  66. [
  67. '30.0.0',
  68. 'https://download.nextcloud.com/server/releases/nextcloud-30.0.0.metadata'
  69. ],
  70. [
  71. '30.0.0-beta1',
  72. 'https://download.nextcloud.com/server/prereleases/nextcloud-30.0.0-beta1.metadata'
  73. ],
  74. [
  75. '30',
  76. 'https://download.nextcloud.com/server/releases/latest-30.metadata'
  77. ]
  78. ];
  79. }
  80. private function resultRequest(): string {
  81. return json_encode($this->resultRequestArray());
  82. }
  83. private function resultRequestArray(): array {
  84. return [
  85. 'migrations' => [
  86. 'core' => [],
  87. 'apps' => [
  88. 'testing' => [
  89. '30000Date20240102030405' => [
  90. 'class' => 'OCP\\Migration\\Attributes\\DropTable',
  91. 'table' => 'old_table',
  92. 'description' => '',
  93. 'notes' => [],
  94. 'columns' => []
  95. ],
  96. [
  97. 'class' => 'OCP\\Migration\\Attributes\\CreateTable',
  98. 'table' => 'new_table',
  99. 'description' => 'Table is used to store things, but also to get more things',
  100. 'notes' => [
  101. 'this is a notice',
  102. 'and another one, if really needed'
  103. ],
  104. 'columns' => []
  105. ],
  106. [
  107. 'class' => 'OCP\\Migration\\Attributes\\AddColumn',
  108. 'table' => 'my_table',
  109. 'description' => '',
  110. 'notes' => [],
  111. 'name' => '',
  112. 'type' => ''
  113. ],
  114. [
  115. 'class' => 'OCP\\Migration\\Attributes\\AddColumn',
  116. 'table' => 'my_table',
  117. 'description' => '',
  118. 'notes' => [],
  119. 'name' => 'another_field',
  120. 'type' => ''
  121. ],
  122. [
  123. 'class' => 'OCP\\Migration\\Attributes\\AddColumn',
  124. 'table' => 'other_table',
  125. 'description' => '',
  126. 'notes' => [],
  127. 'name' => 'last_one',
  128. 'type' => 'date'
  129. ],
  130. [
  131. 'class' => 'OCP\\Migration\\Attributes\\AddIndex',
  132. 'table' => 'my_table',
  133. 'description' => '',
  134. 'notes' => [],
  135. 'type' => ''
  136. ],
  137. [
  138. 'class' => 'OCP\\Migration\\Attributes\\AddIndex',
  139. 'table' => 'my_table',
  140. 'description' => '',
  141. 'notes' => [],
  142. 'type' => 'primary'
  143. ],
  144. [
  145. 'class' => 'OCP\\Migration\\Attributes\\DropColumn',
  146. 'table' => 'other_table',
  147. 'description' => '',
  148. 'notes' => [],
  149. 'name' => '',
  150. 'type' => ''
  151. ],
  152. [
  153. 'class' => 'OCP\\Migration\\Attributes\\DropColumn',
  154. 'table' => 'other_table',
  155. 'description' => 'field is not used anymore and replaced by \'last_one\'',
  156. 'notes' => [],
  157. 'name' => 'old_column',
  158. 'type' => ''
  159. ],
  160. [
  161. 'class' => 'OCP\\Migration\\Attributes\\DropIndex',
  162. 'table' => 'other_table',
  163. 'description' => '',
  164. 'notes' => [],
  165. 'type' => ''
  166. ],
  167. [
  168. 'class' => 'OCP\\Migration\\Attributes\\ModifyColumn',
  169. 'table' => 'other_table',
  170. 'description' => '',
  171. 'notes' => [],
  172. 'name' => '',
  173. 'type' => ''
  174. ],
  175. [
  176. 'class' => 'OCP\\Migration\\Attributes\\ModifyColumn',
  177. 'table' => 'other_table',
  178. 'description' => '',
  179. 'notes' => [],
  180. 'name' => 'this_field',
  181. 'type' => ''
  182. ],
  183. [
  184. 'class' => 'OCP\\Migration\\Attributes\\ModifyColumn',
  185. 'table' => 'other_table',
  186. 'description' => '',
  187. 'notes' => [],
  188. 'name' => 'this_field',
  189. 'type' => 'bigint'
  190. ]
  191. ]
  192. ]
  193. ]
  194. ];
  195. }
  196. }