3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
10 * Copyright © 2021-2023 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
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.
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.
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/>.
28 * @package GaletteTests
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
37 namespace Galette\Entity\test\units
;
39 use Galette\GaletteTestCase
;
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
53 class Social
extends GaletteTestCase
55 protected int $seed = 25568744158;
62 public function tearDown(): void
66 $this->deleteSocials();
68 //drop dynamic translations
69 $delete = $this->zdb
->delete(\Galette\Core\L10n
::TABLE
);
70 $this->zdb
->execute($delete);
72 $delete = $this->zdb
->delete(\Galette\Entity\Adherent
::TABLE
);
73 $delete->where(['fingerprint' => 'FAKER' . $this->seed
]);
74 $this->zdb
->execute($delete);
82 private function deleteSocials()
84 $delete = $this->zdb
->delete(\Galette\Entity\Social
::TABLE
);
85 $this->zdb
->execute($delete);
93 public function testObject()
95 $social = new \Galette\Entity\
Social($this->zdb
);
98 $this->assertInstanceOf(\Galette\Entity\Social
::class, $social->setType('mytype'));
99 $this->assertSame('mytype', $social->type
);
101 $this->assertInstanceOf(\Galette\Entity\Social
::class, $social->setUrl('myurl'));
102 $this->assertSame('myurl', $social->url
);
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
);
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
);
117 * Test socials "system" types
121 public function testGetSystemTypes()
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));
128 $this->assertSame('Twitter', $social->getSystemType(\Galette\Entity\Social
::TWITTER
));
129 $this->assertSame('twitter', $social->getSystemType(\Galette\Entity\Social
::TWITTER
, false));
133 * Test getListForMember
137 public function testGetListForMember(): void
139 $this->assertEmpty(\Galette\Entity\Social
::getListForMember(null));
141 $this->getMemberTwo();
142 $this->assertEmpty(\Galette\Entity\Social
::getListForMember($this->adh
->id
));
144 $social = new \Galette\Entity\
Social($this->zdb
);
147 ->setType(\Galette\Entity\Social
::MASTODON
)
148 ->setUrl('mastodon URL')
149 ->setLinkedMember($this->adh
->id
)
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
);
160 $social = new \Galette\Entity\
Social($this->zdb
);
163 ->setType(\Galette\Entity\Social
::MASTODON
)
164 ->setUrl('Galette mastodon URL')
165 ->setLinkedMember(null)
169 $social = new \Galette\Entity\
Social($this->zdb
);
172 ->setType(\Galette\Entity\Social
::JABBER
)
173 ->setUrl('Galette jabber')
174 ->setLinkedMember(null)
178 $social = new \Galette\Entity\
Social($this->zdb
);
181 ->setType(\Galette\Entity\Social
::MASTODON
)
182 ->setUrl('Another Galette mastodon URL')
183 ->setLinkedMember(null)
187 $this->assertCount(3, \Galette\Entity\Social
::getListForMember(null));
188 $this->assertCount(1, \Galette\Entity\Social
::getListForMember(null, \Galette\Entity\Social
::JABBER
));
190 $this->assertTrue($social->remove());
191 $this->assertCount(2, \Galette\Entity\Social
::getListForMember(null));