Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased](https://github.com/orca-services/cakephp-data-validation-testing)

### Added
- `testDataValidationNotContains()` to assert that specific validation rules are absent, ignoring others on the same field.
- `testDataValidationInListContains()` and `testDataValidationInListNotContains()` list helpers.
- Optional custom `$expected` parameter for `testDataValidationForeignKey()` and `testDataValidationIsUnique()`.

### Changed
- **BREAKING CHANGE:** All type-specific/rule-dedicated methods now assert only their own validation rule for the field, ignoring others.

### Fixed
- Ignore dataValidation in `testDataValidationIsUnique()` to correctly assert build rules.

### Dependencies

Expand Down
44 changes: 26 additions & 18 deletions docs/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,31 @@ Each helper builds an entity, runs the validator, and asserts the expected error

## Available methods

> **Note:** The presence, emptiness and type helpers listed below are rule-dedicated: each one only asserts that
> its own validation rule is (or is not) configured for the given field and ignores any other validation errors
> present on that field. They no longer compare against the field's full error list.

### Presence and emptiness

- `testDataValidationRequired($table, $fieldName)` - field must be present.
- `testDataValidationNotRequired($table, $fieldName)` - field is optional.
- `testDataValidationNotEmpty($table, $fieldName)` - field cannot be `null` or `''`.
- `testDataValidationEmpty($table, $fieldName)` - field may be `null` or `''`.
- `testDataValidationRequired($table, $fieldName)` - asserts the field is configured to require presence (`_required`).
- `testDataValidationNotRequired($table, $fieldName)` - asserts the field is not configured to require presence.
- `testDataValidationNotEmpty($table, $fieldName)` - asserts the field is configured to disallow empty values, i.e. `null` or `''` (`_empty`).
- `testDataValidationEmpty($table, $fieldName)` - asserts the field is configured to allow empty values, i.e. `null` or `''`.

### Type validators

- `testDataValidationBoolean($table, $fieldName)` - field must be boolean.
- `testDataValidationURLWithProtocol($table, $fieldName)` - requires `http://` or `https://`.
- `testDataValidationDateTime($table, $fieldName)` - field must be datetime.
- `testDataValidationDate($table, $fieldName)` - field must be date.
- `testDataValidationNaturalNumber($table, $fieldName)` - positive integers only.
- `testDataValidationScalar($table, $fieldName)` - rejects non-scalar values like arrays.
- `testDataValidationDecimal($table, $fieldName)` - rejects non-decimal values like arrays.
- `testDataValidationInteger($table, $fieldName)` - rejects non-integer values like arrays.
- `testDataValidationNonNegativeInteger($table, $fieldName)` - rejects negative integer values like `-1`.
- `testDataValidationGreaterThanOrEqual($table, $fieldName)` - rejects values below the threshold.
- `testDataValidationEmail($table, $fieldName)` - rejects invalid email addresses.
- `testDataValidationUuid($table, $fieldName)` - rejects invalid UUIDs.
- `testDataValidationBoolean($table, $fieldName)` - asserts the field is configured with the `boolean` validation rule.
- `testDataValidationURLWithProtocol($table, $fieldName)` - asserts the field is configured with the `urlWithProtocol` validation rule (requires `http://` or `https://`).
- `testDataValidationDateTime($table, $fieldName)` - asserts the field is configured with the `dateTime` validation rule.
- `testDataValidationDate($table, $fieldName)` - asserts the field is configured with the `date` validation rule.
- `testDataValidationNaturalNumber($table, $fieldName)` - asserts the field is configured with the `naturalNumber` validation rule (positive integers).
- `testDataValidationScalar($table, $fieldName)` - asserts the field is configured with the `scalar` validation rule.
- `testDataValidationDecimal($table, $fieldName)` - asserts the field is configured with the `decimal` validation rule.
- `testDataValidationInteger($table, $fieldName)` - asserts the field is configured with the `integer` validation rule.
- `testDataValidationNonNegativeInteger($table, $fieldName)` - asserts the field is configured with the `nonNegativeInteger` validation rule.
- `testDataValidationGreaterThanOrEqual($table, $fieldName, $threshold)` - asserts the field is configured with the `greaterThanOrEqual` validation rule.
- `testDataValidationEmail($table, $fieldName)` - asserts the field is configured with the `email` validation rule.
- `testDataValidationUuid($table, $fieldName)` - asserts the field is configured with the `uuid` validation rule.

### Length validators

Expand All @@ -83,9 +87,13 @@ Each helper builds an entity, runs the validator, and asserts the expected error

### Generic helpers

- `testDataValidation($table, $fieldName, $dataSet, $expected)` - the underlying helper. Use when no specialized helper fits.
- `testDataValidation($table, $fieldName, $dataSet, $expected)` - the underlying helper. Use when no specialized helper fits. Compares the field's **complete** error array against `$expected`.
- `testDataValidationContains($table, $fieldName, $dataSet, $expected)` - asserts the given `"rule name" => "message"` pairs are present on the field, ignoring any other errors.
- `testDataValidationNotContains($table, $fieldName, $dataSet, $rules)` - asserts the given rule names are **not** present on the field, ignoring any other errors.
- `testDataValidationNoErrors($table, $fieldName, $dataSet)` - asserts a data set produces no errors on the field.
- `testDataValidationInList($table, $list, $fieldName, $expected)` - runs the same assertion for each value in a list.
- `testDataValidationInList($table, $list, $fieldName, $expected)` - runs the complete-error-array assertion for each value in a list.
- `testDataValidationInListContains($table, $list, $fieldName, $expected)` - runs the `contains` assertion for each value in a list.
- `testDataValidationInListNotContains($table, $list, $fieldName, $rules)` - runs the `not contains` assertion for each value in a list.
- `testFullDataValidation($table, $dataSet, $expected)` - asserts errors across all fields.
- `testFullDataValidationNoErrors($table, $dataSet)` - asserts a full data set produces no errors at all.

Expand Down
Loading