/** * Assert form error * * @param sfForm $form * @param string $field - Form field name * @param string $expectedError - Expected error, "required" * @param string $message */ protected function assertFormError(sfForm $form, $field, $expectedError, $message = null) { $message = $message ? $message . PHP_EOL : null; // Global error if (!$field) { $this->assertTrue($form->hasGlobalErrors(), $this->makeErrorMess($form, $message . "Expected form HAS global errors")); $errors = implode('; ', $form->getGlobalErrors()); $this->assertContains($expectedError, $errors, $this->makeErrorMess($form, $message . "Global errors contains next text")); } else { $errors = $form->getErrorSchema(); $this->assertTrue(isset($errors[$field]), $this->makeErrorMess($form, $message . "Expected field `{$field}` HAS error")); $error = $errors[$field]->getCode(); $this->assertEquals($expectedError, $error, $this->makeErrorMess($form, $message . "Expected error `{$expectedError}` for field `{$field}`")); } }
/** * Treats any error as a global error, so we can show these errors in the global area. * @see sfForm::hasGlobalErrors() * * @return Boolean */ public function hasGlobalErrors() { $hasGlobalErrors = parent::hasGlobalErrors(); return TwicalHelper::hasGlobalErrors($hasGlobalErrors, $this); }