updateoutdatedocsids.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * @author Lukas Reschke <l8kas@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2015, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace Test\Repair;
  22. use OCP\IConfig;
  23. use Test\TestCase;
  24. /**
  25. * Class UpdateOutdatedOcsIds
  26. *
  27. * @package Test\Repair
  28. */
  29. class UpdateOutdatedOcsIds extends TestCase {
  30. /** @var IConfig */
  31. private $config;
  32. /** @var \OC\Repair\UpdateOutdatedOcsIds */
  33. private $updateOutdatedOcsIds;
  34. public function setUp() {
  35. parent::setUp();
  36. $this->config = $this->getMockBuilder('\\OCP\\IConfig')->getMock();
  37. $this->updateOutdatedOcsIds = new \OC\Repair\UpdateOutdatedOcsIds($this->config);
  38. }
  39. public function testGetName() {
  40. $this->assertSame('Repair outdated OCS IDs', $this->updateOutdatedOcsIds->getName());
  41. }
  42. public function testFixOcsIdNoOcsId() {
  43. $this->config
  44. ->expects($this->once())
  45. ->method('getAppValue')
  46. ->with('MyNotInstalledApp', 'ocsid')
  47. ->will($this->returnValue(''));
  48. $this->assertFalse($this->updateOutdatedOcsIds->fixOcsId('MyNotInstalledApp', '1337', '0815'));
  49. }
  50. public function testFixOcsIdUpdateOcsId() {
  51. $this->config
  52. ->expects($this->at(0))
  53. ->method('getAppValue')
  54. ->with('MyInstalledApp', 'ocsid')
  55. ->will($this->returnValue('1337'));
  56. $this->config
  57. ->expects($this->at(1))
  58. ->method('setAppValue')
  59. ->with('MyInstalledApp', 'ocsid', '0815');
  60. $this->assertTrue($this->updateOutdatedOcsIds->fixOcsId('MyInstalledApp', '1337', '0815'));
  61. }
  62. public function testFixOcsIdAlreadyFixed() {
  63. $this->config
  64. ->expects($this->once())
  65. ->method('getAppValue')
  66. ->with('MyAlreadyFixedAppId', 'ocsid')
  67. ->will($this->returnValue('0815'));
  68. $this->assertFalse($this->updateOutdatedOcsIds->fixOcsId('MyAlreadyFixedAppId', '1337', '0815'));
  69. }
  70. }