]> git.agnieray.net Git - galette.git/blob - tests/Galette/Entity/tests/units/Social.php
ffe387842a6834a3b035e04e04dc4c516debc13f
[galette.git] / tests / Galette / Entity / tests / units / Social.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Socials tests
7 *
8 * PHP version 5
9 *
10 * Copyright © 2021-2023 The Galette Team
11 *
12 * This file is part of Galette (http://galette.tuxfamily.org).
13 *
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
26 *
27 * @category Entity
28 * @package GaletteTests
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2019-2023 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @link http://galette.tuxfamily.org
34 * @since 2021-10-26
35 */
36
37 namespace Galette\Entity\test\units;
38
39 use Galette\GaletteTestCase;
40
41 /**
42 * Status tests
43 *
44 * @category Entity
45 * @name Social
46 * @package GaletteTests
47 * @author Johan Cwiklinski <johan@x-tnd.be>
48 * @copyright 2021-2023 The Galette Team
49 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
50 * @link http://galette.tuxfamily.org
51 * @since 2021-10-26
52 */
53 class Social extends GaletteTestCase
54 {
55 protected int $seed = 25568744158;
56
57 /**
58 * Tear down tests
59 *
60 * @return void
61 */
62 public function tearDown(): void
63 {
64 parent::tearDown();
65
66 $this->deleteSocials();
67
68 //drop dynamic translations
69 $delete = $this->zdb->delete(\Galette\Core\L10n::TABLE);
70 $this->zdb->execute($delete);
71
72 $delete = $this->zdb->delete(\Galette\Entity\Adherent::TABLE);
73 $delete->where(['fingerprint' => 'FAKER' . $this->seed]);
74 $this->zdb->execute($delete);
75 }
76
77 /**
78 * Delete socials
79 *
80 * @return void
81 */
82 private function deleteSocials()
83 {
84 $delete = $this->zdb->delete(\Galette\Entity\Social::TABLE);
85 $this->zdb->execute($delete);
86 }
87
88 /**
89 * Test social object
90 *
91 * @return void
92 */
93 public function testObject()
94 {
95 $social = new \Galette\Entity\Social($this->zdb);
96
97 //setters and getters
98 $this->assertInstanceOf(\Galette\Entity\Social::class, $social->setType('mytype'));
99 $this->assertSame('mytype', $social->type);
100
101 $this->assertInstanceOf(\Galette\Entity\Social::class, $social->setUrl('myurl'));
102 $this->assertSame('myurl', $social->url);
103
104 //null as member id for Galette main preferences
105 $this->assertInstanceOf(\Galette\Entity\Social::class, $social->setLinkedMember(null));
106 $this->assertNull($social->id_adh);
107 $this->assertNull($social->member);
108
109 $this->getMemberTwo();
110 $this->assertInstanceOf(\Galette\Entity\Social::class, $social->setLinkedMember($this->adh->id));
111 $this->assertSame($this->adh->id, $social->id_adh);
112 $this->assertInstanceOf(\Galette\Entity\Adherent::class, $social->member);
113 $this->assertSame($this->adh->name, $social->member->name);
114 }
115
116 /**
117 * Test socials "system" types
118 *
119 * @return void
120 */
121 public function testGetSystemTypes()
122 {
123 $social = new \Galette\Entity\Social($this->zdb);
124 $this->assertCount(9, $social->getSystemTypes());
125 $this->assertSame($social->getSystemTypes(true), $social->getSystemTypes());
126 $this->assertCount(9, $social->getSystemTypes(false));
127
128 $this->assertSame('Twitter', $social->getSystemType(\Galette\Entity\Social::TWITTER));
129 $this->assertSame('twitter', $social->getSystemType(\Galette\Entity\Social::TWITTER, false));
130 }
131
132 /**
133 * Test getListForMember
134 *
135 * @return void
136 */
137 public function testGetListForMember(): void
138 {
139 $this->assertEmpty(\Galette\Entity\Social::getListForMember(null));
140
141 $this->getMemberTwo();
142 $this->assertEmpty(\Galette\Entity\Social::getListForMember($this->adh->id));
143
144 $social = new \Galette\Entity\Social($this->zdb);
145 $this->assertTrue(
146 $social
147 ->setType(\Galette\Entity\Social::MASTODON)
148 ->setUrl('mastodon URL')
149 ->setLinkedMember($this->adh->id)
150 ->store()
151 );
152
153 $socials = \Galette\Entity\Social::getListForMember($this->adh->id);
154 $this->assertCount(1, $socials);
155 $social = array_pop($socials);
156 $this->assertSame(\Galette\Entity\Social::MASTODON, $social->type);
157 $this->assertSame($this->adh->id, $social->id_adh);
158 $this->assertSame('mastodon URL', $social->url);
159
160 $social = new \Galette\Entity\Social($this->zdb);
161 $this->assertTrue(
162 $social
163 ->setType(\Galette\Entity\Social::MASTODON)
164 ->setUrl('Galette mastodon URL')
165 ->setLinkedMember(null)
166 ->store()
167 );
168
169 $social = new \Galette\Entity\Social($this->zdb);
170 $this->assertTrue(
171 $social
172 ->setType(\Galette\Entity\Social::JABBER)
173 ->setUrl('Galette jabber')
174 ->setLinkedMember(null)
175 ->store()
176 );
177
178 $social = new \Galette\Entity\Social($this->zdb);
179 $this->assertTrue(
180 $social
181 ->setType(\Galette\Entity\Social::MASTODON)
182 ->setUrl('Another Galette mastodon URL')
183 ->setLinkedMember(null)
184 ->store()
185 );
186
187 $this->assertCount(3, \Galette\Entity\Social::getListForMember(null));
188 $this->assertCount(1, \Galette\Entity\Social::getListForMember(null, \Galette\Entity\Social::JABBER));
189
190 $this->assertTrue($social->remove());
191 $this->assertCount(2, \Galette\Entity\Social::getListForMember(null));
192 }
193 }