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
34 * @link http://galette.tuxfamily.org
38 namespace Galette\Entity\test\units
;
40 use Galette\GaletteTestCase
;
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
54 class Social
extends GaletteTestCase
56 protected int $seed = 25568744158;
61 * @param string $method Calling method
65 public function afterTestMethod($method)
67 parent
::afterTestMethod($method);
69 $this->deleteSocials();
71 //drop dynamic translations
72 $delete = $this->zdb
->delete(\Galette\Core\L10n
::TABLE
);
73 $this->zdb
->execute($delete);
75 $delete = $this->zdb
->delete(\Galette\Entity\Adherent
::TABLE
);
76 $delete->where(['fingerprint' => 'FAKER' . $this->seed
]);
77 $this->zdb
->execute($delete);
79 $this->cleanHistory();
87 private function deleteSocials()
89 $delete = $this->zdb
->delete(\Galette\Entity\Social
::TABLE
);
90 $this->zdb
->execute($delete);
98 public function testObject()
100 $social = new \Galette\Entity\
Social($this->zdb
);
102 //setters and getters
103 $this->object($social->setType('mytype'))->isInstanceOf('\Galette\Entity\Social');
104 $this->string($social->type
)->isIdenticalTo('mytype');
106 $this->object($social->setUrl('myurl'))->isInstanceOf('\Galette\Entity\Social');
107 $this->string($social->url
)->isIdenticalTo('myurl');
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();
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
);
122 * Test socials "system" types
126 public function testGetSystemTypes()
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);
133 $this->string($social->getSystemType(\Galette\Entity\Social
::TWITTER
))->isIdenticalTo('Twitter');
134 $this->string($social->getSystemType(\Galette\Entity\Social
::TWITTER
, false))->isIdenticalTo('twitter');
138 * Test getListForMember
142 public function testGetListForMember(): void
144 $this->array(\Galette\Entity\Social
::getListForMember(null))->isEmpty();
146 $this->getMemberTwo();
147 $this->array(\Galette\Entity\Social
::getListForMember($this->adh
->id
))->isEmpty();
149 $social = new \Galette\Entity\
Social($this->zdb
);
152 ->setType(\Galette\Entity\Social
::MASTODON
)
153 ->setUrl('mastodon URL')
154 ->setLinkedMember($this->adh
->id
)
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');
165 $social = new \Galette\Entity\
Social($this->zdb
);
168 ->setType(\Galette\Entity\Social
::MASTODON
)
169 ->setUrl('Galette mastodon URL')
170 ->setLinkedMember(null)
174 $social = new \Galette\Entity\
Social($this->zdb
);
177 ->setType(\Galette\Entity\Social
::JABBER
)
178 ->setUrl('Galette jabber')
179 ->setLinkedMember(null)
183 $social = new \Galette\Entity\
Social($this->zdb
);
186 ->setType(\Galette\Entity\Social
::MASTODON
)
187 ->setUrl('Another Galette mastodon URL')
188 ->setLinkedMember(null)
192 $this->array(\Galette\Entity\Social
::getListForMember(null))->hasSize(3);
193 $this->array(\Galette\Entity\Social
::getListForMember(null, \Galette\Entity\Social
::JABBER
))->hasSize(1);
195 $this->boolean($social->remove())->isTrue();
196 $this->array(\Galette\Entity\Social
::getListForMember(null))->hasSize(2);