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