Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
## [1.2.0] - 2026-07-28

### Add

Expand Down
5 changes: 5 additions & 0 deletions advancedforms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
<author>Teclib'</author>
</authors>
<versions>
<version>
<num>1.2.0</num>
<compatibility>~11.0.0</compatibility>
<download_url>https://github.com/pluginsGLPI/advancedforms/releases/download/1.2.0/glpi-advancedforms-1.2.0.tar.bz2</download_url>
</version>
<version>
<num>1.1.1</num>
<compatibility>~11.0.0</compatibility>
Expand Down
42 changes: 20 additions & 22 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,26 @@
* -------------------------------------------------------------------------
*/

use Rector\Configuration\RectorConfigBuilder;

require_once __DIR__ . '/../../src/Plugin.php';

use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\Config\RectorConfig;
use Rector\ValueObject\PhpVersion;
$baseline_file = __DIR__ . '/../../PluginsRector.php';
if (!file_exists($baseline_file)) {
throw new RuntimeException(
sprintf(
'Unable to find "%s". Running rector on a plugin requires a GLPI development checkout that ships PluginsRector.php.',
$baseline_file,
),
);
}

$baseline = require $baseline_file;

/** @var RectorConfigBuilder $config */
$config = $baseline([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
])
->withPhpVersion(PhpVersion::PHP_82)
->withCache(
cacheDirectory: __DIR__ . '/var/rector',
cacheClass: FileCacheStorage::class,
)
->withRootFiles()
->withParallel(timeoutSeconds: 300)
->withImportNames(removeUnusedImports: true)
->withPreparedSets(
deadCode: true,
codeQuality: true,
codingStyle: true,
)
->withPhpSets(php82: true) // apply PHP sets up to PHP 8.2
;
return $config;
2 changes: 1 addition & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
use GlpiPlugin\Advancedforms\Service\InitManager;

/** @phpstan-ignore theCodingMachineSafe.function (safe to assume this isn't already defined) */
define('PLUGIN_ADVANCEDFORMS_VERSION', '1.1.1');
define('PLUGIN_ADVANCEDFORMS_VERSION', '1.2.0');

// Minimal GLPI version, inclusive
/** @phpstan-ignore theCodingMachineSafe.function (safe to assume this isn't already defined) */
Expand Down
8 changes: 3 additions & 5 deletions tests/AdvancedFormsTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ public function setUp(): void
]);
}

public function tearDown(): void
{
parent::tearDown();
}

protected function enableConfigurableItem(
ConfigurableItemInterface|string $item,
): void {
Expand All @@ -91,6 +86,7 @@ protected function enableConfigurableItems(
foreach ($items as $item) {
$this->setConfigurableItemConfig($item, true);
}

InitManager::getInstance()->init();
}

Expand All @@ -108,6 +104,7 @@ protected function disableConfigurableItems(
foreach ($items as $item) {
$this->setConfigurableItemConfig($item, false);
}

InitManager::getInstance()->init();
}

Expand Down Expand Up @@ -169,6 +166,7 @@ private function deleteSingletonInstance(array $classes)
$reflection_property = $reflection_class->getProperty('instance');
$reflection_property->setValue(null, null);
}

