Skip to content

Commit 9467568

Browse files
committed
let's see
Signed-off-by: dartcafe <github@dartcafe.de>
1 parent b4355b6 commit 9467568

File tree

6 files changed

+146
-21
lines changed

6 files changed

+146
-21
lines changed

.github/workflows/phpunit-mariadb.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ jobs:
104104
persist-credentials: false
105105
path: apps/${{ env.APP_NAME }}
106106

107+
- name: Checkout contacts app
108+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
109+
with:
110+
persist-credentials: false
111+
repository: nextcloud/contacts
112+
ref: ${{ matrix.server-versions }}
113+
path: apps/contacts
114+
115+
- name: Checkout circles app
116+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
117+
with:
118+
persist-credentials: false
119+
repository: nextcloud/circles
120+
ref: ${{ matrix.server-versions }}
121+
path: apps/circles
122+
107123
- name: Set up php ${{ matrix.php-versions }}
108124
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2.36.0
109125
with:
@@ -138,6 +154,8 @@ jobs:
138154
mkdir data
139155
./occ maintenance:install --verbose --database=mysql --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin
140156
./occ app:enable --force ${{ env.APP_NAME }}
157+
./occ app:enable contacts
158+
./occ app:enable circles
141159
142160
- name: Check PHPUnit script is defined
143161
id: check_phpunit

.github/workflows/phpunit-mysql.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ jobs:
102102
persist-credentials: false
103103
path: apps/${{ env.APP_NAME }}
104104

105+
- name: Checkout contacts app
106+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
107+
with:
108+
persist-credentials: false
109+
repository: nextcloud/contacts
110+
ref: ${{ matrix.server-versions }}
111+
path: apps/contacts
112+
113+
- name: Checkout circles app
114+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
115+
with:
116+
persist-credentials: false
117+
repository: nextcloud/circles
118+
ref: ${{ matrix.server-versions }}
119+
path: apps/circles
120+
105121
- name: Set up php ${{ matrix.php-versions }}
106122
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2.36.0
107123
with:
@@ -136,6 +152,8 @@ jobs:
136152
mkdir data
137153
./occ maintenance:install --verbose --database=mysql --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin
138154
./occ app:enable --force ${{ env.APP_NAME }}
155+
./occ app:enable contacts
156+
./occ app:enable circles
139157
140158
- name: Check PHPUnit script is defined
141159
id: check_phpunit

.github/workflows/phpunit-pgsql.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,22 @@ jobs:
105105
persist-credentials: false
106106
path: apps/${{ env.APP_NAME }}
107107

108+
- name: Checkout contacts app
109+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
110+
with:
111+
persist-credentials: false
112+
repository: nextcloud/contacts
113+
ref: ${{ matrix.server-versions }}
114+
path: apps/contacts
115+
116+
- name: Checkout circles app
117+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
118+
with:
119+
persist-credentials: false
120+
repository: nextcloud/circles
121+
ref: ${{ matrix.server-versions }}
122+
path: apps/circles
123+
108124
- name: Set up php ${{ matrix.php-versions }}
109125
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2.36.0
110126
with:
@@ -139,6 +155,8 @@ jobs:
139155
mkdir data
140156
./occ maintenance:install --verbose --database=pgsql --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin
141157
./occ app:enable --force ${{ env.APP_NAME }}
158+
./occ app:enable contacts
159+
./occ app:enable circles
142160
143161
- name: Check PHPUnit script is defined
144162
id: check_phpunit

.github/workflows/phpunit-sqlite.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,22 @@ jobs:
9494
persist-credentials: false
9595
path: apps/${{ env.APP_NAME }}
9696

