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.

ActionProviderStoreTest.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
  4. *
  5. * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
  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 Tests\Contacts\ContactsMenu;
  24. use OC\App\AppManager;
  25. use OC\Contacts\ContactsMenu\ActionProviderStore;
  26. use OC\Contacts\ContactsMenu\Providers\EMailProvider;
  27. use OCP\App\IAppManager;
  28. use OCP\AppFramework\QueryException;
  29. use OCP\Contacts\ContactsMenu\IProvider;
  30. use OCP\ILogger;
  31. use OCP\IServerContainer;
  32. use OCP\IUser;
  33. use Test\TestCase;
  34. class ActionProviderStoreTest extends TestCase {
  35. /** @var IServerContainer|\PHPUnit\Framework\MockObject\MockObject */
  36. private $serverContainer;
  37. /** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
  38. private $appManager;
  39. /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
  40. private $logger;
  41. /** @var ActionProviderStore */
  42. private $actionProviderStore;
  43. protected function setUp(): void {
  44. parent::setUp();
  45. $this->serverContainer = $this->createMock(IServerContainer::class);
  46. $this->appManager = $this->createMock(AppManager::class);
  47. $this->logger = $this->createMock(ILogger::class);
  48. $this->actionProviderStore = new ActionProviderStore($this->serverContainer, $this->appManager, $this->logger);
  49. }
  50. public function testGetProviders() {
  51. $user = $this->createMock(IUser::class);
  52. $provider1 = $this->createMock(EMailProvider::class);
  53. $provider2 = $this->createMock(IProvider::class);
  54. $this->appManager->expects($this->once())
  55. ->method('getEnabledAppsForUser')
  56. ->with($user)
  57. ->willReturn(['contacts']);
  58. $this->appManager->expects($this->once())
  59. ->method('getAppInfo')
  60. ->with('contacts')
  61. ->willReturn([
  62. 'contactsmenu' => [
  63. 'OCA\Contacts\Provider1',
  64. ],
  65. ]);
  66. $this->serverContainer->expects($this->exactly(2))
  67. ->method('query')
  68. ->willReturnMap([
  69. [EMailProvider::class, true, $provider1],
  70. ['OCA\Contacts\Provider1', true, $provider2]
  71. ]);
  72. $providers = $this->actionProviderStore->getProviders($user);
  73. $this->assertCount(2, $providers);
  74. $this->assertInstanceOf(EMailProvider::class, $providers[0]);
  75. }
  76. public function testGetProvidersOfAppWithIncompleInfo() {
  77. $user = $this->createMock(IUser::class);
  78. $provider1 = $this->createMock(EMailProvider::class);
  79. $this->appManager->expects($this->once())
  80. ->method('getEnabledAppsForUser')
  81. ->with($user)
  82. ->willReturn(['contacts']);
  83. $this->appManager->expects($this->once())
  84. ->method('getAppInfo')
  85. ->with('contacts')
  86. ->willReturn([/* Empty info.xml */]);
  87. $this->serverContainer->expects($this->once())
  88. ->method('query')
  89. ->willReturnMap([
  90. [EMailProvider::class, true, $provider1],
  91. ]);
  92. $providers = $this->actionProviderStore->getProviders($user);
  93. $this->assertCount(1, $providers);
  94. $this->assertInstanceOf(EMailProvider::class, $providers[0]);
  95. }
  96. public function testGetProvidersWithQueryException() {
  97. $this->expectException(\Exception::class);
  98. $user = $this->createMock(IUser::class);
  99. $this->appManager->expects($this->once())
  100. ->method('getEnabledAppsForUser')
  101. ->with($user)
  102. ->willReturn([]);
  103. $this->serverContainer->expects($this->once())
  104. ->method('query')
  105. ->willThrowException(new QueryException());
  106. $this->actionProviderStore->getProviders($user);
  107. }
  108. }