Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2021-03-19 18:55:39 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2021-03-23 14:33:12 +0300
commitb58dd9ee6018a9809f6359c1d355ce7f95392ac0 (patch)
tree82598f4fbfe72dc23168080d3cc0319fb0edd719 /tests
parentc8d2059c2ef25e4fd6ab472e88294c23cd7c5593 (diff)
Respect allow/disallow group sharing setting in group service
Some instances don't want to allow sending emails to everyone in a group Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'tests')
-rw-r--r--tests/Unit/Service/Group/NextcloudGroupServiceTest.php61
1 files changed, 46 insertions, 15 deletions
diff --git a/tests/Unit/Service/Group/NextcloudGroupServiceTest.php b/tests/Unit/Service/Group/NextcloudGroupServiceTest.php
index dac3fdb7d..23bae1fe0 100644
--- a/tests/Unit/Service/Group/NextcloudGroupServiceTest.php
+++ b/tests/Unit/Service/Group/NextcloudGroupServiceTest.php
@@ -2,6 +2,7 @@
/**
* @author Matthias Rella <mrella@pisys.eu>
+ * @author Thomas Citharel <nextcloud@tcit.fr>
*
* Mail
*
@@ -24,19 +25,32 @@ namespace OCA\Mail\Tests\Unit\Service\Group;
use ChristophWurst\Nextcloud\Testing\TestCase;
use OCA\Mail\Service\Group\NextcloudGroupService;
use OCA\Mail\Exception\ServiceException;
+use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IGroup;
use OCP\IUser;
+use PHPUnit\Framework\MockObject\MockObject;
class NextcloudGroupServiceTest extends TestCase {
+ /**
+ * @var IGroupManager|MockObject
+ */
private $groupsManager;
+ /**
+ * @var IGroupManager|MockObject
+ */
+ private $config;
+ /**
+ * @var NextcloudGroupService
+ */
private $groupService;
protected function setUp(): void {
parent::setUp();
$this->groupsManager = $this->createMock(IGroupManager::class);
- $this->groupService = new NextcloudGroupService($this->groupsManager);
+ $this->config = $this->createMock(IConfig::class);
+ $this->groupService = new NextcloudGroupService($this->groupsManager, $this->config);
}
private function createTestGroup($id, $name, $users = []) {
@@ -67,32 +81,49 @@ class NextcloudGroupServiceTest extends TestCase {
return $mockUser;
}
+ public function dataForTestSearch(): array {
+ return [
+ ['yes', [
+ [
+ 'id' => 'testgroup',
+ 'name' => 'first test group',
+ ],
+ [
+ 'id' => 'testgroup2',
+ 'name' => 'second test group',
+ ]
+ ]],
+ ['no', []]
+ ];
+ }
- public function testSearch() {
+
+ /**
+ * @dataProvider dataForTestSearch
+ * @param string $allowGroupSharing
+ * @param array $expected
+ */
+ public function testSearch(string $allowGroupSharing, array $expected): void {
$term = 'te'; // searching for: John Doe
$searchResult = [
$this->createTestGroup('testgroup', 'first test group'),
$this->createTestGroup('testgroup2', 'second test group'),
];
- $this->groupsManager->expects($this->once())
+ $this->groupsManager->expects($allowGroupSharing === 'yes' ? self::once() : self::never())
->method('search')
->with($term)
- ->will($this->returnValue($searchResult));
+ ->willReturn($searchResult);
+
+ $this->config->expects(self::once())
+ ->method('getAppValue')
+ ->with('core', 'shareapi_allow_group_sharing', 'yes')
+ ->willReturn($allowGroupSharing);
+
- $expected = [
- [
- 'id' => 'testgroup',
- 'name' => 'first test group',
- ],
- [
- 'id' => 'testgroup2',
- 'name' => 'second test group',
- ]
- ];
$actual = $this->groupService->search($term);
- $this->assertEquals($expected, $actual);
+ self::assertEquals($expected, $actual);
}
public function testGetUsers() {