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 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 */
  11. protected $config;
  12. /** @var \OC_Setup */
  13. protected $setupClass;
  14. protected function setUp() {
  15. parent::setUp();
  16. $this->config = $this->getMock('\OCP\IConfig');
  17. $this->setupClass = $this->getMock('\OC_Setup', array('class_exists', 'is_callable'), array($this->config));
  18. }
  19. public function testGetSupportedDatabasesWithOneWorking() {
  20. $this->config
  21. ->expects($this->once())
  22. ->method('getSystemValue')
  23. ->will($this->returnValue(
  24. array('sqlite', 'mysql', 'oci')
  25. ));
  26. $this->setupClass
  27. ->expects($this->once())
  28. ->method('class_exists')
  29. ->will($this->returnValue(true));
  30. $this->setupClass
  31. ->expects($this->exactly(2))
  32. ->method('is_callable')
  33. ->will($this->returnValue(false));
  34. $result = $this->setupClass->getSupportedDatabases();
  35. $expectedResult = array(
  36. 'sqlite' => 'SQLite'
  37. );
  38. $this->assertSame($expectedResult, $result);
  39. }
  40. public function testGetSupportedDatabasesWithNoWorking() {
  41. $this->config
  42. ->expects($this->once())
  43. ->method('getSystemValue')
  44. ->will($this->returnValue(
  45. array('sqlite', 'mysql', 'oci', 'pgsql')
  46. ));
  47. $this->setupClass
  48. ->expects($this->once())
  49. ->method('class_exists')
  50. ->will($this->returnValue(false));
  51. $this->setupClass
  52. ->expects($this->exactly(3))
  53. ->method('is_callable')
  54. ->will($this->returnValue(false));
  55. $result = $this->setupClass->getSupportedDatabases();
  56. $this->assertSame(array(), $result);
  57. }
  58. public function testGetSupportedDatabasesWitAllWorking() {
  59. $this->config
  60. ->expects($this->once())
  61. ->method('getSystemValue')
  62. ->will($this->returnValue(
  63. array('sqlite', 'mysql', 'pgsql', 'oci', 'mssql')
  64. ));
  65. $this->setupClass
  66. ->expects($this->once())
  67. ->method('class_exists')
  68. ->will($this->returnValue(true));
  69. $this->setupClass
  70. ->expects($this->exactly(4))
  71. ->method('is_callable')
  72. ->will($this->returnValue(true));
  73. $result = $this->setupClass->getSupportedDatabases();
  74. $expectedResult = array(
  75. 'sqlite' => 'SQLite',
  76. 'mysql' => 'MySQL/MariaDB',
  77. 'pgsql' => 'PostgreSQL',
  78. 'oci' => 'Oracle',
  79. 'mssql' => 'MS SQL'
  80. );
  81. $this->assertSame($expectedResult, $result);
  82. }
  83. /**
  84. * @expectedException \Exception
  85. * @expectedExceptionMessage Supported databases are not properly configured.
  86. */
  87. public function testGetSupportedDatabaseException() {
  88. $this->config
  89. ->expects($this->once())
  90. ->method('getSystemValue')
  91. ->will($this->returnValue('NotAnArray'));
  92. $this->setupClass->getSupportedDatabases();
  93. }
  94. }