public function testInvalidUser() { $request = array("user" => array("username" => 'user_' . mt_rand(), "email" => 'test_' . mt_rand() . '@test.com', "enabled" => 'true', "plainPassword" => '1231231q', "firstName" => "firstName", "lastName" => "lastName", "rolesCollection" => array("1"))); $this->client->request('POST', $this->client->generate('oro_api_post_user'), $request, array(), array(), ToolsAPI::generateWsseHeader(self::USER_NAME, ToolsAPI::USER_PASSWORD)); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 401); }
public function testWsseAccess() { try { $this->client->soap("http://localhost/api/soap", array('location' => 'http://localhost/api/soap', 'soap_version' => SOAP_1_2)); } catch (\Exception $e) { $this->assertEquals('Forbidden', $e->getMessage()); } }
public function testInvalidUser() { $this->client = static::createClient(array(), ToolsAPI::generateWsseHeader(self::USER_NAME, ToolsAPI::USER_PASSWORD)); try { $this->client->soap("http://localhost/api/soap", array('location' => 'http://localhost/api/soap', 'soap_version' => SOAP_1_2)); } catch (\Exception $e) { $this->assertEquals('Unauthorized', $e->getMessage()); } }
/** * @depends testGetAddressTypes * @param array $expected */ public function testGetAddressType($expected) { foreach ($expected as $addrType) { $result = $this->client->getSoap()->getAddressType($addrType['name']); $result = ToolsAPI::classToArray($result); $this->assertNotEmpty($result); $this->assertEquals($addrType, $result); } }
/** * @depends testApiGetRoleById * @param $roleId */ public function testApiDeleteRole($roleId) { $this->client->request('DELETE', $this->client->generate('oro_api_delete_role', array('id' => $roleId))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 204); $this->client->request('GET', $this->client->generate('oro_api_get_role', array('id' => $roleId))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 404); }
/** * Test POST * @return string */ public function testCreate() { $this->markTestSkipped('BAP-1375'); $result = $this->client->getSoap()->createBusinessUnit($this->fixtureData['business_unit']); $responseData = ToolsAPI::classToArray($result); $this->assertNotEmpty($responseData); $this->assertInternalType('array', $responseData); $this->assertArrayHasKey('id', $responseData); return $responseData['id']; }
/** * @param array $request * @param array $response * * @dataProvider requestsApi */ public function testApi($request, $response) { $requestUrl = $request['query']; $this->client->request('GET', $this->client->generate('oro_api_get_search_advanced'), array('query' => $requestUrl)); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 200); $result = json_decode($result->getContent(), true); //compare result $this->assertEqualsResponse($response, $result); }
/** * @param array $response * @return array * @depends testGetAudits */ public function testGetAudit($response) { foreach ($response as $audit) { $result = $this->client->getSoap()->getAudit($audit['id']); $result = ToolsAPI::classToArray($result); unset($result['loggedAt']); unset($audit['loggedAt']); $this->assertEquals($audit, $result); } }
public function testSearch() { $result = ToolsAPI::getEntityGrid($this->client, 'tag-grid', array('tag-grid[_filter][name][value]' => 'tag758_updated')); ToolsAPI::assertJsonResponse($result, 200); $result = ToolsAPI::jsonToArray($result->getContent()); $result = reset($result['data']); $this->client->request('GET', $this->client->generate('oro_tag_search', array('id' => $result['id']))); $result = $this->client->getResponse(); $this->assertContains('Records tagged as "tag758_updated"', $result->getContent()); $this->assertContains('No results were found', $result->getContent()); }
/** * @param array $response * @depends testGetAudits */ public function testGetAudit($response) { foreach ($response as $audit) { $this->client->request('GET', $this->client->generate('oro_api_get_audit', array('id' => $audit['id']))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 200); $result = ToolsAPI::jsonToArray($result->getContent()); unset($result['loggedAt']); unset($audit['loggedAt']); $this->assertEquals($audit, $result); } }
private function chooseEmbeddedFormFromGrid() { $response = $this->client->requestGrid('embedded-forms-grid'); $this->assertEquals(200, $response->getStatusCode()); $result = $this->jsonToArray($response->getContent()); foreach ($result['data'] as $row) { if ($row['formType'] == 'Diamante Ticket') { return $row; } } return 0; }
/** * @depends testGetAddressTypes * @param array $expected */ public function testGetAddressType($expected) { foreach ($expected as $addrType) { $this->client->request('GET', $this->client->generate('oro_api_get_addresstype', array('name' => $addrType['name']))); /** @var $result Response */ $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 200); $result = ToolsAPI::jsonToArray($result->getContent()); $this->assertNotEmpty($result); $this->assertEquals($addrType, $result); } }
/** * @param string $request * @param array $response * * @dataProvider requestsApi */ public function testApi($request, $response) { if (is_null($request['search'])) { $request['search'] = ''; } if (is_null($request['offset'])) { $request['offset'] = self::DEFAULT_VALUE; } if (is_null($request['max_results'])) { $request['max_results'] = self::DEFAULT_VALUE; } $result = $this->client->getSoap()->search($request['search'], $request['offset'], $request['max_results']); $result = ToolsAPI::classToArray($result); $this->assertEqualsResponse($response, $result); }
/** * @dataProvider requestsApi * @depends testGetUsers */ public function testDeleteUser($request) { //get user id $userId = $this->client->getSoap()->getUserBy(array('item' => array('key' => 'username', 'value' => 'Updated_' . $request['username']))); $userId = ToolsAPI::classToArray($userId); $result = $this->client->getSoap()->deleteUser($userId['id']); $this->assertTrue($result); try { $this->client->getSoap()->getUserBy(array('item' => array('key' => 'username', 'value' => 'Updated_' . $request['username']))); } catch (\SoapFault $e) { if ($e->faultcode != 'NOT_FOUND') { throw $e; } } }
/** * Creates a Client. * * @param array $options An array of options to pass to the createKernel class * @param array $server An array of server parameters * * @return Client A Client instance */ protected static function createClient(array $options = array(), array $server = array()) { if (!self::$internalClient) { self::$internalClient = parent::createClient($options, $server); if (self::$db_isolation) { /** @var Client $client */ $client = self::$internalClient; //workaround MyISAM search tables are not on transaction if (self::$db_reindex) { $kernel = $client->getKernel(); $application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel); $application->setAutoExit(false); $options = array('command' => 'oro:search:reindex'); $options['--env'] = "test"; $options['--quiet'] = null; $application->run(new \Symfony\Component\Console\Input\ArrayInput($options)); } $client->startTransaction(); $pdoConnection = Client::getPdoConnection(); if ($pdoConnection) { //set transaction level to 1 for entityManager $connection = $client->createConnection($pdoConnection); $client->getContainer()->set('doctrine.dbal.default_connection', $connection); /** @var EntityManager $entityManager */ $entityManager = $client->getContainer()->get('doctrine.orm.entity_manager'); if (spl_object_hash($entityManager->getConnection()) != spl_object_hash($connection)) { $reflection = new \ReflectionProperty('Doctrine\\ORM\\EntityManager', 'conn'); $reflection->setAccessible(true); $reflection->setValue($entityManager, $connection); } } } } return self::$internalClient; }
/** * @depends testGetRole * @param array $roles */ public function testDeleteRoles($roles) { //get roles foreach ($roles as $role) { $result = $this->client->getSoap()->deleteRole($role['id']); $this->assertTrue($result); } $roles = $this->client->getSoap()->getRoles(); $roles = ToolsAPI::classToArray($roles); if (!empty($roles)) { $roles = array_filter($roles['item'], function ($v) { return strpos($v['label'], '_Updated') !== false; }); } $this->assertEmpty($roles); }
/** * @depends testUpdate * @param string $id */ public function testView($id) { $crawler = $this->client->request('GET', $this->client->generate('oro_business_unit_view', array('id' => $id))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 200, 'text/html; charset=UTF-8'); $this->assertContains("testBU_Updated - Business Units - Users Management - System", $crawler->html()); }
/** * @depends testGetGroups */ public function testDeleteGroups() { $groups = $this->client->getSoap()->getGroups(); $groups = ToolsAPI::classToArray($groups); $this->assertEquals(6, count($groups['item'])); foreach ($groups['item'] as $k => $group) { if ($k > 1) { //do not delete default groups $result = $this->client->getSoap()->deleteGroup($group['id']); $this->assertTrue($result); } } $groups = $this->client->getSoap()->getGroups(); $groups = ToolsAPI::classToArray($groups); $this->assertEquals(2, count($groups['item'])); }
/** * @depends testApiUpdateGroup * @param $group */ public function apiDeleteGroup($group) { $this->client->request('DELETE', $this->client->generate('oro_api_delete_group', array('id' => $group['id']))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 204); $this->client->request('GET', $this->client->generate('oro_api_get_group', array('id' => $group['id']))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 404); }
/** * Test DELETE * * @depends testCreate * @param string $id */ public function testDelete($id) { $this->client->request('DELETE', $this->client->generate('oro_api_delete_businessunit', array('id' => $id))); /** @var $result Response */ $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 204); $this->client->request('GET', $this->client->generate('oro_api_get_businessunit', array('id' => $id))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 404); }
/** * @depends testCreate */ public function testDelete() { $result = ToolsAPI::getEntityGrid($this->client, 'email-notification-grid', array('email-notification-grid[_pager][_page]' => 1, 'email-notification-grid[_pager][_per_page]' => 1)); ToolsAPI::assertJsonResponse($result, 200); $result = ToolsAPI::jsonToArray($result->getContent()); $result = reset($result['data']); $this->client->request('DELETE', $this->client->generate('oro_api_delete_emailnotication', array('id' => $result['id']))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 204); }
/** * @param string $method * @param string $url * @param int $code * @param array $urlParameters * @param array $requestParameters * @param string $assert * * @return \Symfony\Component\HttpFoundation\Response */ protected function request($method, $url, $code, $urlParameters = array(), $requestParameters = array(), $assert = 'assertJsonResponseStatusCodeEquals') { $server = $this->generateWsse(); $this->client->setServerParameters($server); $this->client->insulate(); $this->client->request($method, $this->getUrl($url, $urlParameters), $requestParameters); $result = $this->client->getResponse(); $this->{$assert}($result, $code); return $result; }
/** * Reset client and rollback transaction */ protected function resetClient() { if (self::$clientInstance) { if (self::getDbIsolationSetting()) { self::$clientInstance->rollbackTransaction(); } $this->client = null; self::$clientInstance = null; } }
/** * @depends testApiUpdateUser * @param int $userId */ public function testApiDeleteUser($userId) { $this->client->request('DELETE', $this->client->generate('oro_api_delete_user', array('id' => $userId))); $result = $this->client->getResponse(); $this->assertJsonResponse($result, 204); $this->client->request('GET', $this->client->generate('oro_api_get_user', array('id' => $userId))); $result = $this->client->getResponse(); $this->assertJsonResponse($result, 404); }
/** * @depends testGetRegion */ public function testGetCountryRegion() { $result = $this->client->getSoap()->getRegionByCountry('US'); $result = ToolsAPI::classToArray($result); foreach ($result['item'] as $region) { $region['country'] = $region['country']['name']; $expectedResult = $this->client->getSoap()->getRegion($region['combinedCode']); $expectedResult = ToolsAPI::classToArray($expectedResult); $this->assertEquals($expectedResult, $region); } }
/** * @depends testRemoveAclsFromRole */ public function testAddAclsToRole($expectedAcl) { $roleId = $this->client->getSoap()->getRoleByName(self::TEST_EDIT_ROLE); $roleId = ToolsAPI::classToArray($roleId); $this->client->getSoap()->addAclsToRole($roleId['id'], array('oro_security', 'oro_address')); $result = $this->client->getSoap()->getRoleAcl($roleId['id']); $result = ToolsAPI::classToArray($result); $actualAcl = $result['item']; sort($actualAcl); $this->assertEquals($expectedAcl, $actualAcl); }
/** * @depends testRunDaemon */ public function testStopDaemon() { $this->client->request('GET', $this->client->generate('oro_cron_job_stop_daemon')); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 200, 'text/html; charset=UTF-8'); $this->client->request('GET', $this->client->generate('oro_cron_job_status'), array(), array(), array('HTTP_X-Requested-With' => 'XMLHttpRequest')); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 200, 'text/html; charset=UTF-8'); $this->assertEquals(0, (int) $result->getContent()); }
/** * Test Empty Body error * * @depends testNotFound * @dataProvider navagationItemsProvider */ public function testEmptyBody($itemType) { $this->assertNotEmpty(self::$entities[$itemType]); $requests = array('POST' => $this->client->generate('oro_api_post_navigationitems', array('type' => $itemType)), 'PUT' => $this->client->generate('oro_api_put_navigationitems_id', array('type' => $itemType, 'itemId' => self::$entities[$itemType]['id']))); foreach ($requests as $requestType => $url) { $this->client->request($requestType, $url, array(), array(), ToolsAPI::generateWsseHeader()); /** @var $response Response */ $response = $this->client->getResponse(); ToolsAPI::assertJsonResponse($response, 400); $responseJson = json_decode($response->getContent(), true); $this->assertArrayHasKey('message', $responseJson); $this->assertEquals('Wrong JSON inside POST body', $responseJson['message']); $this->client->restart(); } }
public function testGetCountryRegion() { $this->client->request('GET', $this->client->generate('oro_api_country_get_regions', array('country' => 'US'))); /** @var $result Response */ $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 200); $result = ToolsAPI::jsonToArray($result->getContent()); foreach ($result as $region) { $this->client->request('GET', $this->client->generate('oro_api_get_region'), array('id' => $region['combined_code'])); /** @var $result Response */ $expectedResult = $this->client->getResponse(); ToolsAPI::assertJsonResponse($expectedResult, 200); $expectedResult = ToolsAPI::jsonToArray($expectedResult->getContent()); $this->assertEquals($expectedResult, $region); } }
public function testUpdateProfile() { $crawler = $this->client->request('GET', $this->client->generate('oro_user_profile_update')); ToolsAPI::assertJsonResponse($this->client->getResponse(), 200, 'text/html; charset=UTF-8'); $this->assertContains('John Doe - Edit - Users - Users Management - System', $this->client->getResponse()->getContent()); /** @var Form $form */ $form = $crawler->selectButton('Save and Close')->form(); $form['oro_user_user_form[birthday]'] = '1999-01-01'; $this->client->followRedirects(true); $crawler = $this->client->submit($form); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 200, 'text/html; charset=UTF-8'); $this->assertContains("User saved", $crawler->html()); $crawler = $this->client->request('GET', $this->client->generate('oro_user_profile_update')); ToolsAPI::assertJsonResponse($this->client->getResponse(), 200, 'text/html; charset=UTF-8'); $this->assertContains('John Doe - Edit - Users - Users Management - System', $this->client->getResponse()->getContent()); /** @var Form $form */ $form = $crawler->selectButton('Save and Close')->form(); $this->assertEquals('1999-01-01', $form['oro_user_user_form[birthday]']->getValue()); }