ClearGeneratedAvatarCacheTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
  4. *
  5. * @author Julius Härtl <jus@bitgrid.net>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test\Repair;
  24. use OC\Avatar\AvatarManager;
  25. use OC\Repair\ClearGeneratedAvatarCache;
  26. use OCP\BackgroundJob\IJobList;
  27. use OCP\IConfig;
  28. use OCP\Migration\IOutput;
  29. class ClearGeneratedAvatarCacheTest extends \Test\TestCase {
  30. /** @var AvatarManager */
  31. private $avatarManager;
  32. /** @var IOutput */
  33. private $outputMock;
  34. /** @var IConfig */
  35. private $config;
  36. /** @var IJobList */
  37. private $jobList;
  38. protected ClearGeneratedAvatarCache $repair;
  39. protected function setUp(): void {
  40. parent::setUp();
  41. $this->outputMock = $this->createMock(IOutput::class);
  42. $this->avatarManager = $this->createMock(AvatarManager::class);
  43. $this->config = $this->createMock(IConfig::class);
  44. $this->jobList = $this->createMock(IJobList::class);
  45. $this->repair = new ClearGeneratedAvatarCache($this->config, $this->avatarManager, $this->jobList);
  46. }
  47. public function shouldRunDataProvider() {
  48. return [
  49. ['11.0.0.0', true],
  50. ['15.0.0.3', true],
  51. ['13.0.5.2', true],
  52. ['12.0.0.0', true],
  53. ['26.0.0.1', true],
  54. ['15.0.0.2', true],
  55. ['13.0.0.0', true],
  56. ['27.0.0.5', false]
  57. ];
  58. }
  59. /**
  60. * @dataProvider shouldRunDataProvider
  61. *
  62. * @param string $from
  63. * @param boolean $expected
  64. */
  65. public function testShouldRun($from, $expected) {
  66. $this->config->expects($this->any())
  67. ->method('getSystemValueString')
  68. ->with('version', '0.0.0.0')
  69. ->willReturn($from);
  70. $this->assertEquals($expected, $this->invokePrivate($this->repair, 'shouldRun'));
  71. }
  72. }