Skip to content

Commit

Permalink
Migrate class
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Mar 17, 2023
1 parent d92c10d commit 9430578
Show file tree
Hide file tree
Showing 18 changed files with 605 additions and 0 deletions.
240 changes: 240 additions & 0 deletions phpunit/Galette/Core/tests/units/Plugins.php
@@ -0,0 +1,240 @@
<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
* Plugins tests
*
* PHP version 5
*
* Copyright © 2013-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 Core
* @package GaletteTests
*
* @author Johan Cwiklinski <johan@x-tnd.be>
* @copyright 2013-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 2013-01-13
*/

namespace Galette\Core\test\units;

use PHPUnit\Framework\TestCase;

/**
* Plugins tests class
*
* @category Core
* @name Plugins
* @package GaletteTests
* @author Johan Cwiklinski <johan@x-tnd.be>
* @copyright 2013-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 2013-01-13
*/
class Plugins extends TestCase
{
private \Galette\Core\Db $zdb;
private \Galette\Core\Preferences $preferences;
private \Galette\Core\Plugins $plugins;

private array $plugin2 = array(
'root' => 'plugin-test2',
'name' => 'Galette Test2 Plugin',
'desc' => 'Test two plugin',
'author' => 'Johan Cwiklinski',
'version' => '1.0',
'acls' => [
'plugin2_root' => 'member',
'plugin2_admin' => 'staff'
],
'date' => '2013-12-15',
'priority' => 1000,
'root_writable' => true,
'route' => 'plugin2'
);

/**
* Get instanciated plugins instance
*
* @return Galette\Core\Plugins
*/
private function getPlugins()
{
$plugins = new \Galette\Core\Plugins();
$plugins->autoload(GALETTE_PLUGINS_PATH);
$plugins->loadModules($this->preferences, GALETTE_PLUGINS_PATH);
return $plugins;
}

/**
* Set up tests
*
* @return void
*/
public function setUp(): void
{
$this->zdb = new \Galette\Core\Db();
$this->preferences = new \Galette\Core\Preferences($this->zdb);

$this->plugins = $this->getPlugins();

$this->plugin2['root'] = GALETTE_PLUGINS_PATH .
$this->plugin2['root'];
}

/**
* Tear down tests
*
* @return void
*/
public function tearDown(): void
{
if (TYPE_DB === 'mysql') {
$this->assertSame([], $this->zdb->getWarnings());
}
}

/**
* Tests plugins load
*
* @return void
*/
public function testLoadModules()
{
$plugins = $this->getPlugins();
$this->assertCount(3, $this->plugins->getModules());

$loaded_plugin = $this->plugins->getModules('plugin-test2');
$loaded_plugin['date'] = $this->plugin2['date'];

$this->assertSame($this->plugin2, $loaded_plugin);
}

/**
* Test module existence
*
* @return void
*/
public function testModuleExists()
{
$this->assertTrue($this->plugins->moduleExists('plugin-test2'));
$this->assertFalse($this->plugins->moduleExists('plugin-disabled'));
}

/**
* Test disabled plugin
*
* @return void
*/
public function testDisabledModules()
{
$disabled_modules = $this->plugins->getDisabledModules();
$this->assertTrue(isset($disabled_modules['plugin-disabled']));
$this->assertTrue(isset($disabled_modules['plugin-unversionned']));
$this->assertTrue(isset($disabled_modules['plugin-oldversion']));
}

/**
* Test module root
*
* @return void
*/
public function testModuleRoot()
{
$this->assertSame($this->plugin2['root'], $this->plugins->moduleRoot('plugin-test2'));
}

/**
* Test templates path
*
* @return void
*/
/*public function testGetTemplatesPath()
{
//FIXME:
// - at the moment, there is no config for preferences, so default theme is empty
// - remove global $preferences to have this one working as expected...
$this->variable($this->plugins->getTemplatesPath('plugin-test2'))
->isIdenticalTo($this->plugin2['root'] . '/templates/');
}*/

/**
* Test reset modules list
*
* @return void
*/
public function testResetModulesList()
{
$this->plugins->resetModulesList();

$this->assertEmpty($this->plugins->getModules());
}

/**
* Test plugin (des)activation
*
* @return void
*/
public function testModuleActivation()
{
$plugins = $this->getPlugins();
$modules = $plugins->getModules();
$this->assertCount(3, $modules);
$this->assertTrue(isset($modules['plugin-test2']));
$plugins->deactivateModule('plugin-test2');

$plugins = $this->getPlugins();
$modules = $plugins->getModules();
$this->assertCount(2, $modules);
$this->assertFalse(isset($module['plugin-test2']));
$plugins->activateModule('plugin-test2');

$plugins = $this->getPlugins();
$modules = $plugins->getModules();
$this->assertCount(3, $modules);
$this->assertTrue(isset($modules['plugin-test2']));

$plugins = $this->getPlugins();
$this->expectExceptionMessage(_T('No such module.'));
$plugins->deactivateModule('nonexistant');

$plugins = $this->getPlugins();
$this->expectExceptionMessage(_T('No such module.'));
$plugins->activateModule('nonexistant');
}

/**
* Test if plugin needs database
*
* @return void
*/
public function testNeedDatabse()
{
$this->assertTrue($this->plugins->needsDatabase('plugin-db'));
$this->assertFalse($this->plugins->needsDatabase('plugin-test2'));

$plugins = $this->getPlugins();
$this->expectExceptionMessage(_T('Module does not exists!'));
$plugins->needsDatabase('nonexistant');
}
}
50 changes: 50 additions & 0 deletions phpunit/plugins/plugin-db/_define.php
@@ -0,0 +1,50 @@
<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
* Configuration file for db plugin
*
* PHP version 5
*
* Copyright © 2013-2014 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 Plugins
* @package GaletteTests
*
* @author Johan Cwiklinski <johan@x-tnd.be>
* @copyright 2013-2014 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 2013-01-15
*/

