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.

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