mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Make sure expectations work.
This commit is contained in:
@@ -11,12 +11,14 @@ use RuntimeException;
|
||||
*/
|
||||
class TestConfiguration
|
||||
{
|
||||
protected const MAX_ITERATIONS = 3;
|
||||
public const SHOW_DEBUG = false;
|
||||
public array $ignores;
|
||||
public array $mandatoryFieldSets;
|
||||
public array $optionalFieldSets;
|
||||
public array $parameters;
|
||||
private array $expected;
|
||||
private array $submission;
|
||||
protected const MAX_ITERATIONS = 3;
|
||||
public array $ignores;
|
||||
public array $parameters;
|
||||
|
||||
/**
|
||||
* TestConfiguration constructor.
|
||||
@@ -28,6 +30,7 @@ class TestConfiguration
|
||||
$this->optionalFieldSets = [];
|
||||
$this->ignores = [];
|
||||
$this->parameters = [];
|
||||
$this->expected = [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,157 +46,40 @@ class TestConfiguration
|
||||
$this->optionalFieldSets[$key] = $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $submissions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function generateIgnores(array $submissions): array
|
||||
public function generateAll(): array
|
||||
{
|
||||
$ignores = [];
|
||||
// loop each submission and find its expected return and create
|
||||
// a return array with the expected values.
|
||||
/** @var array $submission */
|
||||
foreach ($submissions as $index => $submission) {
|
||||
$ignores[$index] = [];
|
||||
// loop each field and use the "name" to find it.
|
||||
/**
|
||||
* @var string $fieldName
|
||||
* @var string $fieldValue
|
||||
*/
|
||||
foreach ($submission as $fieldTitle => $fieldValue) {
|
||||
//echo "Now searching for field $fieldTitle on index $index.\n";
|
||||
$fieldObject = $this->findField($fieldTitle);
|
||||
if (null !== $fieldObject) {
|
||||
if (0 !== count($fieldObject->ignorableFields)) {
|
||||
/** @var string $ignorableField */
|
||||
foreach ($fieldObject->ignorableFields as $ignorableField) {
|
||||
// explode and put in the right position:
|
||||
$positions = explode('/', $ignorableField);
|
||||
if (1 === count($positions)) {
|
||||
$ignores[$index][$ignorableField] = true;
|
||||
}
|
||||
if (3 === count($positions)) {
|
||||
$root = $positions[0];
|
||||
$index = (int)$positions[1];
|
||||
$final = $positions[2];
|
||||
$ignores[$index][$root][$index][$final] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (null === $fieldObject) {
|
||||
die('null field object :(');
|
||||
}
|
||||
}
|
||||
$this->debugMsg('Now in generateAll()');
|
||||
// generate submissions
|
||||
$array = $this->generateSubmissions();
|
||||
//$expected = $this->generateExpected($array);
|
||||
$parameters = $this->parameters;
|
||||
$ignored = $this->ignores;
|
||||
$expected = $this->expected;
|
||||
|
||||
// now create a combination for each submission and associated data:
|
||||
$final = [];
|
||||
foreach ($array as $index => $submission) {
|
||||
$final[] = [[
|
||||
'submission' => $submission,
|
||||
'expected' => $expected[$index] ?? $submission,
|
||||
'ignore' => $ignored[$index] ?? [],
|
||||
'parameters' => $parameters[$index] ?? [],
|
||||
]];
|
||||
}
|
||||
|
||||
return $ignores;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
* @param string $title
|
||||
*
|
||||
* @return Field|null
|
||||
*/
|
||||
private function findField(string $title): ?Field
|
||||
{
|
||||
// since there is no index for optional field sets (they use ID)
|
||||
// reverse the set and loop them all:
|
||||
// reason we reverse them is because the last always overrules the first.
|
||||
$reversed = array_reverse($this->optionalFieldSets);
|
||||
foreach ($reversed as $fieldSet) {
|
||||
foreach ($fieldSet->fields as $field) {
|
||||
if ($title === $field->fieldTitle) {
|
||||
//echo " found field $title in an optional field set.\n";
|
||||
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
}
|
||||
$reversed = array_reverse($this->mandatoryFieldSets);
|
||||
foreach ($reversed as $fieldSet) {
|
||||
foreach ($fieldSet->fields as $field) {
|
||||
if ($title === $field->fieldTitle) {
|
||||
//echo " found field $title in a mandatory field set.\n";
|
||||
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $submissions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function generateExpected(array $submissions): array
|
||||
{
|
||||
$returns = [];
|
||||
// loop each submission and find its expected return and create
|
||||
// a return array with the expected values.
|
||||
/** @var array $submission */
|
||||
foreach ($submissions as $index => $submission) {
|
||||
$returns[$index] = [];
|
||||
// loop each field and use the "name" to find it.
|
||||
/**
|
||||
* @var string $fieldName
|
||||
* @var string $fieldValue
|
||||
*/
|
||||
foreach ($submission as $fieldTitle => $fieldValue) {
|
||||
//echo "Now searching for field $fieldTitle on index $index.\n";
|
||||
$fieldObject = $this->findField($fieldTitle);
|
||||
if (null !== $fieldObject) {
|
||||
if (null === $fieldObject->expectedReturn) {
|
||||
$returns[$index][$fieldTitle] = $submissions[$index][$fieldTitle];
|
||||
}
|
||||
if (null !== $fieldObject->expectedReturn) {
|
||||
die('cannot handle closure');
|
||||
}
|
||||
}
|
||||
if (null === $fieldObject) {
|
||||
die('null field object :(');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $returns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FieldSet $set
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function toArray(FieldSet $set): array
|
||||
{
|
||||
$ignore = [];
|
||||
$result = [];
|
||||
/** @var Field $field */
|
||||
foreach ($set->fields as $field) {
|
||||
$result = $this->parseField($result, $field);
|
||||
$ignore = array_unique($ignore + $field->ignorableFields);
|
||||
}
|
||||
$this->ignores[] = $ignore;
|
||||
$this->parameters[] = $set->parameters ?? [];
|
||||
|
||||
return $result;
|
||||
return $final;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function generateSubmissions(): array
|
||||
private function generateSubmissions(): array
|
||||
{
|
||||
$this->debugMsg('Now in generateSubmissions()');
|
||||
// first generate standard submissions:
|
||||
$this->submission = [];
|
||||
|
||||
// loop each standard submission:
|
||||
$this->debugMsg(sprintf('There are %d mandatory field sets', count($this->mandatoryFieldSets)));
|
||||
/** @var FieldSet $set */
|
||||
foreach ($this->mandatoryFieldSets as $set) {
|
||||
$this->submission[] = $this->toArray($set);
|
||||
@@ -234,31 +120,34 @@ class TestConfiguration
|
||||
// of the submission in the array
|
||||
$index = count($this->submission) - 1;
|
||||
$this->updateIgnorables($index, $customFields);
|
||||
$this->updateExpected($index, $customFields);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
// no mandatory sets? Loop the optional sets:
|
||||
if (0 === count($this->mandatoryFieldSets)) {
|
||||
// expand the standard submission with extra sets from the optional field set.
|
||||
$setCount = count($this->optionalFieldSets);
|
||||
// echo "there are " . $setCount . " optional sets\n";
|
||||
$this->debugMsg(sprintf('there are %d optional field sets', $setCount));
|
||||
if (0 !== $setCount) {
|
||||
$keys = array_keys($this->optionalFieldSets);
|
||||
// echo " keys to consider are: " . join(', ', $keys) . "\n";
|
||||
$this->debugMsg(sprintf(' keys to consider are: %s', join(', ', $keys)));
|
||||
$maxCount = count($keys) > self::MAX_ITERATIONS ? self::MAX_ITERATIONS : count($keys);
|
||||
// echo " max count is " . $maxCount . "\n";
|
||||
$this->debugMsg(sprintf(' max count is %d', $maxCount));
|
||||
for ($i = 1; $i <= $maxCount; $i++) {
|
||||
$combinationSets = $this->combinationsOf($i, $keys);
|
||||
// echo " will create " . count($combinationSets) . " extra sets.\n";
|
||||
$this->debugMsg(sprintf(' will create %d extra sets.', count($combinationSets)));
|
||||
foreach ($combinationSets as $ii => $combinationSet) {
|
||||
// echo " Set " . ($ii + 1) . "/" . count($combinationSets) . " will consist of:\n";
|
||||
$totalCount++;
|
||||
$this->debugMsg(sprintf(' Set #%d will consist of:', $totalCount));
|
||||
// the custom set is born!
|
||||
//$custom = $this->toArray($set);
|
||||
$custom = [];
|
||||
$custom = [];
|
||||
$expected = [];
|
||||
foreach ($combinationSet as $combination) {
|
||||
// echo " $combination\n";
|
||||
$this->debugMsg(sprintf(' %s', $combination));
|
||||
// here we start adding stuff to a copy of the standard submission.
|
||||
/** @var FieldSet $customSet */
|
||||
$customSet = $this->optionalFieldSets[$combination] ?? false;
|
||||
@@ -266,74 +155,63 @@ class TestConfiguration
|
||||
// loop each field in this custom set and add them, nothing more.
|
||||
/** @var Field $field */
|
||||
foreach ($customSet->fields as $field) {
|
||||
// echo " added field " . $field->fieldTitle . " from custom set " . $combination . "\n";
|
||||
$custom = $this->parseField($custom, $field);
|
||||
$this->debugMsg(sprintf(' added field %s from custom set %s', $field->fieldTitle, $combination));
|
||||
$custom = $this->parseField($custom, $field);
|
||||
$expected = $this->parseExpected($expected, $field, $custom);
|
||||
// for each field, add the ignores to the current index (+1!) of
|
||||
// ignores.
|
||||
$count = count($this->submission);
|
||||
if (null !== $field->ignorableFields && count($field->ignorableFields) > 0) {
|
||||
$count = count($this->submission);
|
||||
$currentIgnoreSet = $this->ignores[$count] ?? [];
|
||||
$this->ignores[$count] = array_unique(array_values(array_merge($currentIgnoreSet, $field->ignorableFields)));
|
||||
$this->ignores[$count] = array_values(array_unique(array_values(array_merge($currentIgnoreSet, $field->ignorableFields))));
|
||||
}
|
||||
$this->expected[$count] = $expected;
|
||||
}
|
||||
$count = count($this->submission);
|
||||
$this->parameters[$count] = $customSet->parameters ?? [];
|
||||
}
|
||||
$count = count($this->submission);
|
||||
$this->submission[] = $custom;
|
||||
$this->debugMsg(sprintf(' Created set #%d', $totalCount));
|
||||
$this->debugMsg(sprintf(' Will submit: %s', json_encode($custom)));
|
||||
$this->debugMsg(sprintf(' Will ignore: %s', json_encode($this->ignores[$count] ?? [])));
|
||||
$this->debugMsg(sprintf(' Will expect: %s', json_encode($this->expected[$count] ?? [])));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->debugMsg('Done!');
|
||||
|
||||
return $this->submission;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
* @param array $customFields
|
||||
*/
|
||||
function updateIgnorables(int $index, array $customFields): void
|
||||
{
|
||||
if (count($customFields) > 0) {
|
||||
/** @var Field $field */
|
||||
foreach ($customFields as $field) {
|
||||
if (0 !== count($field->ignorableFields)) {
|
||||
$this->ignores[$index] = array_unique(array_values(array_merge($this->ignores[$index], $field->ignorableFields)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $submissions
|
||||
* @param FieldSet $set
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function generateParameters(array $submissions): array
|
||||
private function toArray(FieldSet $set): array
|
||||
{
|
||||
$params = [];
|
||||
$index = 0;
|
||||
/** @var array $submission */
|
||||
foreach ($submissions as $submission) {
|
||||
// last one defined param
|
||||
$submission = array_reverse($submission);
|
||||
foreach ($submission as $key => $value) {
|
||||
if (array_key_exists($key, $this->optionalFieldSets)) {
|
||||
/** @var FieldSet $fieldSet */
|
||||
$fieldSet = $this->optionalFieldSets[$key];
|
||||
if (null !== $fieldSet->parameters) {
|
||||
$params[$index] = $fieldSet->parameters;
|
||||
continue;
|
||||
}
|
||||
if (null !== $fieldSet->parameters) {
|
||||
$params[$index] = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
$ignore = [];
|
||||
$result = [];
|
||||
$expected = [];
|
||||
/** @var Field $field */
|
||||
foreach ($set->fields as $field) {
|
||||
// this is what we will submit:
|
||||
$result = $this->parseField($result, $field);
|
||||
$expected = $this->parseExpected($expected, $field, $result);
|
||||
|
||||
return $params;
|
||||
// this is what we will ignore:
|
||||
$newIgnore = array_unique($ignore + $field->ignorableFields);
|
||||
$ignore = $newIgnore;
|
||||
$this->debugMsg(sprintf('Merged! ignores %s + %s = %s', json_encode($ignore), json_encode($field->ignorableFields), json_encode($newIgnore)));
|
||||
|
||||
}
|
||||
$this->ignores[] = array_values($ignore);
|
||||
$this->expected[] = $expected;
|
||||
$this->parameters[] = $set->parameters ?? [];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -403,6 +281,8 @@ class TestConfiguration
|
||||
return $faker->randomFloat(2, 1, 99);
|
||||
case 'random-interest-period':
|
||||
return $faker->randomElement(['daily', 'monthly', 'yearly']);
|
||||
case 'random-bill-repeat-freq':
|
||||
return $faker->randomElement(['half-year', 'weekly', 'monthly', 'yearly']);
|
||||
case 'random-past-date':
|
||||
return $faker->dateTimeBetween('-3 years', '-1 years')->format('Y-m-d');
|
||||
case 'random-date-two-year':
|
||||
@@ -436,9 +316,69 @@ class TestConfiguration
|
||||
return null;
|
||||
case 'random-attachment-type':
|
||||
return $faker->randomElement(['Account', 'Budget', 'Bill', 'TransactionJournal', 'PiggyBank', 'Tag',]);
|
||||
case 'random-amount-min':
|
||||
return number_format($faker->randomFloat(2, 10, 50), 2);
|
||||
case 'random-amount-max':
|
||||
return number_format($faker->randomFloat(2, 50, 100), 2);
|
||||
case 'random-skip':
|
||||
return $faker->numberBetween(0, 4);
|
||||
case 'random-og-id':
|
||||
return $faker->numberBetween(1, 2);
|
||||
case 'random-auto-type':
|
||||
return $faker->randomElement(['rollover', 'reset']);
|
||||
case 'random-auto-period':
|
||||
return $faker->randomElement(['weekly', 'monthly', 'yearly']);
|
||||
case 'static-auto-none':
|
||||
return 'none';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $expected
|
||||
* @param Field $field
|
||||
* @param array $result
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function parseExpected(array $expected, Field $field, array $result): array
|
||||
{
|
||||
// fieldTitle indicates the position:
|
||||
$positions = explode('/', $field->fieldTitle);
|
||||
$count = count($positions);
|
||||
|
||||
if (1 === $count && null === $field->expectedReturn) {
|
||||
$expected[$field->fieldTitle] = $result[$field->fieldTitle];
|
||||
$this->debugMsg(sprintf(' Expected result of field "%s" = "%s"', $field->fieldTitle, $expected[$field->fieldTitle]));
|
||||
|
||||
return $expected;
|
||||
}
|
||||
if (1 === $count && null !== $field->expectedReturn) {
|
||||
// call the closure!
|
||||
$expected[$field->fieldTitle] = ($field->expectedReturn)($result[$field->fieldTitle]);
|
||||
|
||||
return $expected;
|
||||
}
|
||||
|
||||
if (3 === $count) {
|
||||
$root = $positions[0];
|
||||
$count = (int)$positions[1];
|
||||
$final = $positions[2];
|
||||
$expected[$root] = array_key_exists($root, $expected) ? $expected[$root] : [];
|
||||
$expected[$root][$count] = array_key_exists($count, $expected[$root]) ? $expected[$root][$count] : [];
|
||||
$expected[$root][$count][$final] = null;
|
||||
|
||||
if (null === $field->expectedReturn) {
|
||||
$expected[$root][$count][$final] = $result[$root][$count][$final] ?? false;
|
||||
}
|
||||
if (null !== $field->expectedReturn) {
|
||||
$expected[$root][$count][$final] = ($field->expectedReturn)($result[$root][$count][$final] ?? false);
|
||||
}
|
||||
|
||||
return $expected;
|
||||
}
|
||||
throw new RuntimeException(sprintf('Did not expect count %d from fieldTitle "%s".', $count, $field->fieldTitle));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $k
|
||||
* @param $xs
|
||||
@@ -464,6 +404,122 @@ class TestConfiguration
|
||||
return array_merge($res1, $res2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
* @param array $customFields
|
||||
*/
|
||||
function updateIgnorables(int $index, array $customFields): void
|
||||
{
|
||||
if (count($customFields) > 0) {
|
||||
/** @var Field $field */
|
||||
foreach ($customFields as $field) {
|
||||
if (0 !== count($field->ignorableFields)) {
|
||||
$this->ignores[$index] = array_values(array_unique(array_values(array_merge($this->ignores[$index], $field->ignorableFields))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
* @param array $customFields
|
||||
*/
|
||||
function updateExpected(int $index, array $customFields): void
|
||||
{
|
||||
if (count($customFields) > 0) {
|
||||
/** @var Field $field */
|
||||
foreach ($customFields as $field) {
|
||||
if (null === $field->expectedReturn) {
|
||||
$this->expected[$index][$field->fieldTitle] = $this->submission[$index][$field->fieldTitle];
|
||||
}
|
||||
if (null !== $field->expectedReturn) {
|
||||
$this->expected[$index][$field->fieldTitle] = ($field->expectedReturn)($this->submission[$index][$field->fieldTitle]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $submissions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function generateIgnores(array $submissions): array
|
||||
{
|
||||
$ignores = [];
|
||||
// loop each submission and find its expected return and create
|
||||
// a return array with the expected values.
|
||||
/** @var array $submission */
|
||||
foreach ($submissions as $index => $submission) {
|
||||
$ignores[$index] = [];
|
||||
// loop each field and use the "name" to find it.
|
||||
/**
|
||||
* @var string $fieldName
|
||||
* @var string $fieldValue
|
||||
*/
|
||||
foreach ($submission as $fieldTitle => $fieldValue) {
|
||||
//echo "Now searching for field $fieldTitle on index $index.\n";
|
||||
$fieldObject = $this->findField($fieldTitle);
|
||||
if (null !== $fieldObject) {
|
||||
if (0 !== count($fieldObject->ignorableFields)) {
|
||||
/** @var string $ignorableField */
|
||||
foreach ($fieldObject->ignorableFields as $ignorableField) {
|
||||
// explode and put in the right position:
|
||||
$positions = explode('/', $ignorableField);
|
||||
if (1 === count($positions)) {
|
||||
$ignores[$index][$ignorableField] = true;
|
||||
}
|
||||
if (3 === count($positions)) {
|
||||
$root = $positions[0];
|
||||
$index = (int)$positions[1];
|
||||
$final = $positions[2];
|
||||
$ignores[$index][$root][$index][$final] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (null === $fieldObject) {
|
||||
die('null field object :(');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ignores;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $submissions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function generateParameters(array $submissions): array
|
||||
{
|
||||
$params = [];
|
||||
$index = 0;
|
||||
/** @var array $submission */
|
||||
foreach ($submissions as $submission) {
|
||||
// last one defined param
|
||||
$submission = array_reverse($submission);
|
||||
foreach ($submission as $key => $value) {
|
||||
if (array_key_exists($key, $this->optionalFieldSets)) {
|
||||
/** @var FieldSet $fieldSet */
|
||||
$fieldSet = $this->optionalFieldSets[$key];
|
||||
if (null !== $fieldSet->parameters) {
|
||||
$params[$index] = $fieldSet->parameters;
|
||||
continue;
|
||||
}
|
||||
if (null !== $fieldSet->parameters) {
|
||||
$params[$index] = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FieldSet $optionalFieldSet
|
||||
*/
|
||||
@@ -472,6 +528,90 @@ class TestConfiguration
|
||||
$this->optionalFieldSet = $optionalFieldSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
*/
|
||||
private function debugMsg(string $message): void
|
||||
{
|
||||
if (true === self::SHOW_DEBUG) {
|
||||
echo sprintf("%s\n", $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $submissions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function generateExpected(array $submissions): array
|
||||
{
|
||||
$returns = [];
|
||||
// loop each submission and find its expected return and create
|
||||
// a return array with the expected values.
|
||||
/** @var array $submission */
|
||||
foreach ($submissions as $index => $submission) {
|
||||
$returns[$index] = [];
|
||||
// loop each field and use the "name" to find it.
|
||||
/**
|
||||
* @var string $fieldName
|
||||
* @var string $fieldValue
|
||||
*/
|
||||
foreach ($submission as $fieldTitle => $fieldValue) {
|
||||
//echo "Now searching for field $fieldTitle on index $index.\n";
|
||||
$fieldObject = $this->findField($fieldTitle);
|
||||
if (null !== $fieldObject) {
|
||||
if (null === $fieldObject->expectedReturn) {
|
||||
$returns[$index][$fieldTitle] = $submissions[$index][$fieldTitle];
|
||||
}
|
||||
if (null !== $fieldObject->expectedReturn) {
|
||||
$returns[$index][$fieldTitle] = 'hi there';//($fieldObject->expectedReturn)($submissions[$index][$fieldTitle]);
|
||||
}
|
||||
}
|
||||
if (null === $fieldObject) {
|
||||
die('null field object :(');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $returns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
* @param string $title
|
||||
*
|
||||
* @return Field|null
|
||||
*/
|
||||
private function findField(string $title): ?Field
|
||||
{
|
||||
// since there is no index for optional field sets (they use ID)
|
||||
// reverse the set and loop them all:
|
||||
// reason we reverse them is because the last always overrules the first.
|
||||
$reversed = array_reverse($this->optionalFieldSets);
|
||||
foreach ($reversed as $fieldSet) {
|
||||
foreach ($fieldSet->fields as $field) {
|
||||
if ($title === $field->fieldTitle) {
|
||||
//echo " found field $title in an optional field set.\n";
|
||||
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
}
|
||||
$reversed = array_reverse($this->mandatoryFieldSets);
|
||||
foreach ($reversed as $fieldSet) {
|
||||
foreach ($fieldSet->fields as $field) {
|
||||
if ($title === $field->fieldTitle) {
|
||||
//echo " found field $title in a mandatory field set.\n";
|
||||
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $existing
|
||||
* @param array $config
|
||||
|
Reference in New Issue
Block a user