1
0

StatusControllerTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Björn Schießle <bjoern@schiessle.org>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OCA\Encryption\Tests\Controller;
  28. use OCA\Encryption\Controller\StatusController;
  29. use OCA\Encryption\Session;
  30. use OCP\Encryption\IManager;
  31. use OCP\IL10N;
  32. use OCP\IRequest;
  33. use Test\TestCase;
  34. class StatusControllerTest extends TestCase {
  35. /** @var \OCP\IRequest|\PHPUnit\Framework\MockObject\MockObject */
  36. private $requestMock;
  37. /** @var \OCP\IL10N|\PHPUnit\Framework\MockObject\MockObject */
  38. private $l10nMock;
  39. /** @var \OCA\Encryption\Session | \PHPUnit\Framework\MockObject\MockObject */
  40. protected $sessionMock;
  41. /** @var IManager | \PHPUnit\Framework\MockObject\MockObject */
  42. protected $encryptionManagerMock;
  43. /** @var StatusController */
  44. protected $controller;
  45. protected function setUp(): void {
  46. parent::setUp();
  47. $this->sessionMock = $this->getMockBuilder(Session::class)
  48. ->disableOriginalConstructor()->getMock();
  49. $this->requestMock = $this->createMock(IRequest::class);
  50. $this->l10nMock = $this->getMockBuilder(IL10N::class)
  51. ->disableOriginalConstructor()->getMock();
  52. $this->l10nMock->expects($this->any())
  53. ->method('t')
  54. ->willReturnCallback(function ($message) {
  55. return $message;
  56. });
  57. $this->encryptionManagerMock = $this->createMock(IManager::class);
  58. $this->controller = new StatusController('encryptionTest',
  59. $this->requestMock,
  60. $this->l10nMock,
  61. $this->sessionMock,
  62. $this->encryptionManagerMock);
  63. }
  64. /**
  65. * @dataProvider dataTestGetStatus
  66. *
  67. * @param string $status
  68. * @param string $expectedStatus
  69. */
  70. public function testGetStatus($status, $expectedStatus) {
  71. $this->sessionMock->expects($this->once())
  72. ->method('getStatus')->willReturn($status);
  73. $result = $this->controller->getStatus();
  74. $data = $result->getData();
  75. $this->assertSame($expectedStatus, $data['status']);
  76. }
  77. public function dataTestGetStatus() {
  78. return [
  79. [Session::INIT_EXECUTED, 'interactionNeeded'],
  80. [Session::INIT_SUCCESSFUL, 'success'],
  81. [Session::NOT_INITIALIZED, 'interactionNeeded'],
  82. ['unknown', 'error'],
  83. ];
  84. }
  85. }