]> git.agnieray.net Git - galette.git/blob - tests/Galette/Entity/tests/units/Social.php
a1b611fa6c284232144eb747413b7522cc076b23
[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 * @version SVN: $Id$
34 * @link http://galette.tuxfamily.org
35 * @since 2021-10-26
36 */
37
38 namespace Galette\Entity\test\units;
39
40 use Galette\GaletteTestCase;
41
42 /**
43 * Status tests
44 *
45 * @category Entity
46 * @name Social
47 * @package GaletteTests
48 * @author Johan Cwiklinski <johan@x-tnd.be>
49 * @copyright 2021-2023 The Galette Team
50 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
51 * @link http://galette.tuxfamily.org
52 * @since 2021-10-26
53 */
54 class Social extends GaletteTestCase
55 {
56 protected int $seed = 25568744158;
57
58 /**
59 * Tear down tests
60 *
61 * @param string $method Calling method
62 *
63 * @return void
64 */
65 public function afterTestMethod($method)
66 {
67 parent::afterTestMethod($method);
68
69 $this->deleteSocials();
70
71 //drop dynamic translations
72 $delete = $this->zdb->delete(\Galette\Core\L10n::TABLE);
73 $this->zdb->execute($delete);
74
75 $delete = $this->zdb->delete(\Galette\Entity\Adherent::TABLE);
76 $delete->where(['fingerprint' => 'FAKER' . $this->seed]);
77 $this->zdb->execute($delete);
78
79 $this->cleanHistory();
80 }
81
82 /**
83 * Delete socials
84 *
85 * @return void
86 */
87 private function deleteSocials()
88 {
89 $delete = $this->zdb->delete(\Galette\Entity\Social::TABLE);
90 $this->zdb->execute($delete);
91 }
92
93 /**
94 * Test social object
95 *
96 * @return void
97 */
98 public function testObject()
99 {
100 $social = new \Galette\Entity\Social($this->zdb);
101
102 //setters and getters
103 $this->object($social->setType('mytype'))->isInstanceOf('\Galette\Entity\Social');
104 $this->string($social->type)->isIdenticalTo('mytype');
105
106 $this->object($social->setUrl('myurl'))->isInstanceOf('\Galette\Entity\Social');
107 $this->string($social->url)->isIdenticalTo('myurl');
108
109 //null as member id for Galette main preferences
110 $this->object($social->setLinkedMember(null))->isInstanceOf('\Galette\Entity\Social');
111 $this->variable($social->id_adh)->isNull();
112 $this->variable($social->member)->isNull();
113
114 $this->getMemberTwo();
115 $this->object($social->setLinkedMember($this->adh->id))->isInstanceOf(\Galette\Entity\Social::class);
116 $this->integer($social->id_adh)->isIdenticalTo($this->adh->id);
117 $this->object($social->member)->isInstanceOf(\Galette\Entity\Adherent::class);
118 $this->string($social->member->name)->isIdenticalTo($this->adh->name);
119 }
120
121 /**
122 * Test socials "system" types
123 *
124 * @return void
125 */
126 public function testGetSystemTypes()
127 {
128 $social = new \Galette\Entity\Social($this->zdb);
129 $this->array($social->getSystemTypes())->hasSize(9);
130 $this->array($social->getSystemTypes())->isIdenticalTo($social->getSystemTypes(true));
131 $this->array($social->getSystemTypes(false))->hasSize(9);
132
133 $this->string($social->getSystemType(\Galette\Entity\Social::TWITTER))->isIdenticalTo('Twitter');
134 $this->string($social->getSystemType(\Galette\Entity\Social::TWITTER, false))->isIdenticalTo('twitter');
135 }
136
137 /**
138 * Test getListForMember
139 *
140 * @return void
141 */
142 public function testGetListForMember(): void
143 {
144 $this->array(\Galette\Entity\Social::getListForMember(null))->isEmpty();
145
146 $this->getMemberTwo();
147 $this->array(\Galette\Entity\Social::getListForMember($this->adh->id))->isEmpty();
148
149 $social = new \Galette\Entity\Social($this->zdb);
150 $this->boolean(
151 $social
152 ->setType(\Galette\Entity\Social::MASTODON)
153 ->setUrl('mastodon URL')
154 ->setLinkedMember($this->adh->id)
155 ->store()
156 )->isTrue();
157
158 $socials = \Galette\Entity\Social::getListForMember($this->adh->id);
159 $this->array($socials)->HasSize(1);
160 $social = array_pop($socials);
161 $this->string($social->type)->isIdenticalTo(\Galette\Entity\Social::MASTODON);
162 $this->integer($social->id_adh)->isIdenticalTo($this->adh->id);
163 $this->string($social->url)->isIdenticalTo('mastodon URL');
164
165 $social = new \Galette\Entity\Social($this->zdb);
166 $this->boolean(
167 $social
168 ->setType(\Galette\Entity\Social::MASTODON)
169 ->setUrl('Galette mastodon URL')
170 ->setLinkedMember(null)
171 ->store()
172 )->isTrue();
173
174 $social = new \Galette\Entity\Social($this->zdb);
175 $this->boolean(
176 $social
177 ->setType(\Galette\Entity\Social::JABBER)
178 ->setUrl('Galette jabber')
179 ->setLinkedMember(null)
180 ->store()
181 )->isTrue();
182
183 $social = new \Galette\Entity\Social($this->zdb);
184 $this->boolean(
185 $social
186 ->setType(\Galette\Entity\Social::MASTODON)
187 ->setUrl('Another Galette mastodon URL')
188 ->setLinkedMember(null)
189 ->store()
190 )->isTrue();
191
192 $this->array(\Galette\Entity\Social::getListForMember(null))->hasSize(3);
193 $this->array(\Galette\Entity\Social::getListForMember(null, \Galette\Entity\Social::JABBER))->hasSize(1);
194
195 $this->boolean($social->remove())->isTrue();
196 $this->array(\Galette\Entity\Social::getListForMember(null))->hasSize(2);
197 }
198 }