setup.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. protected function setUp() {
  21. parent::setUp();
  22. $this->config = $this->getMock('\OCP\IConfig');
  23. $this->iniWrapper = $this->getMock('\bantu\IniGetWrapper\IniGetWrapper');
  24. $this->l10n = $this->getMock('\OCP\IL10N');
  25. $this->defaults = $this->getMock('\OC_Defaults');
  26. $this->setupClass = $this->getMock('\OC\Setup',
  27. ['class_exists', 'is_callable'],
  28. [$this->config, $this->iniWrapper, $this->l10n, $this->defaults]);
  29. }
  30. public function testGetSupportedDatabasesWithOneWorking() {
  31. $this->config
  32. ->expects($this->once())
  33. ->method('getSystemValue')
  34. ->will($this->returnValue(
  35. array('sqlite', 'mysql', 'oci')
  36. ));
  37. $this->setupClass
  38. ->expects($this->once())
  39. ->method('class_exists')
  40. ->will($this->returnValue(true));
  41. $this->setupClass
  42. ->expects($this->exactly(2))
  43. ->method('is_callable')
  44. ->will($this->returnValue(false));
  45. $result = $this->setupClass->getSupportedDatabases();
  46. $expectedResult = array(
  47. 'sqlite' => 'SQLite'
  48. );
  49. $this->assertSame($expectedResult, $result);
  50. }
  51. public function testGetSupportedDatabasesWithNoWorking() {
  52. $this->config
  53. ->expects($this->once())
  54. ->method('getSystemValue')
  55. ->will($this->returnValue(
  56. array('sqlite', 'mysql', 'oci', 'pgsql')
  57. ));
  58. $this->setupClass
  59. ->expects($this->once())
  60. ->method('class_exists')
  61. ->will($this->returnValue(false));
  62. $this->setupClass
  63. ->expects($this->exactly(3))
  64. ->method('is_callable')
  65. ->will($this->returnValue(false));
  66. $result = $this->setupClass->getSupportedDatabases();
  67. $this->assertSame(array(), $result);
  68. }
  69. public function testGetSupportedDatabasesWitAllWorking() {
  70. $this->config
  71. ->expects($this->once())
  72. ->method('getSystemValue')
  73. ->will($this->returnValue(
  74. array('sqlite', 'mysql', 'pgsql', 'oci', 'mssql')
  75. ));
  76. $this->setupClass
  77. ->expects($this->once())
  78. ->method('class_exists')
  79. ->will($this->returnValue(true));
  80. $this->setupClass
  81. ->expects($this->exactly(4))
  82. ->method('is_callable')
  83. ->will($this->returnValue(true));
  84. $result = $this->setupClass->getSupportedDatabases();
  85. $expectedResult = array(
  86. 'sqlite' => 'SQLite',
  87. 'mysql' => 'MySQL/MariaDB',
  88. 'pgsql' => 'PostgreSQL',
  89. 'oci' => 'Oracle',
  90. 'mssql' => 'MS SQL'
  91. );
  92. $this->assertSame($expectedResult, $result);
  93. }
  94. /**
  95. * @expectedException \Exception
  96. * @expectedExceptionMessage Supported databases are not properly configured.
  97. */
  98. public function testGetSupportedDatabaseException() {
  99. $this->config
  100. ->expects($this->once())
  101. ->method('getSystemValue')
  102. ->will($this->returnValue('NotAnArray'));
  103. $this->setupClass->getSupportedDatabases();
  104. }
  105. /**
  106. * This is actual more an integration test whether the version parameter in the .htaccess
  107. * was updated as well when the version has been incremented.
  108. * If it hasn't this test will fail.
  109. */
  110. public function testHtaccessIsCurrent() {
  111. $result = Test_Helper::invokePrivate(
  112. $this->setupClass,
  113. 'isCurrentHtaccess'
  114. );
  115. $this->assertTrue($result);
  116. }
  117. }