TYPO3 CMS  TYPO3_7-6
StructureHasRecordConstraint.php
Go to the documentation of this file.
1 <?php
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 
18 
23 {
28  protected function matchesSection(ResponseSection $responseSection)
29  {
30  $nonMatchingVariants = [];
31  $remainingRecordVariants = [];
32 
33  foreach ($responseSection->findStructures($this->recordIdentifier, $this->recordField) as $path => $structure) {
34  if (empty($structure) || !is_array($structure)) {
35  $this->sectionFailures[$responseSection->getIdentifier()] = 'No records found in "' . $path . '"';
36  return false;
37  }
38 
39  $remainingRecords = [];
40  $nonMatchingValues = $this->getNonMatchingValues($structure);
41 
42  if ($this->strict) {
43  $remainingRecords = $this->getRemainingRecords($structure);
44  }
45 
46  if (empty($nonMatchingValues) && (!$this->strict || empty($remainingRecords))) {
47  return true;
48  }
49 
50  if (!empty($nonMatchingValues)) {
51  $nonMatchingVariants[$path] = $nonMatchingValues;
52  }
53  if ($this->strict && !empty($remainingRecords)) {
54  $remainingRecordVariants[$path] = $remainingRecords;
55  }
56  }
57 
58  $failureMessage = '';
59 
60  if (!empty($nonMatchingVariants)) {
61  $failureMessage .= 'Could not assert all values for "' . $this->table . '.' . $this->field . '"' . LF;
62  foreach ($nonMatchingVariants as $path => $nonMatchingValues) {
63  $failureMessage .= ' * Not found in "' . $path . '": ' . implode(', ', $nonMatchingValues) . LF;
64  }
65  }
66 
67  if (!empty($remainingRecordVariants)) {
68  $failureMessage .= 'Found remaining records for "' . $this->table . '.' . $this->field . '"' . LF;
69  foreach ($remainingRecordVariants as $path => $remainingRecords) {
70  $failureMessage .= ' * Found in "' . $path . '": ' . implode(', ', array_keys($remainingRecords)) . LF;
71  }
72  }
73 
74  $this->sectionFailures[$responseSection->getIdentifier()] = $failureMessage;
75  return false;
76  }
77 
83  public function toString()
84  {
85  return 'structure has record';
86  }
87 }