20204207070442f2a27fc212c34d1000ddff5f40
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / Framework / Constraint / RequestSection / StructureDoesNotHaveRecordConstraint.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional\Framework\Constraint\RequestSection;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2014 Oliver Hader <oliver.hader@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 use TYPO3\CMS\Core\Tests\Functional\Framework\Frontend\ResponseSection;
28
29 /**
30 * Model of frontend response
31 */
32 class StructureDoesNotHaveRecordConstraint extends AbstractStructureRecordConstraint {
33
34 /**
35 * @param ResponseSection $responseSection
36 * @return bool
37 */
38 protected function matchesSection(ResponseSection $responseSection) {
39 $matchingVariants = array();
40
41 foreach ($responseSection->findStructures($this->recordIdentifier, $this->recordField) as $path => $structure) {
42 if (empty($structure) || !is_array($structure)) {
43 $this->sectionFailures[$responseSection->getIdentifier()] = 'No records found in "' . $path . '"';
44 return FALSE;
45 }
46
47 $nonMatchingValues = $this->getNonMatchingValues($structure);
48 $matchingValues = array_diff($this->values, $nonMatchingValues);
49
50 if (!empty($matchingValues)) {
51 $matchingVariants[$path] = $matchingValues;
52 }
53 }
54
55 if (empty($matchingVariants)) {
56 return TRUE;
57 }
58
59 $matchingMessage = '';
60 foreach ($matchingVariants as $path => $matchingValues) {
61 $matchingMessage .= ' * Found in "' . $path . '": ' . implode(', ', $matchingValues);
62 }
63
64 $this->sectionFailures[$responseSection->getIdentifier()] = 'Could not assert not having values for "' . $this->table . '.' . $this->field . '"' . LF . $matchingMessage;
65 return FALSE;
66 }
67
68 /**
69 * Returns a string representation of the constraint.
70 *
71 * @return string
72 */
73 public function toString() {
74 return 'structure does not have record';
75 }
76
77 }