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.

135 lines
4.0 KiB

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