function test_comparisonOfAggreagtorResults() { $result = tx_caretaker_AggregatorResult::create(tx_caretaker_Constants::state_undefined); $compareResult = tx_caretaker_AggregatorResult::create(tx_caretaker_Constants::state_undefined); $this->assertTrue($result->equals($compareResult), 'two empty undefined results should be equal'); $compareResult = tx_caretaker_AggregatorResult::create(tx_caretaker_Constants::state_ok); $this->assertTrue($result->isDifferent($compareResult), 'result with other state is not equal'); $compareResult = tx_caretaker_AggregatorResult::create(tx_caretaker_Constants::state_undefined, 0, 0, 0, 0); $this->assertTrue($result->equals($compareResult), 'result with state undefined and all errorNumbers 0 is equal to empty result'); $compareResult = tx_caretaker_AggregatorResult::create(tx_caretaker_Constants::state_undefined, 1, 0, 0, 0); $this->assertFalse($result->equals($compareResult), 'result with state undefined and but numUndefined = 1 is not equal to empty result'); $compareResult = tx_caretaker_AggregatorResult::create(tx_caretaker_Constants::state_undefined, 0, 1, 0, 0); $this->assertFalse($result->equals($compareResult), 'result with state undefined and but numOK = 1 is not equal to empty result'); $compareResult = tx_caretaker_AggregatorResult::create(tx_caretaker_Constants::state_undefined, 0, 0, 1, 0); $this->assertFalse($result->equals($compareResult), 'result with state undefined and but numWarning = 1 is not equal to empty result'); $compareResult = tx_caretaker_AggregatorResult::create(tx_caretaker_Constants::state_undefined, 0, 0, 0, 1); $this->assertFalse($result->equals($compareResult), 'result with state undefined and but numError = 1 is not equal to empty result'); }
/** * Aggregate Child-Testresults * * @param array<tx_caretaker_NodeResult> $test_results Child-Results to aggregate * @return tx_caretaker_AggregatorResult Aggregated State */ protected function getAggregatedResult($test_results) { $num_tests = count($test_results); $num_undefined = 0; $num_ok = 0; $num_warnings = 0; $num_errors = 0; $num_due = 0; $num_ack = 0; $childnode_titles_undefined = array(); $childnode_titles_ok = array(); $childnode_titles_warning = array(); $childnode_titles_error = array(); $childnode_titles_ack = array(); $childnode_titles_due = array(); if (is_array($test_results)) { foreach ($test_results as $test_result) { /** @var tx_caretaker_NodeResult $result */ $result = $test_result['result']; /** @var tx_caretaker_AbstractNode $node */ $node = $test_result['node']; switch ($result->getState()) { default: case tx_caretaker_Constants::state_undefined: $num_undefined++; $childnode_titles_undefined[] = $node->getTitle(); break; case tx_caretaker_Constants::state_ack: $num_ack++; $num_undefined++; $childnode_titles_ack[] = $node->getTitle(); break; case tx_caretaker_Constants::state_due: $num_due++; $num_undefined++; $childnode_titles_due[] = $node->getTitle(); break; case tx_caretaker_Constants::state_ok: $num_ok++; $childnode_titles_ok[] = $node->getTitle(); break; case tx_caretaker_Constants::state_warning: $num_warnings++; $childnode_titles_warning[] = $node->getTitle(); break; case tx_caretaker_Constants::state_error: $num_errors++; $childnode_titles_error[] = $node->getTitle(); break; } } } $values = array('num_tests' => $num_tests, 'num_ok' => $num_ok, 'num_warning' => $num_warnings, 'num_error' => $num_errors, 'num_undefined' => $num_undefined, 'num_ack' => $num_undefined, 'num_due' => $num_undefined); $message = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:aggregator_result_message', $values); // create Submessages $submessages = array(); if ($num_errors > 0) { foreach ($childnode_titles_error as $childTitle) { $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:aggregator_result_submessage_error', array('title' => $childTitle)); } } if ($num_warnings > 0) { foreach ($childnode_titles_warning as $childTitle) { $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:aggregator_result_submessage_warning', array('title' => $childTitle)); } } if ($num_undefined > 0) { foreach ($childnode_titles_undefined as $childTitle) { $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:aggregator_result_submessage_undefined', array('title' => $childTitle)); } } if ($num_ack > 0) { foreach ($childnode_titles_ack as $childTitle) { $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:aggregator_result_submessage_ack', array('title' => $childTitle)); } } if ($num_due > 0) { foreach ($childnode_titles_due as $childTitle) { $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:aggregator_result_submessage_due', array('title' => $childTitle)); } } if ($num_errors > 0) { return tx_caretaker_AggregatorResult::create(tx_caretaker_Constants::state_error, $num_undefined, $num_ok, $num_warnings, $num_errors, $message, $submessages); } else { if ($num_warnings > 0) { return tx_caretaker_AggregatorResult::create(tx_caretaker_Constants::state_warning, $num_undefined, $num_ok, $num_warnings, $num_errors, $message, $submessages); } else { if ($num_undefined == $num_tests) { return tx_caretaker_AggregatorResult::create(tx_caretaker_Constants::state_undefined, $num_undefined, $num_ok, $num_warnings, $num_errors, $message, $submessages); } else { return tx_caretaker_AggregatorResult::create(tx_caretaker_Constants::state_ok, $num_undefined, $num_ok, $num_warnings, $num_errors, $message, $submessages); } } } }