public function testControllerNoticeToException() { $this->client = $this->createClient(); $errorOccured = false; $syslogProcessorMock = $this->getMockBuilder('Keboola\\Syrup\\Monolog\\Processor\\SyslogProcessor')->disableOriginalConstructor()->getMock(); $syslogProcessorMock->expects($this->any())->method("processRecord")->with($this->callback(function ($subject) use(&$errorOccured) { if ($subject['message'] == 'Notice: Undefined offset: 3') { $e = $subject['context']['exception']; $errorOccured = true; return $e instanceof \Symfony\Component\Debug\Exception\ContextErrorException; } return true; }))->willReturn(['level' => 100]); $container = $this->client->getContainer(); $container->set('syrup.monolog.syslog_processor', $syslogProcessorMock); $this->client->request('GET', '/tests/notice'); $response = $this->client->getResponse(); $responseJson = json_decode($response->getContent(), true); $this->assertEquals('error', $responseJson['status']); $this->assertEquals('Application error', $responseJson['error']); $this->assertEquals(500, $responseJson['code']); $this->assertArrayHasKey('exceptionId', $responseJson); $this->assertArrayHasKey('runId', $responseJson); $this->assertTrue($errorOccured); }
protected function setUp() { $this->client = static::createClient(); $this->client->followRedirects(true); $this->crawler = $this->client->request('GET', self::REGISTRATION_URL); $this->form = $this->crawler->selectButton(self::SUBMIT_BUTTON)->form(); }
public function testSearchPage() { $this->client->request('GET', '/search?keyword=samsung sync master'); $response = $this->client->getResponse(); $this->assertTrue($response->isSuccessful()); $this->assertEquals('application/json', $response->headers->get('Content-Type')); }
public function testPutPlayerAction() { $em = self::$kernel->getContainer()->get('doctrine')->getManager(); $queryBuilder = $em->createQueryBuilder(); $players = $queryBuilder->select('p')->from('DraftBundle:Player', 'p')->setMaxResults(1)->getQuery()->execute(); if (is_array($players)) { $player = $players[0]; } else { $player = $players; } $name = $player->getName(); $team = $player->getNflTeam(); $position = $player->getPosition(); $toEncode = array('name' => 'willy wonka', 'position' => 'QB', 'nflTeam' => 'SF', 'draftYear' => '2016'); $postData = json_encode($toEncode); $this->client->request('PUT', '/api/players/' . $player->getId(), array(), array(), array('CONTENT_TYPE' => 'application/json'), $postData); $response = $this->client->getResponse(); $content = $response->getContent(); $this->assertTrue($response->isSuccessful()); $this->assertEmpty($content); $updatedPlayer = $em->getRepository('DraftBundle:Player')->find($player->getId()); $this->assertEquals('willy wonka', $updatedPlayer->getName()); $updatedPlayer->setName($name); $updatedPlayer->setNflTeam($team); $updatedPlayer->setPosition($position); $em->persist($updatedPlayer); $em->flush(); }
/** * @dataProvider provideLoginData */ public function testLogin(Client $client, $securedUrl, $login, $expectedMessage) { // client follow redirects $client->followRedirects(); // go to secured page -> got login required $crawler = $client->request('GET', $securedUrl); $this->assertEquals(TrustedSsoController::LOGIN_REQUIRED_MESSAGE, $crawler->filter('#message')->text()); // click link -> got login form $crawler = $client->click($crawler->filter('#url')->link()); $this->assertEquals('login', $crawler->filter('form')->attr('id')); // fill form & submit -> got expected message $form = $crawler->filter('input[type=submit]')->form(); $crawler = $client->submit($form, array('login[username]' => $login, 'login[password]' => $login)); $this->assertEquals($expectedMessage, $crawler->filter('#message')->text()); if (!$login === self::LOGIN_INVALID) { // check validation attributes $attrs = static::$kernel->getContainer()->get('security.context')->getToken()->getValidationAttributes(); $this->assertEquals(array('attr1' => 'val1', 'attr2' => 'val2'), $attrs); } // logout -> got logout redirect $crawler = $client->request('GET', '/secured/logout'); $this->assertEquals(TrustedSsoController::LOGOUT_REDIRECT_MESSAGE, $crawler->filter('#message')->text()); // click link -> got logout done $crawler = $client->click($crawler->filter('#url')->link()); $this->assertEquals(ServerController::LOGOUT_MESSAGE, $crawler->filter('#message')->text()); // click link -> go to homepage $crawler = $client->click($crawler->filter('#url')->link()); $this->assertEquals(TestController::HOME_MESSAGE, $crawler->filter('#message')->text()); }
/** * Test token creation and usage */ public function testTokenCreation() { $headers = array('PHP_AUTH_USER' => 'test_key', 'PHP_AUTH_PW' => 'test_secret', 'HTTP_username' => 'p-admin', 'HTTP_password' => 'p-admin'); $this->client->request('GET', '/oauth/access_token?grant_type=password', array(), array(), $headers); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type')); }
/** * @depends testPut */ public function testDeleteMultiple() { $data = [2, 3]; $uri = self::$router->generate('post_assets') . '.json'; self::$client->request('DELETE', $uri, ['images' => json_encode($data)]); $this->assertTrue(self::$client->getResponse()->isRedirect()); }
protected function assertApiGetResponse($apiUri, $expectedStatusCode, $expectedJsonString) { static::$client->request('GET', $apiUri); $this->assertStatusCode($expectedStatusCode, static::$client); $responseBody = static::$client->getResponse()->getContent(); static::assertJson($responseBody); static::assertJsonStringEqualsJsonString($expectedJsonString, $responseBody); }
public function testCreateTransAndRedirectToTpv() { $this->transaction = new Transaction(1); $this->manager->update($this->transaction); /** @var $crawler */ $crawler = $this->client->request('GET', $this->route_index); $this->assertEquals($crawler->filter('body:contains(form)')->count(), 1); }
/** * Test AjaxDeleteFromBookmark action */ public function testAjaxDeleteFromBookmarkAction() { $fixtures = $this->loadFixtures(['AppBundle\\DataFixtures\\ORM\\LoadUserData', 'AppBundle\\DataFixtures\\ORM\\LoadUserGroupData', 'AppBundle\\DataFixtures\\ORM\\LoadGroupData'])->getReferenceRepository(); $this->loginAs($fixtures->getReference('user-admin'), 'main'); $this->client = static::makeClient(); $this->client->request('GET', '/group/jinjer/bookmark/delete', [], [], ['HTTP_X-Requested-With' => 'XMLHttpRequest']); $this->assertStatusCode(Response::HTTP_OK, $this->client); }
/** * @param string $method * @param string $url * @param array $params * @param array $headers */ private function request(string $method, string $url, array $params = [], array $headers = []) { if (is_null($this->client)) { $this->client = static::createClient(); } $headers['HTTP_X_ACCEPT_VERSION'] = self::API_VERSION; $this->client->request($method, $url, $params, [], $headers); }
/** * @param string $method * @param array $parameters * @return Page */ public function open($method = 'GET', $parameters = []) { $this->crawler = $this->client->request($method, $this->unmaskUrl($parameters)); if (!in_array($this->client->getResponse()->getStatusCode(), [200, 302])) { throw new \RuntimeException(sprintf("Can't open \"%s\"", $this->getUrl())); } return $this; }
/** * Request to API, return result * @param string $url URL of API call * @param string $method HTTP method of API call * @param array $params parameters of POST call * @return array */ protected function callApi($url, $method = 'POST', $params = array()) { $this->httpClient->request($method, $url, [], [], [], json_encode($params)); $response = $this->httpClient->getResponse(); /* @var \Symfony\Component\HttpFoundation\Response $response */ $responseJson = json_decode($response->getContent(), true); $this->assertNotEmpty($responseJson, sprintf("Response of API call '%s' after json decoding should not be empty. Raw response:\n%s\n", $url, $response->getContent())); return $responseJson; }
/** * @return void */ protected function setUp() { $this->logout(); $this->client = static::createClient(); $this->client->setMaxRedirects(1); $this->client->request('GET', self::URL_UPLOAD_THEME); $this->login(); $this->client->request('GET', self::URL_UPLOAD_THEME); }
/** * @return Crawler * @throws \Exception */ protected static function loginAsUser() { $uri = self::$container->get('router')->generate('login_route'); $crawler = self::$client->request('GET', $uri); $form = $crawler->selectButton('login_btn')->form(['_username' => 'test', '_password' => '12345678']); self::$client->submit($form); self::assertTrue(self::$client->getResponse()->isRedirection()); return self::$client->followRedirect(); }
protected function callApiGet($url = null, $data = array(), $requiredHttpCode = 200) { $method = 'GET'; $this->httpClient->request($method, $url, array()); $response = $this->httpClient->getResponse(); $this->assertEquals($requiredHttpCode, $response->getStatusCode(), sprintf(AbstractTest::ERROR_HTTP_CODE, $method, $url, $response->getContent())); $responseJson = json_decode($response->getContent(), true); // $this->assertNotEmpty($responseJson, sprintf(self::ERROR_EMPTY_REPONSE, $method, $url)); return $responseJson; }
private function addBattery($type, $count, $name = null) { $crawler = $this->client->request('GET', '/add'); $buttonCrawlerNode = $crawler->selectButton('Save'); $form = $buttonCrawlerNode->form(); $form['battery[type]'] = $type; $form['battery[count]'] = $count; $form['battery[name]'] = $name; $this->client->submit($form); }
/** * Use this function to connect to user in the application using login form * MORE SLOW, Use connectUser function above instead * * @param $username * @param $password * @return Client */ protected function loginUsingFormUser($username, $password) { $this->client = static::createClient(); $this->crawler = $this->client->request('GET', '/login'); $credentials = array('_username' => $username, '_password' => $password); $form = $this->crawler->selectButton('_submit')->form($credentials); $this->client->submit($form); $this->client->followRedirects(); return $this->client; }
/** * Test for AppBundle\Controller\DefaultController::feedAction * Also test performance - Any PHP used should be limited to 32MB of memory * * @param string $source * @param integer $start * @param integer $amount * @param integer $expectedAmount * * @dataProvider feedDataProvider */ public function testFeed($source, $start, $amount, $expectedAmount) { $this->client->request('GET', '/feed', array('source' => $source, 'start' => $start, 'amount' => $amount)); $response = $this->client->getResponse(); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('application/json', $response->headers->get('Content-type')); $this->assertCount($expectedAmount, json_decode($response->getContent(), true)); $this->assertLessThan(1024 * 1024 * 32, memory_get_peak_usage(true)); // 32 MB }
public function testOut() { $this->client->request('GET', '/'); $crawler = $this->client->followRedirect(); $link = $crawler->filter('a#logout')->eq(0)->link(); $this->client->click($link); //suivre redirection vers page login quand click sur 'logout' $this->assertEquals('Sonata\\UserBundle\\Controller\\SecurityFOSUser1Controller::logoutAction', $this->client->getRequest()->attributes->get('_controller')); $this->assertEquals(302, $this->client->getResponse()->getStatusCode()); }
/** * Test show action */ public function testShowAction() { $fixtures = $this->loadFixtures(['AppBundle\\DataFixtures\\ORM\\LoadGroupData', 'AppBundle\\DataFixtures\\ORM\\LoadGenreData', 'AppBundle\\DataFixtures\\ORM\\LoadEventData', 'AppBundle\\DataFixtures\\ORM\\LoadGroupGenreData', 'AppBundle\\DataFixtures\\ORM\\LoadUserData', 'AppBundle\\DataFixtures\\ORM\\LoadUserGenreData', 'AppBundle\\DataFixtures\\ORM\\LoadUserGroupData', 'AppBundle\\DataFixtures\\ORM\\LoadEventGroupData'])->getReferenceRepository(); $this->loginAs($fixtures->getReference('user-manager'), 'main'); $this->client = static::makeClient(); $crawler = $this->client->request('GET', '/event/zaxid'); $this->assertStatusCode(Response::HTTP_OK, $this->client); $this->assertCount(1, $crawler->filter('header.concert-header')); $this->assertCount(1, $crawler->filter('main.concert-header__info')); }
/** * Test token creation and usage */ public function testTokenCreation() { $this->client->request('GET', '/oauth/access_token?grant_type=client_credentials', array(), array(), array('PHP_AUTH_USER' => 'test_key', 'PHP_AUTH_PW' => 'test_secret')); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type')); $tokenReponse = json_decode($this->client->getResponse()->getContent(), true); $refreshToken = $tokenReponse['refresh_token']; $this->client->request('GET', '/oauth/access_token?grant_type=refresh_token&refresh_token=' . $refreshToken, array(), array(), array('PHP_AUTH_USER' => 'test_key', 'PHP_AUTH_PW' => 'test_secret')); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type')); }
public function testEnableRebootKernel() { $mock = $this->getKernelMock(); $mock->expects($this->once())->method('shutdown'); $client = new Client($mock); $client->disableReboot(); $client->request('GET', '/'); $client->request('GET', '/'); $client->enableReboot(); $client->request('GET', '/'); }
/** * Overridden _doRequest method * * @param string $request * @param string $location * @param string $action * @param int $version * @param int $one_way * * @return string */ public function __doRequest($request, $location, $action, $version, $one_way = 0) { //save directly in _SERVER array $_SERVER['HTTP_SOAPACTION'] = $action; $_SERVER['CONTENT_TYPE'] = 'application/soap+xml'; //make POST request $this->client->request('POST', (string) $location, array(), array(), array(), (string) $request); unset($_SERVER['HTTP_SOAPACTION']); unset($_SERVER['CONTENT_TYPE']); return $this->client->getResponse()->getContent(); }
public function testListAction() { // Request the endpoint $this->client->request('GET', '/instruments', [], [], $this->requestParameters); // Get the Response content $response = $this->client->getResponse(); $content = json_decode($response->getContent()); // Validate Response $this->assertEquals(200, $response->getStatusCode()); $this->assertTrue(!empty($content->data)); $this->assertTrue(is_array($content->data)); }
/** * @return mixed */ protected function getAccessToken() { if (!array_key_exists($this->getUsername(), $this->accessToken)) { $headers = array('PHP_AUTH_USER' => 'test_key', 'PHP_AUTH_PW' => 'test_secret', 'HTTP_username' => $this->getUsername(), 'HTTP_password' => $this->getPassword()); $this->client->request('GET', '/oauth/access_token?grant_type=password', array(), array(), $headers); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type')); $tokenReponse = json_decode($this->client->getResponse()->getContent(), true); $this->accessToken[$this->getUsername()] = $tokenReponse['access_token']; } return $this->accessToken[$this->getUsername()]; }
private function oAuthLogin() { // var_dump(JWT::encode( // [ // 'username' => $this->client_username, 'password' => $this->client_password // ], // $this->client_id // ));die; $this->client->request('POST', 'http://' . $this->url . '/oauth/v2/token', ['client_id' => $this->client_id, 'client_secret' => $this->client_secret, 'api_key' => JWT::encode(['username' => $this->client_username, 'password' => $this->client_password], $this->client_id), 'grant_type' => 'http://' . $this->url . '/grants/api_key']); $response = json_decode($this->client->getResponse()->getContent()); $this->access_token = $response->access_token; $this->refresh_token = $response->refresh_token; }
/** * Test form login with invalid user */ public function testLoginWithInvalidUser() { $userName = '******'; $password = '******'; $crawler = $this->client->request('GET', '/login'); $form = $crawler->selectButton('Log in')->form(); $form['_username'] = $userName; $form['_password'] = $password; $this->client->submit($form); $this->assertEquals(302, $this->client->getResponse()->getStatusCode()); $token = $this->client->getContainer()->get('security.token_storage')->getToken(); $this->assertNull($token); }
/** * Request on granting rights manager */ public function testRightManagerAction() { $fixtures = $this->loadFixtures(['AppBundle\\DataFixtures\\ORM\\LoadUserData', 'AppBundle\\DataFixtures\\ORM\\LoadGroupData', 'AppBundle\\DataFixtures\\ORM\\LoadRequestManagerData', 'AppBundle\\DataFixtures\\ORM\\LoadRequestManagerGroupData'])->getReferenceRepository(); $this->loginAs($fixtures->getReference('user-admin'), 'main'); //GET $this->client = static::makeClient(); $crawler = $this->client->request('GET', '/cabinet/request-manager'); //POST $token = $crawler->filter('[name="request_manager[_token]"]')->attr('value'); $data = ['request_manager' => ['fullName' => 'Олекcієнко Марія Вікторівна', 'phone' => '0974567233', 'text' => 'Заявка', 'groups' => [0 => ['slug' => 'shikari']], '_token' => $token]]; $this->client->request('POST', '/cabinet/request-manager', $data); $this->assertStatusCode(Response::HTTP_FOUND, $this->client); }
public function testEdit() { $crawler = $this->client->request('GET', '/member'); $this->assertEquals(Response::HTTP_OK, $this->client->getResponse()->getStatusCode()); $this->assertEquals(1, $crawler->filter('div.app_member_index')->count()); $this->assertGreaterThanOrEqual(1, $crawler->selectLink('Show')->count()); $crawler = $this->client->click($crawler->selectLink('Show')->first()->link()); $this->assertEquals(Response::HTTP_OK, $this->client->getResponse()->getStatusCode()); $this->assertEquals(1, $crawler->filter('div.app_member_show')->count()); $this->assertGreaterThanOrEqual(1, $crawler->selectLink('Edit')->count()); $crawler = $this->client->click($crawler->selectLink('Edit')->first()->link()); $this->assertEquals(Response::HTTP_OK, $this->client->getResponse()->getStatusCode()); $this->assertEquals(1, $crawler->filter('div.app_member_edit')->count()); }