[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / components / testing_framework / core / Functional / Framework / Constraint / RequestSection / DoesNotHaveRecordConstraint.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 DoesNotHaveRecordConstraint extends AbstractRecordConstraint
23 {
24 /**
25 * @param ResponseSection $responseSection
26 * @return bool
27 */
28 protected function matchesSection(ResponseSection $responseSection)
29 {
30 $records = $responseSection->getRecords();
31
32 if (empty($records) || !is_array($records)) {
33 $this->sectionFailures[$responseSection->getIdentifier()] = 'No records found.';
34 return false;
35 }
36
37 $nonMatchingValues = $this->getNonMatchingValues($records);
38 $matchingValues = array_diff($this->values, $nonMatchingValues);
39
40 if (!empty($matchingValues)) {
41 $this->sectionFailures[$responseSection->getIdentifier()] = 'Could not assert not having values for "' . $this->table . '.' . $this->field . '": ' . implode(', ', $matchingValues);
42 return false;
43 }
44
45 return true;
46 }
47
48 /**
49 * Returns a string representation of the constraint.
50 *
51 * @return string
52 */
53 public function toString()
54 {
55 return 'response does not have record';
56 }
57 }