public function testCreateSession() { //Пусть сразу вошли на /#/game и пытаемся отправить ответ //(для простоты тестирования есть тестовая форма /answer) U::get('/answer', $client, $crawler, $html, $json); $form = $crawler->selectButton('Send')->form(array('answer_id' => 4, 'quest_id' => 5)); $client->submit($form); $response = $client->getResponse(); $jsonResponseData = json_decode($response->getContent()); $this->assertTrue($jsonResponseData->info == 'Lost session'); //А теперь сначала создадим пользователя ATL::createUser($userJson, $repository, $username, $em, $client); //Пробуем ответить на вопрос U::get('/answer', $client, $crawler, $html, $json); $form = $crawler->selectButton('Send')->form(array('answer_id' => 4, 'quest_id' => 5)); $client->submit($form); $response = $client->getResponse(); $jsonResponseData = json_decode($response->getContent()); $this->assertTrue(@$jsonResponseData->info != 'Lost session'); $this->assertTrue(@$jsonResponseData->info == 'Answer #4 not found!'); ATL::deleteUser($em, $userJson->id); }
private function _sendAnswer($answerId, $questionId, $client, &$status = null, &$text = null, $buttonText = 'Send') { //print "\n\n_sendAnswer: $questionId = questionId\n\n"; U::get('/answer', $client, $crawler, $html, $json); $form = $crawler->selectButton($buttonText)->form(array('answer_id' => strval($answerId), 'quest_id' => $questionId)); /* * Попытка добратья до приватного свойства формы, по сути успешная, но сессия теряется... * $reflectionClass = new \ReflectionClass('Symfony\Component\DomCrawler\Form'); $prop = $reflectionClass->getProperty('currentUri'); $prop->setAccessible(true); $prop->setValue($form, 'http://ang.loc:8000/answer/add/' . $questionId);*/ $client->submit($form); $response = $client->getResponse(); $text = $response->getContent(); $status = $response->getStatusCode(); $json = json_decode($text); return $json; }