/** * @expectedException CM_Exception_FormFieldValidation */ public function testValidate() { $formField = new CM_FormField_Birthdate(['name' => 'foo', 'minAge' => 18, 'maxAge' => 30]); $request = CM_Http_Request_Abstract::factory('get', '/foo'); $response = CM_Http_Response_Abstract::factory($request, $this->getServiceManager()); $environment = new CM_Frontend_Environment(); $value = $formField->validate($environment, array('year' => 1995, 'month' => 1, 'day' => 1)); $this->assertEquals(new DateTime('1995-01-01'), $value); $formField->validate($environment, array('year' => 2005, 'month' => 1, 'day' => 1)); }
/** * @param CM_Http_Request_Abstract $request * @throws CM_Exception * @return CM_Http_Response_Abstract */ public function processRequest(CM_Http_Request_Abstract $request) { try { $response = CM_Http_Response_Abstract::factory($request, $this->getServiceManager()); } catch (CM_Exception $e) { $e->setSeverity(CM_Exception::WARN); throw $e; } $response->process(); return $response; }
public function testGetLanguageByUrl() { $request = $this->_prepareRequest('/de/home'); CM_Http_Response_Abstract::factory($request, $this->getServiceManager()); $this->assertNull($request->getLanguage()); CMTest_TH::createLanguage('en'); // default language $urlLanguage = CMTest_TH::createLanguage('de'); $request = $this->_prepareRequest('/de/home'); $response = CM_Http_Response_Abstract::factory($request, $this->getServiceManager()); $this->assertEquals($response->getRequest()->getLanguage(), $urlLanguage); }
public function testSetDeleteCookie() { $request = new CM_Http_Request_Post('/foo/null'); $response = CM_Http_Response_Abstract::factory($request, $this->getServiceManager()); $time = time(); $timeString = date('D\\, d\\-M\\-Y h:i:s e', $time); $response->setCookie('foo', 'bar', $time); $response->setCookie('bar', 'bad!=();'); $headers = $response->getHeaders(); $this->assertSame('Set-Cookie: foo=bar; Expires=' . $timeString . '; Path=/', $headers[0]); $this->assertSame('Set-Cookie: bar=bad%21%3D%28%29%3B; Path=/', $headers[1]); $response->deleteCookie('foo'); $headers = $response->getHeaders(); $this->assertSame('Set-Cookie: foo=; Expires=Thu, 01-Jan-1970 12:00:01 UTC; Path=/', $headers[0]); }