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.

setup.php 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. use OCP\IConfig;
  9. class Test_OC_Setup extends \Test\TestCase {
  10. /** @var IConfig | PHPUnit_Framework_MockObject_MockObject */
  11. protected $config;
  12. /** @var \bantu\IniGetWrapper\IniGetWrapper | PHPUnit_Framework_MockObject_MockObject */
  13. private $iniWrapper;
  14. /** @var \OCP\IL10N | PHPUnit_Framework_MockObject_MockObject */
  15. private $l10n;
  16. /** @var \OC_Defaults | PHPUnit_Framework_MockObject_MockObject */
  17. private $defaults;
  18. /** @var \OC\Setup | PHPUnit_Framework_MockObject_MockObject */
  19. protected $setupClass;
  20. /** @var \OCP\ILogger | PHPUnit_Framework_MockObject_MockObject */
  21. protected $logger;
  22. /** @var \OCP\Security\ISecureRandom | PHPUnit_Framework_MockObject_MockObject */
  23. protected $random;
  24. protected function setUp() {
  25. parent::setUp();
  26. $this->config = $this->getMock('\OCP\IConfig');
  27. $this->iniWrapper = $this->getMock('\bantu\IniGetWrapper\IniGetWrapper');
  28. $this->l10n = $this->getMock('\OCP\IL10N');
  29. $this->defaults = $this->getMock('\OC_Defaults');
  30. $this->logger = $this->getMock('\OCP\ILogger');
  31. $this->random = $this->getMock('\OCP\Security\ISecureRandom');
  32. $this->setupClass = $this->getMock('\OC\Setup',
  33. ['class_exists', 'is_callable', 'getAvailableDbDriversForPdo'],
  34. [$this->config, $this->iniWrapper, $this->l10n, $this->defaults, $this->logger, $this->random]);
  35. }
  36. public function testGetSupportedDatabasesWithOneWorking() {
  37. $this->config
  38. ->expects($this->once())
  39. ->method('getSystemValue')
  40. ->will($this->returnValue(
  41. array('sqlite', 'mysql', 'oci')
  42. ));
  43. $this->setupClass
  44. ->expects($this->once())
  45. ->method('class_exists')
  46. ->will($this->returnValue(true));
  47. $this->setupClass
  48. ->expects($this->once())
  49. ->method('is_callable')
  50. ->will($this->returnValue(false));
  51. $this->setupClass
  52. ->expects($this->once())
  53. ->method('getAvailableDbDriversForPdo')
  54. ->will($this->returnValue([]));
  55. $result = $this->setupClass->getSupportedDatabases();
  56. $expectedResult = array(
  57. 'sqlite' => 'SQLite'
  58. );
  59. $this->assertSame($expectedResult, $result);
  60. }
  61. public function testGetSupportedDatabasesWithNoWorking() {
  62. $this->config
  63. ->expects($this->once())
  64. ->method('getSystemValue')
  65. ->will($this->returnValue(
  66. array('sqlite', 'mysql', 'oci', 'pgsql')
  67. ));
  68. $this->setupClass
  69. ->expects($this->once())
  70. ->method('class_exists')
  71. ->will($this->returnValue(false));
  72. $this->setupClass
  73. ->expects($this->exactly(2))
  74. ->method('is_callable')
  75. ->will($this->returnValue(false));
  76. $this->setupClass
  77. ->expects($this->once())
  78. ->method('getAvailableDbDriversForPdo')
  79. ->will($this->returnValue([]));
  80. $result = $this->setupClass->getSupportedDatabases();
  81. $this->assertSame(array(), $result);
  82. }
  83. public function testGetSupportedDatabasesWithAllWorking() {
  84. $this->config
  85. ->expects($this->once())
  86. ->method('getSystemValue')
  87. ->will($this->returnValue(
  88. array('sqlite', 'mysql', 'pgsql', 'oci')
  89. ));
  90. $this->setupClass
  91. ->expects($this->once())
  92. ->method('class_exists')
  93. ->will($this->returnValue(true));
  94. $this->setupClass
  95. ->expects($this->exactly(2))
  96. ->method('is_callable')
  97. ->will($this->returnValue(true));
  98. $this->setupClass
  99. ->expects($this->once())
  100. ->method('getAvailableDbDriversForPdo')
  101. ->will($this->returnValue(['mysql']));
  102. $result = $this->setupClass->getSupportedDatabases();
  103. $expectedResult = array(
  104. 'sqlite' => 'SQLite',
  105. 'mysql' => 'MySQL/MariaDB',
  106. 'pgsql' => 'PostgreSQL',
  107. 'oci' => 'Oracle'
  108. );
  109. $this->assertSame($expectedResult, $result);
  110. }
  111. /**
  112. * @expectedException \Exception
  113. * @expectedExceptionMessage Supported databases are not properly configured.
  114. */
  115. public function testGetSupportedDatabaseException() {
  116. $this->config
  117. ->expects($this->once())
  118. ->method('getSystemValue')
  119. ->will($this->returnValue('NotAnArray'));
  120. $this->setupClass->getSupportedDatabases();
  121. }
  122. }