[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / components / testing_framework / core / Functional / Framework / Constraint / RequestSection / StructureDoesNotHaveRecordConstraint.php
1 <?php
2 namespace TYPO3\CMS\Components\TestingFramework\Core\Functional\Framework\Constraint\RequestSection;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Components\TestingFramework\Core\Functional\Framework\Frontend\ResponseSection;
18
19 /**
20 * Model of frontend response
21 */
22 class StructureDoesNotHaveRecordConstraint extends AbstractStructureRecordConstraint
23 {
24 /**
25 * @param ResponseSection $responseSection
26 * @return bool
27 */
28 protected function matchesSection(ResponseSection $responseSection)
29 {
30 $matchingVariants = [];
31
32 foreach ($responseSection->findStructures($this->recordIdentifier, $this->recordField) as $path => $structure) {
33 if (empty($structure) || !is_array($structure)) {
34 $this->sectionFailures[$responseSection->getIdentifier()] = 'No records found in "' . $path . '"';
35 return false;
36 }
37
38 $nonMatchingValues = $this->getNonMatchingValues($structure);
39 $matchingValues = array_diff($this->values, $nonMatchingValues);
40
41 if (!empty($matchingValues)) {
42 $matchingVariants[$path] = $matchingValues;
43 }
44 }
45
46 if (empty($matchingVariants)) {
47 return true;
48 }
49
50 $matchingMessage = '';
51 foreach ($matchingVariants as $path => $matchingValues) {
52 $matchingMessage .= ' * Found in "' . $path . '": ' . implode(', ', $matchingValues);
53 }
54
55 $this->sectionFailures[$responseSection->getIdentifier()] = 'Could not assert not having values for "' . $this->table . '.' . $this->field . '"' . LF . $matchingMessage;
56 return false;
57 }
58
59 /**
60 * Returns a string representation of the constraint.
61 *
62 * @return string
63 */
64 public function toString()
65 {
66 return 'structure does not have record';
67 }
68 }