public function index() { $query = new Query(); $query->orderBy('id', 'DESC'); $query->limit(4); $posts = $query->find('Posts'); $this->render('index.html.twig', array('posts' => $posts)); }
private function tstAddPOST($username, $password, $newRecord, $expectedResponseCode, $expectedErrorMessage, $allSectionsForThisTeacherAndSemester = []) { // 1. Attempt to login. $credentials = ['username' => $username, 'password' => $password]; $this->post('/users/login', $credentials); $authUser = $this->_controller->Auth->user(); $this->session(['Auth' => ['User' => $authUser]]); // 2. Submit request... //if (is_null($section_id)) { $this->post('/clazzes/add', $newRecord); //} else { //$this->get('/clazzes/add?section_id=' . $section_id); //} // 3. Examine response. $this->assertResponseCode($expectedResponseCode); switch ($expectedResponseCode) { //case 200: // All is well... keep on truckin' //$this->assertNoRedirect(); //break; case 302: if (is_null()) { $this->assertRedirect('/clazzes'); } // Verify the flash message $flash = $this->_controller->request->session()->read("Flash"); $n = $flash['flash'][0]['message']; $this->assertEquals(ClazzesController::CLAZZ_SAVED, $n); return; case 400: $this->assertResponseContains($expectedErrorMessage); return; default: $this->fail('Unexpected response'); } // 1. Login, POST a suitable record to the url, redirect, and return the record just // posted, as read from the db. //$fixtureRecord=$this->clazzesFixture->newClazzRecord; //$fromDbRecord=$this->genericAddPostProlog( //FixtureConstants::userAndyAdminId, //'/clazzes/add', $fixtureRecord, //'/clazzes', $this->clazzes //); //$this->fakeLogin($user_id); //$this->post($url, $newRecord); //$this->assertResponseSuccess(); // 2xx, 3xx //$this->assertRedirect( $redirect_url ); // Now retrieve the newly written record. $connection = ConnectionManager::get('test'); $query = new Query($connection, $table); $fromDbRecord = $query->find('all')->order(['id' => 'DESC'])->first(); //return $fromDbRecord; // 2. Now validate that record. $this->assertEquals($fromDbRecord['section_id'], $fixtureRecord['section_id']); $this->assertEquals($fromDbRecord['event_datetime'], $fixtureRecord['event_datetime']); $this->assertEquals($fromDbRecord['comments'], $fixtureRecord['comments']); }
public function serverResponse() { $validator = Validator::make(Input::all(), array('id' => array('required', 'exists:queries,id'), 'serverid' => array('required', 'server'), 'response' => array('required'), 'auth' => array('required'))); if ($validator->fails()) { return Response::json(array('success' => false, 'error' => $validator->messages()->first())); } $query = Query::find(Input::get('id')); $serverid = Input::get('serverid'); $servers = Config::get('lowendping.servers'); if (QueryResponse::where('server_id', $serverid)->where('query_id', $query->id)->count() > 0) { return Response::json(array('success' => false, 'error' => 'Response already logged!')); } if (!Input::has('auth') || Input::get('auth') != $servers[$serverid]['auth']) { // Should we be doing this? It makes sense since it could be a valid error. $this->submitResponse($query, $serverid, 'Invalid response authentication.'); return Response::json(array('success' => false, 'error' => 'Invalid authentication!')); } $this->submitResponse($query, $serverid, Input::get('response')); }