Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
1,392 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
<?php | ||
|
||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | ||
|
||
/** | ||
* Saved search tests | ||
* | ||
* PHP version 5 | ||
* | ||
* Copyright © 2019-2023 The Galette Team | ||
* | ||
* This file is part of Galette (http://galette.tuxfamily.org). | ||
* | ||
* Galette is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Galette is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Galette. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* @category Entity | ||
* @package GaletteTests | ||
* | ||
* @author Johan Cwiklinski <johan@x-tnd.be> | ||
* @copyright 2019-2023 The Galette Team | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version | ||
* @version SVN: $Id$ | ||
* @link http://galette.tuxfamily.org | ||
* @since 2019-05-08 | ||
*/ | ||
|
||
namespace Galette\Entity\test\units; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Laminas\Db\Adapter\Adapter; | ||
|
||
/** | ||
* Saved search tests | ||
* | ||
* @category Entity | ||
* @name SavedSearch | ||
* @package GaletteTests | ||
* @author Johan Cwiklinski <johan@x-tnd.be> | ||
* @copyright 2019-2023 The Galette Team | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version | ||
* @link http://galette.tuxfamily.org | ||
* @since 2019-05-08 | ||
*/ | ||
class SavedSearch extends TestCase | ||
{ | ||
private \Galette\Core\Db $zdb; | ||
private \Galette\Core\I18n $i18n; | ||
private \Galette\Core\Login $login; | ||
|
||
/** | ||
* Set up tests | ||
* | ||
* @return void | ||
*/ | ||
public function setUp(): void | ||
{ | ||
$this->zdb = new \Galette\Core\Db(); | ||
$this->i18n = new \Galette\Core\I18n(); | ||
|
||
$this->login = $this->getMockBuilder(\Galette\Core\Login::class) | ||
->setConstructorArgs(array($this->zdb, new \Galette\Core\I18n())) | ||
->onlyMethods(array('isLogged', 'isSuperAdmin', '__get')) | ||
->getMock(); | ||
$this->login->method('isLogged')->willReturn(true); | ||
$this->login->method('isSuperAdmin')->willReturn(true); | ||
$this->login->method('__get')->willReturn(0); | ||
} | ||
|
||
/** | ||
* Tear down tests | ||
* | ||
* @return void | ||
*/ | ||
public function tearDown(): void | ||
{ | ||
if (TYPE_DB === 'mysql') { | ||
$this->assertSame([], $this->zdb->getWarnings()); | ||
} | ||
$this->deleteCreated(); | ||
} | ||
|
||
/** | ||
* Delete status | ||
* | ||
* @return void | ||
*/ | ||
private function deleteCreated() | ||
{ | ||
$this->zdb->db->query( | ||
'TRUNCATE TABLE ' . PREFIX_DB . \Galette\Entity\SavedSearch::TABLE, | ||
\Laminas\Db\Adapter\Adapter::QUERY_MODE_EXECUTE | ||
); | ||
} | ||
|
||
/** | ||
* Test saved search | ||
* | ||
* @return void | ||
*/ | ||
public function testSave() | ||
{ | ||
global $i18n, $translator; // globals :( | ||
$i18n = $this->i18n; | ||
$i18n->changeLanguage('en_US'); | ||
|
||
$saved = new \Galette\Entity\SavedSearch($this->zdb, $this->login); | ||
$searches = new \Galette\Repository\SavedSearches($this->zdb, $this->login); | ||
|
||
$post = [ | ||
'parameters' => [ | ||
'filter_str' => '', | ||
'field_filter' => 0, | ||
'membership_filter' => 0, | ||
'filter_account' => 0, | ||
'roup_filter' => 0, | ||
'email_filter' => 5, | ||
'nbshow' => 10 | ||
], | ||
'form' => 'Adherent', | ||
'name' => 'Simple search' | ||
]; | ||
|
||
$errored = $post; | ||
unset($errored['form']); | ||
$this->assertFalse($saved->check($errored)); | ||
$this->assertSame(['form' => 'Form is mandatory!'], $saved->getErrors()); | ||
|
||
//store search | ||
$this->assertTrue($saved->check($post)); | ||
$this->assertTrue($saved->store()); | ||
$this->assertCount(1, $searches->getList(true)); | ||
//store again, got a duplicate | ||
$this->assertTrue($saved->store()); | ||
$this->assertCount(2, $searches->getList(true)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
<?php | ||
|
||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | ||
|
||
/** | ||
* Socials tests | ||
* | ||
* PHP version 5 | ||
* | ||
* Copyright © 2021-2023 The Galette Team | ||
* | ||
* This file is part of Galette (http://galette.tuxfamily.org). | ||
* | ||
* Galette is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Galette is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Galette. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* @category Entity | ||
* @package GaletteTests | ||
* | ||
* @author Johan Cwiklinski <johan@x-tnd.be> | ||
* @copyright 2019-2023 The Galette Team | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version | ||
* @version SVN: $Id$ | ||
* @link http://galette.tuxfamily.org | ||
* @since 2021-10-26 | ||
*/ | ||
|
||
namespace Galette\Entity\test\units; | ||
|
||
use Galette\GaletteTestCase; | ||
|
||
/** | ||
* Status tests | ||
* | ||
* @category Entity | ||
* @name Social | ||
* @package GaletteTests | ||
* @author Johan Cwiklinski <johan@x-tnd.be> | ||
* @copyright 2021-2023 The Galette Team | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version | ||
* @link http://galette.tuxfamily.org | ||
* @since 2021-10-26 | ||
*/ | ||
class Social extends GaletteTestCase | ||
{ | ||
protected int $seed = 25568744158; | ||
|
||
/** | ||
* Tear down tests | ||
* | ||
* @return void | ||
*/ | ||
public function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
|
||
$this->deleteSocials(); | ||
|
||
//drop dynamic translations | ||
$delete = $this->zdb->delete(\Galette\Core\L10n::TABLE); | ||
$this->zdb->execute($delete); | ||
|
||
$delete = $this->zdb->delete(\Galette\Entity\Adherent::TABLE); | ||
$delete->where(['fingerprint' => 'FAKER' . $this->seed]); | ||
$this->zdb->execute($delete); | ||
|
||
$this->cleanHistory(); | ||
} | ||
|
||
/** | ||
* Delete socials | ||
* | ||
* @return void | ||
*/ | ||
private function deleteSocials() | ||
{ | ||
$delete = $this->zdb->delete(\Galette\Entity\Social::TABLE); | ||
$this->zdb->execute($delete); | ||
} | ||
|
||
/** | ||
* Test social object | ||
* | ||
* @return void | ||
*/ | ||
public function testObject() | ||
{ | ||
$social = new \Galette\Entity\Social($this->zdb); | ||
|
||
//setters and getters | ||
$this->assertInstanceOf(\Galette\Entity\Social::class, $social->setType('mytype')); | ||
$this->assertSame('mytype', $social->type); | ||
|
||
$this->assertInstanceOf(\Galette\Entity\Social::class, $social->setUrl('myurl')); | ||
$this->assertSame('myurl', $social->url); | ||
|
||
//null as member id for Galette main preferences | ||
$this->assertInstanceOf(\Galette\Entity\Social::class, $social->setLinkedMember(null)); | ||
$this->assertNull($social->id_adh); | ||
$this->assertNull($social->member); | ||
|
||
$this->getMemberTwo(); | ||
$this->assertInstanceOf(\Galette\Entity\Social::class, $social->setLinkedMember($this->adh->id)); | ||
$this->assertSame($this->adh->id, $social->id_adh); | ||
$this->assertInstanceOf(\Galette\Entity\Adherent::class, $social->member); | ||
$this->assertSame($this->adh->name, $social->member->name); | ||
} | ||
|
||
/** | ||
* Test socials "system" types | ||
* | ||
* @return void | ||
*/ | ||
public function testGetSystemTypes() | ||
{ | ||
$social = new \Galette\Entity\Social($this->zdb); | ||
$this->assertCount(9, $social->getSystemTypes()); | ||
$this->assertSame($social->getSystemTypes(true), $social->getSystemTypes()); | ||
$this->assertCount(9, $social->getSystemTypes(false)); | ||
|
||
$this->assertSame('Twitter', $social->getSystemType(\Galette\Entity\Social::TWITTER)); | ||
$this->assertSame('twitter', $social->getSystemType(\Galette\Entity\Social::TWITTER, false)); | ||
} | ||
|
||
/** | ||
* Test getListForMember | ||
* | ||
* @return void | ||
*/ | ||
public function testGetListForMember(): void | ||
{ | ||
$this->assertEmpty(\Galette\Entity\Social::getListForMember(null)); | ||
|
||
$this->getMemberTwo(); | ||
$this->assertEmpty(\Galette\Entity\Social::getListForMember($this->adh->id)); | ||
|
||
$social = new \Galette\Entity\Social($this->zdb); | ||
$this->assertTrue( | ||
$social | ||
->setType(\Galette\Entity\Social::MASTODON) | ||
->setUrl('mastodon URL') | ||
->setLinkedMember($this->adh->id) | ||
->store() | ||
); | ||
|
||
$socials = \Galette\Entity\Social::getListForMember($this->adh->id); | ||
$this->assertCount(1, $socials); | ||
$social = array_pop($socials); | ||
$this->assertSame(\Galette\Entity\Social::MASTODON, $social->type); | ||
$this->assertSame($this->adh->id, $social->id_adh); | ||
$this->assertSame('mastodon URL', $social->url); | ||
|
||
$social = new \Galette\Entity\Social($this->zdb); | ||
$this->assertTrue( | ||
$social | ||
->setType(\Galette\Entity\Social::MASTODON) | ||
->setUrl('Galette mastodon URL') | ||
->setLinkedMember(null) | ||
->store() | ||
); | ||
|
||
$social = new \Galette\Entity\Social($this->zdb); | ||
$this->assertTrue( | ||
$social | ||
->setType(\Galette\Entity\Social::JABBER) | ||
->setUrl('Galette jabber') | ||
->setLinkedMember(null) | ||
->store() | ||
); | ||
|
||
$social = new \Galette\Entity\Social($this->zdb); | ||
$this->assertTrue( | ||
$social | ||
->setType(\Galette\Entity\Social::MASTODON) | ||
->setUrl('Another Galette mastodon URL') | ||
->setLinkedMember(null) | ||
->store() | ||
); | ||
|
||
$this->assertCount(3, \Galette\Entity\Social::getListForMember(null)); | ||
$this->assertCount(1, \Galette\Entity\Social::getListForMember(null, \Galette\Entity\Social::JABBER)); | ||
|
||
$this->assertTrue($social->remove()); | ||
$this->assertCount(2, \Galette\Entity\Social::getListForMember(null)); | ||
} | ||
} |
Oops, something went wrong.