if ($reflection_class->hasProperty('_instances')) {
$reflection_property = $reflection_class->getProperty('_instances');
$reflection_property->setValue(null, []);
Expand Down
9 changes: 6 additions & 3 deletions tests/Front/FrontTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public function get(string $url, array $params = []): Crawler
$_SERVER['REQUEST_URI'] = GLPI_ROOT . $url;
require(GLPI_ROOT . $url);
$html = ob_get_clean();
} catch (Throwable $e) {
} catch (Throwable $throwable) {
$_GET = $old_GET;
ob_get_clean();
throw $e;
throw $throwable;
} finally {
$_GET = $old_GET;
}
Expand Down Expand Up @@ -129,17 +129,20 @@ public function sendForm(
if (count($submits) > 1) {
throw new RuntimeException("Only forms with a single submit are supported");
}

$submit = $submits->getNode(0);
if (!$submit instanceof DOMElement) {
throw new LogicException(); // Impossible
}

$payload[$submit->getAttribute('name')] = $submit->getAttribute('value');

// Insert specified payload values
foreach ($form_values as $key => $value) {
if (!isset($payload[$key])) {
throw new RuntimeException("Input '$key' does not exist");
throw new RuntimeException(sprintf("Input '%s' does not exist", $key));
}

$payload[$key] = $value;
}

Expand Down
7 changes: 4 additions & 3 deletions tests/Helpers/NetworkHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@

namespace GlpiPlugin\Advancedforms\Tests\Helpers;

use Generator;
use GlpiPlugin\Advancedforms\Helpers\NetworkHelper;
use GlpiPlugin\Advancedforms\Tests\AdvancedFormsTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

final class NetworkHelperTest extends AdvancedFormsTestCase
{
public static function getRemoteIpAddressProvider(): \Generator
public static function getRemoteIpAddressProvider(): Generator
{
// Test X-Forwarded-For header with single IP (highest priority)
yield 'X-Forwarded-For with single IP' => [
Expand Down Expand Up @@ -126,13 +127,13 @@ public function testGetIPAddress(

// Setup environment
if ($http_x_forwarded_for !== '') {
putenv("HTTP_X_FORWARDED_FOR={$http_x_forwarded_for}");
putenv('HTTP_X_FORWARDED_FOR=' . $http_x_forwarded_for);
} else {
putenv("HTTP_X_FORWARDED_FOR=");
}

if ($remote_addr_env !== '') {
putenv("REMOTE_ADDR={$remote_addr_env}");
putenv('REMOTE_ADDR=' . $remote_addr_env);
} else {
putenv("REMOTE_ADDR=");
}
Expand Down
5 changes: 3 additions & 2 deletions tests/Model/Mapper/FormcreatorHiddenTypeMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

namespace GlpiPlugin\Advancedforms\Tests\Model\Mapper;

use DBmysql;
use Glpi\Form\AccessControl\FormAccessControlManager;
use Glpi\Form\Migration\FormMigration;
use Glpi\Form\Question;
Expand All @@ -43,7 +44,7 @@ final class FormcreatorHiddenTypeMapperTest extends MapperTestCase
{
public function testHiddenTypeMigrationWhenEnabled(): void
{
/** @var \DBmysql $DB */
/** @var DBmysql $DB */
global $DB;

// Arrange: enable ip question type and add some fomrcreator data
Expand Down Expand Up @@ -81,7 +82,7 @@ public function testHiddenTypeMigrationWhenEnabled(): void

public function testHiddenTypeMigrationWhenDisabled(): void
{
/** @var \DBmysql $DB */
/** @var DBmysql $DB */
global $DB;

// Arrange: add some fomrcreator data
Expand Down
5 changes: 3 additions & 2 deletions tests/Model/Mapper/FormcreatorHostnameTypeMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

namespace GlpiPlugin\Advancedforms\Tests\Model\Mapper;

use DBmysql;
use Glpi\Form\AccessControl\FormAccessControlManager;
use Glpi\Form\Migration\FormMigration;
use Glpi\Form\Question;
Expand All @@ -43,7 +44,7 @@ final class FormcreatorHostnameTypeMapperTest extends MapperTestCase
{
public function testHostnameTypeMigrationWhenEnabled(): void
{
/** @var \DBmysql $DB */
/** @var DBmysql $DB */
global $DB;

// Arrange: enable ip question type and add some fomrcreator data
Expand Down Expand Up @@ -71,7 +72,7 @@ public function testHostnameTypeMigrationWhenEnabled(): void

public function testHostnameTypeMigrationWhenDisabled(): void
{
/** @var \DBmysql $DB */
/** @var DBmysql $DB */
global $DB;

// Arrange: add some fomrcreator data
Expand Down
5 changes: 3 additions & 2 deletions tests/Model/Mapper/FormcreatorIpTypeMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

namespace GlpiPlugin\Advancedforms\Tests\Model\Mapper;

use DBmysql;
use Glpi\Form\AccessControl\FormAccessControlManager;
use Glpi\Form\Migration\FormMigration;
use Glpi\Form\Question;
Expand All @@ -43,7 +44,7 @@ final class FormcreatorIpTypeMapperTest extends MapperTestCase
{
public function testIpTypeMigrationWhenEnabled(): void
{
/** @var \DBmysql $DB */
/** @var DBmysql $DB */
global $DB;

// Arrange: enable ip question type and add some fomrcreator data
Expand Down Expand Up @@ -71,7 +72,7 @@ public function testIpTypeMigrationWhenEnabled(): void

public function testIpTypeMigrationWhenDisabled(): void
{
/** @var \DBmysql $DB */
/** @var DBmysql $DB */
global $DB;

// Arrange: add some fomrcreator data
Expand Down
8 changes: 5 additions & 3 deletions tests/Model/Mapper/FormcreatorLdapSelectTypeMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

namespace GlpiPlugin\Advancedforms\Tests\Model\Mapper;

use DBmysql;
use AuthLDAP;
use Glpi\Form\AccessControl\FormAccessControlManager;
use Glpi\Form\Migration\FormMigration;
Expand All @@ -46,7 +47,7 @@ final class FormcreatorLdapSelectTypeMapperTest extends MapperTestCase
{
public function testLdapSelectTypeMigrationWhenEnabledWithValidAuthLDAP(): void
{
/** @var \DBmysql $DB */
/** @var DBmysql $DB */
global $DB;

// Arrange: create a valid AuthLDAP
Expand All @@ -73,7 +74,7 @@ public function testLdapSelectTypeMigrationWhenEnabledWithInvalidAuthLDAP(): voi

private function testLdapSelectTypeMigrationWhenEnabled(int $authldap_id, ?int $expected_authldap_id): void
{
/** @var \DBmysql $DB */
/** @var DBmysql $DB */
global $DB;

// Arrange: enable ldap select question type and add some formcreator data
Expand Down Expand Up @@ -107,6 +108,7 @@ private function testLdapSelectTypeMigrationWhenEnabled(int $authldap_id, ?int $
if (!$config instanceof LdapQuestionConfig) {
throw new LogicException();
}

$this->assertEquals($expected_authldap_id ?? $authldap_id, $config->getAuthLdapId());
$this->assertEquals(456, $config->getLdapAttributeId());
$this->assertEquals(
Expand All @@ -117,7 +119,7 @@ private function testLdapSelectTypeMigrationWhenEnabled(int $authldap_id, ?int $

public function testLdapSelectTypeMigrationWhenDisabled(): void
{
/** @var \DBmysql $DB */
/** @var DBmysql $DB */
global $DB;

// Arrange: add some formcreator data
Expand Down
2 changes: 2 additions & 0 deletions tests/Model/QuestionType/QuestionTypeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ final public function testQuestionIsAvailableInTypeDropdownWhenEnabled(): void

$builder = new FormBuilder("My form");
$builder->addQuestion("My question", QuestionTypeShortText::class);

$form = $this->createForm($builder);

// Act: render form editor
Expand All @@ -108,6 +109,7 @@ final public function testQuestionIsNotAvailableInTypeDropdownWhenDisabled(): vo
// Arrange: create a form
$builder = new FormBuilder("My form");
$builder->addQuestion("My question", QuestionTypeShortText::class);

$form = $this->createForm($builder);

// Act: render form editor
Expand Down
8 changes: 5 additions & 3 deletions tests/Model/QuestionType/TableQuestionConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

namespace GlpiPlugin\Advancedforms\Tests\Model\QuestionType;

use Glpi\Form\QuestionType\QuestionTypeShortText;
use Glpi\Form\QuestionType\QuestionTypeNumber;
use GlpiPlugin\Advancedforms\Model\QuestionType\TableQuestionConfig;
use GlpiPlugin\Advancedforms\Tests\AdvancedFormsTestCase;

Expand All @@ -50,8 +52,8 @@ public function testJsonRoundtrip(): void
{
$original = new TableQuestionConfig(
columns: [
['name' => 'Source IP', 'question_type' => 'Glpi\\Form\\QuestionType\\QuestionTypeShortText', 'required' => true, 'itemtype' => '', 'pattern' => '/^172\\.23\\./'],
['name' => 'Port', 'question_type' => 'Glpi\\Form\\QuestionType\\QuestionTypeNumber', 'required' => false, 'itemtype' => '', 'pattern' => ''],
['name' => 'Source IP', 'question_type' => QuestionTypeShortText::class, 'required' => true, 'itemtype' => '', 'pattern' => '/^172\\.23\\./'],
['name' => 'Port', 'question_type' => QuestionTypeNumber::class, 'required' => false, 'itemtype' => '', 'pattern' => ''],
],
min_rows: 2,
max_rows: 20,
Expand All @@ -67,7 +69,7 @@ public function testColumnPatternDefaultsToEmptyStringWhenAbsent(): void
{
$config = TableQuestionConfig::jsonDeserialize([
'columns' => [
['name' => 'Source IP', 'question_type' => 'Glpi\\Form\\QuestionType\\QuestionTypeShortText', 'required' => true],
['name' => 'Source IP', 'question_type' => QuestionTypeShortText::class, 'required' => true],
],
]);

Expand Down
2 changes: 1 addition & 1 deletion tests/Model/QuestionType/TableQuestionIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function getTestedQuestionType(): QuestionTypeInterface&ConfigurableIt
}

#[Override]
protected function getDefaultExtraDataForQuestionType(QuestionTypeInterface $type): ?string
protected function getDefaultExtraDataForQuestionType(QuestionTypeInterface $type): string
{
return json_encode(new TableQuestionConfig(
columns: [
Expand Down
2 changes: 1 addition & 1 deletion tests/Model/QuestionType/TableQuestionValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function testRequiredValidationCoversEveryCompatibleColumnType(): void

$this->assertFalse(
$result->isValid(),
"Required validation should fail for column type {$fqcn}",
'Required validation should fail for column type ' . $fqcn,
);
}
}
Expand Down
Loading