4 * Copyright © 2003-2024 The Galette Team
6 * This file is part of Galette (https://galette.eu).
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.
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.
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/>.
22 namespace Galette\Entity\test\units
;
24 use Galette\GaletteTestCase
;
29 * @author Johan Cwiklinski <johan@x-tnd.be>
31 class Social
extends GaletteTestCase
33 protected int $seed = 25568744158;
40 public function tearDown(): void
44 $this->deleteSocials();
46 //drop dynamic translations
47 $delete = $this->zdb
->delete(\Galette\Core\L10n
::TABLE
);
48 $this->zdb
->execute($delete);
50 $delete = $this->zdb
->delete(\Galette\Entity\Adherent
::TABLE
);
51 $delete->where(['fingerprint' => 'FAKER' . $this->seed
]);
52 $this->zdb
->execute($delete);
60 private function deleteSocials()
62 $delete = $this->zdb
->delete(\Galette\Entity\Social
::TABLE
);
63 $this->zdb
->execute($delete);
71 public function testObject()
73 $social = new \Galette\Entity\
Social($this->zdb
);
76 $this->assertInstanceOf(\Galette\Entity\Social
::class, $social->setType('mytype'));
77 $this->assertSame('mytype', $social->type
);
79 $this->assertInstanceOf(\Galette\Entity\Social
::class, $social->setUrl('myurl'));
80 $this->assertSame('myurl', $social->url
);
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
);
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
);
95 * Test socials "system" types
99 public function testGetSystemTypes()
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));
106 $this->assertSame('Twitter', $social->getSystemType(\Galette\Entity\Social
::TWITTER
));
107 $this->assertSame('twitter', $social->getSystemType(\Galette\Entity\Social
::TWITTER
, false));
111 * Test getListForMember
115 public function testGetListForMember(): void
117 $this->assertEmpty(\Galette\Entity\Social
::getListForMember(null));
119 $this->getMemberTwo();
120 $this->assertEmpty(\Galette\Entity\Social
::getListForMember($this->adh
->id
));
122 $social = new \Galette\Entity\
Social($this->zdb
);
125 ->setType(\Galette\Entity\Social
::MASTODON
)
126 ->setUrl('mastodon URL')
127 ->setLinkedMember($this->adh
->id
)
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
);
138 $social = new \Galette\Entity\
Social($this->zdb
);
141 ->setType(\Galette\Entity\Social
::MASTODON
)
142 ->setUrl('Galette mastodon URL')
143 ->setLinkedMember(null)
147 $social = new \Galette\Entity\
Social($this->zdb
);
150 ->setType(\Galette\Entity\Social
::JABBER
)
151 ->setUrl('Galette jabber')
152 ->setLinkedMember(null)
156 $social = new \Galette\Entity\
Social($this->zdb
);
159 ->setType(\Galette\Entity\Social
::MASTODON
)
160 ->setUrl('Another Galette mastodon URL')
161 ->setLinkedMember(null)
165 $this->assertCount(3, \Galette\Entity\Social
::getListForMember(null));
166 $this->assertCount(1, \Galette\Entity\Social
::getListForMember(null, \Galette\Entity\Social
::JABBER
));
168 $this->assertTrue($social->remove());
169 $this->assertCount(2, \Galette\Entity\Social
::getListForMember(null));