97+
- name: Checkout contacts app
98+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
99+
with:
100+
persist-credentials: false
101+
repository: nextcloud/contacts
102+
ref: ${{ matrix.server-versions }}
103+
path: apps/contacts
104+
105+
- name: Checkout circles app
106+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
107+
with:
108+
persist-credentials: false
109+
repository: nextcloud/circles
110+
ref: ${{ matrix.server-versions }}
111+
path: apps/circles
112+
97113
- name: Set up php ${{ matrix.php-versions }}
98114
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2.36.0
99115
with:
@@ -128,6 +144,8 @@ jobs:
128144
mkdir data
129145
./occ maintenance:install --verbose --database=sqlite --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin
130146
./occ app:enable --force ${{ env.APP_NAME }}
147+
./occ app:enable contacts
148+
./occ app:enable circles
131149
132150
- name: Check PHPUnit script is defined
133151
id: check_phpunit

tests/Unit/Db/UserMapperTest.php

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
namespace OCA\Polls\Tests\Unit\Db;
1010

11+
use OCA\Circles\Api\v1\Circles as CirclesApi;
12+
use OCA\Circles\Model\Circle as CirclesCircle;
13+
use OCA\DAV\CardDAV\CardDavBackend;
1114
use OCA\Polls\Db\UserMapper;
1215
use OCA\Polls\Exceptions\InvalidShareTypeException;
1316
use OCA\Polls\Model\Group\Circle;
@@ -25,54 +28,102 @@
2528

