1
0

dependencyanalyzer.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php
  2. /**
  3. * @author Thomas Müller
  4. * @copyright 2014 Thomas Müller deepdiver@owncloud.com
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test\App;
  9. use OC;
  10. use OC\App\Platform;
  11. use OCP\IL10N;
  12. class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
  13. /** @var Platform */
  14. private $platformMock;
  15. /** @var IL10N */
  16. private $l10nMock;
  17. /** @var \OC\App\DependencyAnalyzer */
  18. private $analyser;
  19. public function setUp() {
  20. $this->platformMock = $this->getMockBuilder('\OC\App\Platform')
  21. ->disableOriginalConstructor()
  22. ->getMock();
  23. $this->platformMock->expects($this->any())
  24. ->method('getPhpVersion')
  25. ->will( $this->returnValue('5.4.3'));
  26. $this->platformMock->expects($this->any())
  27. ->method('getDatabase')
  28. ->will( $this->returnValue('mysql'));
  29. $this->platformMock->expects($this->any())
  30. ->method('getOS')
  31. ->will( $this->returnValue('Linux'));
  32. $this->platformMock->expects($this->any())
  33. ->method('isCommandKnown')
  34. ->will( $this->returnCallback(function($command) {
  35. return ($command === 'grep');
  36. }));
  37. $this->platformMock->expects($this->any())
  38. ->method('getLibraryVersion')
  39. ->will( $this->returnCallback(function($lib) {
  40. if ($lib === 'curl') {
  41. return "2.3.4";
  42. }
  43. return null;
  44. }));
  45. $this->platformMock->expects($this->any())
  46. ->method('getOcVersion')
  47. ->will( $this->returnValue('8.0.2'));
  48. $this->l10nMock = $this->getMockBuilder('\OCP\IL10N')
  49. ->disableOriginalConstructor()
  50. ->getMock();
  51. $this->l10nMock->expects($this->any())
  52. ->method('t')
  53. ->will($this->returnCallback(function($text, $parameters = array()) {
  54. return vsprintf($text, $parameters);
  55. }));
  56. $this->analyser = new \OC\App\DependencyAnalyzer($this->platformMock, $this->l10nMock);
  57. }
  58. /**
  59. * @dataProvider providesPhpVersion
  60. */
  61. public function testPhpVersion($expectedMissing, $minVersion, $maxVersion) {
  62. $app = array(
  63. 'dependencies' => array(
  64. 'php' => array()
  65. )
  66. );
  67. if (!is_null($minVersion)) {
  68. $app['dependencies']['php']['@attributes']['min-version'] = $minVersion;
  69. }
  70. if (!is_null($maxVersion)) {
  71. $app['dependencies']['php']['@attributes']['max-version'] = $maxVersion;
  72. }
  73. $missing = $this->analyser->analyze($app);
  74. $this->assertTrue(is_array($missing));
  75. $this->assertEquals($expectedMissing, $missing);
  76. }
  77. /**
  78. * @dataProvider providesDatabases
  79. */
  80. public function testDatabases($expectedMissing, $databases) {
  81. $app = array(
  82. 'dependencies' => array(
  83. )
  84. );
  85. if (!is_null($databases)) {
  86. $app['dependencies']['database'] = $databases;
  87. }
  88. $missing = $this->analyser->analyze($app);
  89. $this->assertTrue(is_array($missing));
  90. $this->assertEquals($expectedMissing, $missing);
  91. }
  92. /**
  93. * @dataProvider providesCommands
  94. */
  95. public function testCommand($expectedMissing, $commands) {
  96. $app = array(
  97. 'dependencies' => array(
  98. )
  99. );
  100. if (!is_null($commands)) {
  101. $app['dependencies']['command'] = $commands;
  102. }
  103. $missing = $this->analyser->analyze($app);
  104. $this->assertTrue(is_array($missing));
  105. $this->assertEquals($expectedMissing, $missing);
  106. }
  107. /**
  108. * @dataProvider providesLibs
  109. * @param $expectedMissing
  110. * @param $libs
  111. */
  112. function testLibs($expectedMissing, $libs) {
  113. $app = array(
  114. 'dependencies' => array(
  115. )
  116. );
  117. if (!is_null($libs)) {
  118. $app['dependencies']['lib'] = $libs;
  119. }
  120. $missing = $this->analyser->analyze($app);
  121. $this->assertTrue(is_array($missing));
  122. $this->assertEquals($expectedMissing, $missing);
  123. }
  124. /**
  125. * @dataProvider providesOS
  126. * @param $expectedMissing
  127. * @param $oss
  128. */
  129. function testOS($expectedMissing, $oss) {
  130. $app = array(
  131. 'dependencies' => array()
  132. );
  133. if (!is_null($oss)) {
  134. $app['dependencies']['os'] = $oss;
  135. }
  136. $missing = $this->analyser->analyze($app);
  137. $this->assertTrue(is_array($missing));
  138. $this->assertEquals($expectedMissing, $missing);
  139. }
  140. /**
  141. * @dataProvider providesOC
  142. * @param $expectedMissing
  143. * @param $oc
  144. */
  145. function testOC($expectedMissing, $oc) {
  146. $app = array(
  147. 'dependencies' => array()
  148. );
  149. if (!is_null($oc)) {
  150. $app['dependencies']['owncloud'] = $oc;
  151. }
  152. $missing = $this->analyser->analyze($app);
  153. $this->assertTrue(is_array($missing));
  154. $this->assertEquals($expectedMissing, $missing);
  155. }
  156. function providesOC() {
  157. return array(
  158. // no version -> no missing dependency
  159. array(array(), null),
  160. array(array(), array('@attributes' => array('min-version' => '8', 'max-version' => '8'))),
  161. array(array(), array('@attributes' => array('min-version' => '8.0', 'max-version' => '8.0'))),
  162. array(array(), array('@attributes' => array('min-version' => '8.0.2', 'max-version' => '8.0.2'))),
  163. array(array('ownCloud 8.0.3 or higher is required.'), array('@attributes' => array('min-version' => '8.0.3'))),
  164. array(array('ownCloud 9 or higher is required.'), array('@attributes' => array('min-version' => '9'))),
  165. array(array('ownCloud with a version lower than 8.0.1 is required.'), array('@attributes' => array('max-version' => '8.0.1'))),
  166. );
  167. }
  168. function providesOS() {
  169. return array(
  170. array(array(), null),
  171. array(array(), array()),
  172. array(array('Following platforms are supported: ANDROID'), 'ANDROID'),
  173. array(array('Following platforms are supported: WINNT'), array('WINNT'))
  174. );
  175. }
  176. function providesLibs() {
  177. return array(
  178. // we expect curl to exist
  179. array(array(), 'curl'),
  180. // we expect abcde to exist
  181. array(array('The library abcde is not available.'), array('abcde')),
  182. // curl in version 100.0 does not exist
  183. array(array('Library curl with a version higher than 100.0 is required - available version 2.3.4.'),
  184. array(array('@attributes' => array('min-version' => '100.0'), '@value' => 'curl'))),
  185. // curl in version 100.0 does not exist
  186. array(array('Library curl with a version lower than 1.0.0 is required - available version 2.3.4.'),
  187. array(array('@attributes' => array('max-version' => '1.0.0'), '@value' => 'curl'))),
  188. array(array('Library curl with a version lower than 2.3.3 is required - available version 2.3.4.'),
  189. array(array('@attributes' => array('max-version' => '2.3.3'), '@value' => 'curl'))),
  190. array(array('Library curl with a version higher than 2.3.5 is required - available version 2.3.4.'),
  191. array(array('@attributes' => array('min-version' => '2.3.5'), '@value' => 'curl'))),
  192. array(array(),
  193. array(array('@attributes' => array('min-version' => '2.3.4', 'max-version' => '2.3.4'), '@value' => 'curl'))),
  194. array(array(),
  195. array(array('@attributes' => array('min-version' => '2.3', 'max-version' => '2.3'), '@value' => 'curl'))),
  196. array(array(),
  197. array(array('@attributes' => array('min-version' => '2', 'max-version' => '2'), '@value' => 'curl'))),
  198. );
  199. }
  200. function providesCommands() {
  201. return array(
  202. array(array(), null),
  203. // grep is known on linux
  204. array(array(), array(array('@attributes' => array('os' => 'Linux'), '@value' => 'grep'))),
  205. // grepp is not known on linux
  206. array(array('The command line tool grepp could not be found'), array(array('@attributes' => array('os' => 'Linux'), '@value' => 'grepp'))),
  207. // we don't care about tools on Windows - we are on Linux
  208. array(array(), array(array('@attributes' => array('os' => 'Windows'), '@value' => 'grepp'))),
  209. // grep is known on all systems
  210. array(array(), 'grep'),
  211. );
  212. }
  213. function providesDatabases() {
  214. return array(
  215. // non BC - in case on databases are defined -> all are supported
  216. array(array(), null),
  217. array(array(), array()),
  218. array(array('Following databases are supported: mongodb'), 'mongodb'),
  219. array(array('Following databases are supported: sqlite, postgres'), array('sqlite', array('@value' => 'postgres'))),
  220. );
  221. }
  222. function providesPhpVersion() {
  223. return array(
  224. array(array(), null, null),
  225. array(array(), '5.4', null),
  226. array(array(), null, '5.5'),
  227. array(array(), '5.4', '5.5'),
  228. array(array('PHP 5.4.4 or higher is required.'), '5.4.4', null),
  229. array(array('PHP with a version lower than 5.4.2 is required.'), null, '5.4.2'),
  230. array(array(), '5.4', '5.4'),
  231. );
  232. }
  233. }