$this->register(
'Galette Db Plugin', //Name
'Test db plugin', //Short description
'Johan Cwiklinski', //Author
'1.0', //Version
GALETTE_COMPAT_VERSION, //Galette compatible version
'plugdb', //routing name
'2015-01-30', //release date
[ //Permissions needed
'plugdb_root' => 'member',
'plugdb_admin' => 'staff'
]
);
Empty file.
7 changes: 7 additions & 0 deletions phpunit/plugins/plugin-db/scripts/mysql.sql
@@ -0,0 +1,7 @@
DROP TABLE IF EXISTS galette_logs;
CREATE TABLE galette_logs (
id int(10) unsigned NOT NULL auto_increment,
date_log datetime NOT NULL,
comment text,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
16 changes: 16 additions & 0 deletions phpunit/plugins/plugin-db/scripts/pgsql.sql
@@ -0,0 +1,16 @@
DROP SEQUENCE IF EXISTS galette_db_test_id_seq;
CREATE SEQUENCE galette_db_test_id_seq
START 1
INCREMENT 1
MAXVALUE 2147483647
MINVALUE 1
CACHE 1;

DROP TABLE IF EXISTS galette_db_test;
CREATE TABLE galette_db_test (
id integer DEFAULT nextval('galette_db_test_id_seq'::text) NOT NULL,
date_log timestamp NOT NULL,
comment text,
PRIMARY KEY (id)
);

49 changes: 49 additions & 0 deletions phpunit/plugins/plugin-disabled/_define.php
@@ -0,0 +1,49 @@
<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
* Configuration file for disabled test plugin
*
* PHP version 5
*
* Copyright © 2013-2014 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 Plugins
* @package GaletteAdminTools
*
* @author Johan Cwiklinski <johan@x-tnd.be>
* @copyright 2013-2014 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 2013-01-14
*/

$this->register(
'Galette Disabled Plugin', //Name
'Test disabled plugin', //Short description
'Johan Cwiklinski', //Author
'1.0', //Version
GALETTE_COMPAT_VERSION, //Galette compatible version
'plugdis', //routing name
'2016-10-19', //Release date
[ //Permissions needed
'plugdis_root' => 'admin'
]
);
Empty file.
Empty file.

0 comments on commit 9430578

Please sign in to comment.