mirror of
https://github.com/opnsense/core.git
synced 2026-02-19 02:28:59 -05:00
tests: fix tests broken by #9744
The static option list caching mechanism is now invoked over a nonexistant config.xm; caching no interfaces for the "*" static options key. In order to fix that add a reset for the list. Would be nicer to move reset to BaseListField since a number of fields use the static option list for caching but they all define their own.
This commit is contained in:
parent
49d573691f
commit
870692c154
3 changed files with 21 additions and 12 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015-2019 Deciso B.V.
|
||||
* Copyright (C) 2015-2026 Deciso B.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -40,12 +40,12 @@ class InterfaceField extends BaseListField
|
|||
/**
|
||||
* @var array collected options
|
||||
*/
|
||||
private static $internalStaticOptionList = array();
|
||||
private static $internalStaticOptionList = [];
|
||||
|
||||
/**
|
||||
* @var array filters to use on the interface list
|
||||
*/
|
||||
private $internalFilters = array();
|
||||
private $internalFilters = [];
|
||||
|
||||
/**
|
||||
* @var string key to use for option selections, to prevent excessive reloading
|
||||
|
|
@ -68,14 +68,14 @@ class InterfaceField extends BaseListField
|
|||
*/
|
||||
private function getConfigLaggInterfaces()
|
||||
{
|
||||
$physicalInterfaces = array();
|
||||
$physicalInterfaces = [];
|
||||
$configObj = Config::getInstance()->object();
|
||||
if (!empty($configObj->laggs)) {
|
||||
foreach ($configObj->laggs->children() as $key => $lagg) {
|
||||
if (!empty($lagg->members)) {
|
||||
foreach (explode(',', $lagg->members) as $interface) {
|
||||
if (!isset($physicalInterfaces[$interface])) {
|
||||
$physicalInterfaces[$interface] = array();
|
||||
$physicalInterfaces[$interface] = [];
|
||||
}
|
||||
$physicalInterfaces[$interface][] = (string)$lagg->laggif;
|
||||
}
|
||||
|
|
@ -91,12 +91,12 @@ class InterfaceField extends BaseListField
|
|||
*/
|
||||
private function getConfigVLANInterfaces()
|
||||
{
|
||||
$physicalInterfaces = array();
|
||||
$physicalInterfaces = [];
|
||||
$configObj = Config::getInstance()->object();
|
||||
if (!empty($configObj->vlans)) {
|
||||
foreach ($configObj->vlans->children() as $key => $vlan) {
|
||||
if (!isset($physicalInterfaces[(string)$vlan->if])) {
|
||||
$physicalInterfaces[(string)$vlan->if] = array();
|
||||
$physicalInterfaces[(string)$vlan->if] = [];
|
||||
}
|
||||
$physicalInterfaces[(string)$vlan->if][] = (string)$vlan->vlanif;
|
||||
}
|
||||
|
|
@ -110,10 +110,10 @@ class InterfaceField extends BaseListField
|
|||
protected function actionPostLoadingEvent()
|
||||
{
|
||||
if (!isset(self::$internalStaticOptionList[$this->internalCacheKey])) {
|
||||
self::$internalStaticOptionList[$this->internalCacheKey] = array();
|
||||
self::$internalStaticOptionList[$this->internalCacheKey] = [];
|
||||
|
||||
$allInterfaces = array();
|
||||
$allInterfacesDevices = array(); // mapping device -> interface handle (lan/wan/optX)
|
||||
$allInterfaces = [];
|
||||
$allInterfacesDevices = []; // mapping device -> interface handle (lan/wan/optX)
|
||||
$configObj = Config::getInstance()->object();
|
||||
// Iterate over all interfaces configuration and collect data
|
||||
if (isset($configObj->interfaces) && $configObj->interfaces->count() > 0) {
|
||||
|
|
@ -235,4 +235,12 @@ class InterfaceField extends BaseListField
|
|||
}
|
||||
$this->updateInternalCacheKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* purging state for testing because caching is too persistent
|
||||
*/
|
||||
public function resetStaticOptionList()
|
||||
{
|
||||
self::$internalStaticOptionList = [];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,5 +95,4 @@ class FilterRuleTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$this->assertEquals(join('', $rules), $this->getConf(__FUNCTION__));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,9 @@ class InterfaceFieldTest extends Field_Framework_TestCase
|
|||
*/
|
||||
public function testCanBeCreated()
|
||||
{
|
||||
$this->assertInstanceOf('\OPNsense\Base\FieldTypes\InterfaceField', new InterfaceField());
|
||||
$field = new InterfaceField();
|
||||
$field->resetStaticOptionList();
|
||||
$this->assertInstanceOf('\OPNsense\Base\FieldTypes\InterfaceField', $field);
|
||||
// switch config to test set for this type
|
||||
(new AppConfig())->update('application.configDir', __DIR__ . '/InterfaceFieldTest');
|
||||
Config::getInstance()->forceReload();
|
||||
|
|
|
|||
Loading…
Reference in a new issue