mvc: CertificateField: same as 870692c154

It's time to create a ticket for generalisation because now
resetStaticOptionList() is declared in two places also hinting
at a shared functionality in BaseListField.
This commit is contained in:
Franco Fichtner 2026-02-18 11:59:02 +01:00
parent 18c3f1187f
commit 104d5f02f8
3 changed files with 34 additions and 24 deletions

View file

@ -89,4 +89,12 @@ class CertificateField extends BaseListField
}
$this->internalOptionList = self::$internalStaticOptionList[$this->certificateType];
}
/**
* purging state for testing because caching is too persistent
*/
public function resetStaticOptionList()
{
self::$internalStaticOptionList = [];
}
}

View file

@ -1,31 +1,29 @@
<?php
/**
* Copyright (C) 2019 Deciso B.V.
/*
* Copyright (C) 2019 Deciso B.V.
* All rights reserved.
*
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
namespace tests\OPNsense\Base\FieldTypes;
@ -45,7 +43,10 @@ class CertificateFieldTest extends Field_Framework_TestCase
*/
public function testCanBeCreated()
{
$this->assertInstanceOf('\OPNsense\Base\FieldTypes\CertificateField', new CertificateField());
$field = new CertificateField();
$this->assertInstanceOf('\OPNsense\Base\FieldTypes\CertificateField', $field);
$field->resetStaticOptionList();
// switch config to test set for this type
(new AppConfig())->update('application.configDir', __DIR__ . '/CertificateFieldTest');
Config::getInstance()->forceReload();

View file

@ -46,8 +46,9 @@ class InterfaceFieldTest extends Field_Framework_TestCase
public function testCanBeCreated()
{
$field = new InterfaceField();
$field->resetStaticOptionList();
$this->assertInstanceOf('\OPNsense\Base\FieldTypes\InterfaceField', $field);
$field->resetStaticOptionList();
// switch config to test set for this type
(new AppConfig())->update('application.configDir', __DIR__ . '/InterfaceFieldTest');
Config::getInstance()->forceReload();