2629
class UserMapperTest extends UnitTestCase {
2730
private UserMapper $userMapper;
31+
private string $contactUid = '';
32+
private int $contactBookId = 0;
33+
private string $circleId = '';
2834

2935
protected function setUp(): void {
3036
parent::setUp();
3137
$this->userMapper = Server::get(UserMapper::class);
38+
39+
// Create a test contact for Contact/ContactGroup tests
40+
if (Contact::isEnabled()) {
41+
$backend = Server::get(CardDavBackend::class);
42+
$books = $backend->getAddressBooksForUser('principals/users/admin');
43+
if (empty($books)) {
44+
$backend->createAddressBook('principals/users/admin', 'contacts', []);
45+
$books = $backend->getAddressBooksForUser('principals/users/admin');
46+
}
47+
$this->contactBookId = (int)$books[0]['id'];
48+
$this->contactUid = bin2hex(random_bytes(8));
49+
$vcard = "BEGIN:VCARD\r\nVERSION:3.0\r\nUID:{$this->contactUid}\r\nFN:Test Contact\r\nEMAIL:test_{$this->contactUid}@polls.example.com\r\nEND:VCARD";
50+
$backend->createCard($this->contactBookId, $this->contactUid . '.vcf', $vcard);
51+
}
52+
53+
// Create a test circle for Circle tests
54+
if (Circle::isEnabled()) {
55+
\OC_User::setUserId('admin');
56+
$circle = CirclesApi::createCircle(CirclesCircle::CIRCLES_PERSONAL, 'TestPollsCircle_' . bin2hex(random_bytes(4)));
57+
$this->circleId = $circle->getUniqueId();
58+
}
59+
}
60+
61+
protected function tearDown(): void {
62+
parent::tearDown();
63+
64+
if ($this->contactBookId > 0 && $this->contactUid !== '') {
65+
$backend = Server::get(CardDavBackend::class);
66+
$backend->deleteCard($this->contactBookId, $this->contactUid . '.vcf');
67+
}
68+
69+
if ($this->circleId !== '') {
70+
try {
71+
CirclesApi::destroyCircle($this->circleId);
72+
} catch (\Exception $e) {
73+
// ignore cleanup errors
74+
}
75+
}
3276
}
3377

34-
// --- getUserObject: pure factory, no DB needed ---
78+
// --- getUserObject ---
79+
// User/Admin use 'admin' (created by NC install in CI).
80+
// Group uses 'admin' group (also created by NC install).
81+
// Contact/ContactGroup use a vCard created in setUp() via CardDavBackend.
82+
// Circle uses a circle created in setUp() via the Circles v1 API.
3583

3684
public function testGetUserObjectReturnsUser(): void {
37-
$user = $this->userMapper->getUserObject(User::TYPE, 'user1');
85+
$user = $this->userMapper->getUserObject(User::TYPE, 'admin');
3886
$this->assertInstanceOf(User::class, $user);
3987
}
4088

4189
public function testGetUserObjectReturnsAdmin(): void {
42-
$user = $this->userMapper->getUserObject(Admin::TYPE, 'admin1');
90+
$user = $this->userMapper->getUserObject(Admin::TYPE, 'admin');
4391
$this->assertInstanceOf(Admin::class, $user);
4492
}
4593

46-
public function testGetUserObjectReturnsGhost(): void {
47-
$user = $this->userMapper->getUserObject(Ghost::TYPE, 'ghost1');
48-
$this->assertInstanceOf(Ghost::class, $user);
49-
}
50-
5194
public function testGetUserObjectReturnsGroup(): void {
52-
$user = $this->userMapper->getUserObject(Group::TYPE, 'group1');
95+
$user = $this->userMapper->getUserObject(Group::TYPE, 'admin');
5396
$this->assertInstanceOf(Group::class, $user);
5497
}
5598

56-
public function testGetUserObjectReturnsEmail(): void {
57-
$user = $this->userMapper->getUserObject(Email::TYPE, 'email_user', 'Display', 'test@example.com', 'en');
58-
$this->assertInstanceOf(Email::class, $user);
59-
}
60-
6199
public function testGetUserObjectReturnsContact(): void {
62-
$user = $this->userMapper->getUserObject(Contact::TYPE, 'contact1');
100+
$this->assertNotEmpty($this->contactUid, 'Contacts app not enabled or contact creation failed');
101+
$user = $this->userMapper->getUserObject(Contact::TYPE, $this->contactUid);
63102
$this->assertInstanceOf(Contact::class, $user);
64103
}
65104

66105
public function testGetUserObjectReturnsContactGroup(): void {
67-
$user = $this->userMapper->getUserObject(ContactGroup::TYPE, 'cg1');
106+
// ContactGroup constructor only checks isEnabled() — no data lookup needed
107+
$user = $this->userMapper->getUserObject(ContactGroup::TYPE, 'TestGroup');
68108
$this->assertInstanceOf(ContactGroup::class, $user);
69109
}
70110

71111
public function testGetUserObjectReturnsCircle(): void {
72-
$user = $this->userMapper->getUserObject(Circle::TYPE, 'circle1');
112+
$this->assertNotEmpty($this->circleId, 'Circles app not enabled or circle creation failed');
113+
$user = $this->userMapper->getUserObject(Circle::TYPE, $this->circleId);
73114
$this->assertInstanceOf(Circle::class, $user);
74115
}
75116

117+
public function testGetUserObjectReturnsGhost(): void {
118+
$user = $this->userMapper->getUserObject(Ghost::TYPE, 'ghost1');
119+
$this->assertInstanceOf(Ghost::class, $user);
120+
}
121+
122+
public function testGetUserObjectReturnsEmail(): void {
123+
$user = $this->userMapper->getUserObject(Email::TYPE, 'email_user', 'Display', 'test@example.com', 'en');
124+
$this->assertInstanceOf(Email::class, $user);
125+
}
126+
76127
public function testGetUserObjectReturnsExternalGenericUser(): void {
77128
$user = $this->userMapper->getUserObject(UserBase::TYPE_EXTERNAL, 'ext1', 'External User');
78129
$this->assertInstanceOf(GenericUser::class, $user);

tests/Unit/Factories/PollGroupFactory.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
* SPDX-FileCopyrightText: 2026 Nextcloud contributors
44
* SPDX-License-Identifier: AGPL-3.0-or-later
55
*/
6-
use League\FactoryMuffin\Faker\Facade as Faker;
7-
86
$fm->define('OCA\Polls\Db\PollGroup')->setDefinitions([
9-
'title' => Faker::text(50),
10-
'description' => Faker::text(255),
7+
'title' => function () {
8+
return bin2hex(random_bytes(16));
9+
},
10+
'description' => function () {
11+
return bin2hex(random_bytes(64));
12+
},
1113
]);

0 commit comments

Comments
 (0)