privilegedUser = $this->drupalCreateUser(array( 'administer services', )); $this->drupalLogin($this->privilegedUser); $edit = $this->populateEndpointFAPI() ; $this->drupalPost('admin/build/services/add', $edit, t('Save and proceed')); $this->drupalGet($edit['path']); } /** * Test adding an endpoint succeeds. */ public function testSuccessfulAddEndpoint() { $edit = $this->populateEndpointFAPI() ; // Create and log in our privileged user. $this->privilegedUser = $this->drupalCreateUser(array( 'administer services', 'administer nodes', )); $this->drupalLogin($this->privilegedUser); $this->drupalPost('admin/build/services/add', $edit, t('Save and proceed')) ; $this->assertResponse('200', t('expected 200')); $this->drupalGet('admin/build/services/list') ; $this->assertResponse('200',t('expected 200')); $this->assertText($edit['title'], t('Endpoint path appears')) ; $this->assertText('rest_server', t('Server is rest server')) ; $this->assertText('In database', t('Storage is in database')) ; } /** * Test missing path to endpoint causes an error. */ public function testMissingPath() { $edit = $this->populateEndpointFAPI() ; unset($edit['path']) ; // Create and log in our privileged user. $this->privilegedUser = $this->drupalCreateUser(array( 'administer services', 'administer nodes', )); $this->drupalLogin($this->privilegedUser); $this->drupalPost('admin/build/services/add', $edit, t('Save and proceed')) ; $this->assertResponse('200', 'expected 200'); $this->assertText('Path to endpoint field is required.', t('Endpoint path missing error message.')) ; $this->assertFieldByName('title', $edit['title'], t('Title field remains.')) ; $this->assertFieldByName('server', 'rest_server', t('Server is rest server')) ; $this->assertFieldChecked('edit-services-use-content-permissions', t('Storage use content permission is checked.')) ; } /** * Test missing title for endpoint causes an error. */ public function testMissingTitle() { $edit = $this->populateEndpointFAPI() ; unset($edit['title']) ; // Create and log in our privileged user. $this->privilegedUser = $this->drupalCreateUser(array( 'administer services', 'administer nodes', )); $this->drupalLogin($this->privilegedUser); $this->drupalPost('admin/build/services/add', $edit, t('Save and proceed')) ; $this->assertResponse('200', 'expected 200'); $this->assertText('Endpoint title field is required.', t('Endpoint title missing error message.')) ; $this->assertFieldByName('name', $edit['name'], t('Name field remains.')) ; $this->assertFieldByName('server', 'rest_server', t('Server is rest server')) ; $this->assertFieldChecked('edit-services-use-content-permissions', t('Storage use content permission is checked.')) ; } /** * Test missing server for endpoint causes an error. */ public function testMissingServer() { $edit = $this->populateEndpointFAPI() ; unset($edit['server']) ; // Create and log in our privileged user. $this->privilegedUser = $this->drupalCreateUser(array( 'administer services', 'administer nodes', )); $this->drupalLogin($this->privilegedUser); $this->drupalPost('admin/build/services/add', $edit, t('Save and proceed')) ; $this->assertResponse('200', 'expected 200'); $this->assertText('Server field is required.', t('Server missing error message.')) ; $this->assertFieldByName('name', $edit['name'], t('Name field remains.')) ; $this->assertFieldByName('title', $edit['title'], t('Title field remains.')) ; $this->assertFieldChecked('edit-services-use-content-permissions', t('Storage use content permission is checked.')) ; } /* ------------------------------------ HELPER METHODS ------------------------------------ */ /** * Creates a data array for populating an endpoint creation form. * * @return * An array of fields for fully populating an endpoint creation form. */ public function populateEndpointFAPI() { return array( 'name' => 'mchnname', 'title' => $this->randomName(20), 'path' => $this->randomName(10), 'server' => 'rest_server', 'services_use_content_permissions' => TRUE, ) ; } public function saveNewEndpoint() { $edit = $this->populateEndpointFAPI() ; $endpoint = new stdClass; $endpoint->disabled = FALSE; /* Edit this to true to make a default endpoint disabled initially */ $endpoint->api_version = 3; $endpoint->name = $edit['name']; $endpoint->title = $edit['title']; $endpoint->server = $edit['server']; $endpoint->path = $edit['path']; $endpoint->authentication = array( 'services_sessauth' => array(), ); $endpoint->resources = array( 'node' => array( 'alias' => '', 'operations' => array( 'create' => array( 'enabled' => 1, ), 'retrieve' => array( 'enabled' => 1, ), 'update' => array( 'enabled' => 1, ), 'delete' => array( 'enabled' => 1, ), 'index' => array( 'enabled' => 1, ), ), ), 'system' => array( 'alias' => '', 'actions' => array( 'connect' => array( 'enabled' => 1, ), 'get_variable' => array( 'enabled' => 1, ), 'set_variable' => array( 'enabled' => 1, ), ), ), 'taxonomy_term' => array( 'alias' => '', 'operations' => array( 'create' => array( 'enabled' => 1, ), 'retrieve' => array( 'enabled' => 1, ), 'update' => array( 'enabled' => 1, ), 'delete' => array( 'enabled' => 1, ), ), 'actions' => array( 'selectNodes' => array( 'enabled' => 1, ), ), ), 'taxonomy_vocabulary' => array( 'alias' => '', 'operations' => array( 'create' => array( 'enabled' => 1, ), 'retrieve' => array( 'enabled' => 1, ), 'update' => array( 'enabled' => 1, ), 'delete' => array( 'enabled' => 1, ), ), 'actions' => array( 'getTree' => array( 'enabled' => 1, ), ), ), 'user' => array( 'alias' => '', 'operations' => array( 'create' => array( 'enabled' => 1, ), 'retrieve' => array( 'enabled' => 1, ), 'update' => array( 'enabled' => 1, ), 'delete' => array( 'enabled' => 1, ), 'index' => array( 'enabled' => 1, ), ), 'actions' => array( 'login' => array( 'enabled' => 1, ), 'logout' => array( 'enabled' => 1, ), ), ), 'comment' => array( 'alias' => '', 'operations' => array( 'create' => array( 'enabled' => 1, ), 'retrieve' => array( 'enabled' => 1, ), 'update' => array( 'enabled' => 1, ), 'delete' => array( 'enabled' => 1, ), ), 'actions' => array( 'loadNodeComments' => array( 'enabled' => 1, ), 'countAll' => array( 'enabled' => 1, ), 'countNew' => array( 'enabled' => 1, ), ), ), 'file' => array( 'alias' => '', 'operations' => array( 'create' => array( 'enabled' => 1, ), 'retrieve' => array( 'enabled' => 1, ), 'delete' => array( 'enabled' => 1, ), ), 'actions' => array( 'nodeFiles' => array( 'enabled' => 1, ), ), ), 'echo' => array( 'alias' => '', 'operations' => array( 'index' => array( 'enabled' => 1, ), ), ), ); $endpoint->debug = 1; $endpoint->status = 1; services_endpoint_save($endpoint); $endpoint = services_endpoint_load($endpoint->name); if($endpoint->name == $edit['name']) { $this->pass('Endpoint successfully created'); } else { $this->fail('Endpoint creation failed'); } $this->servicesGet($endpoint->path); return $endpoint; } /** * Builds out our post fields * */ public function services_build_postfields($data = array()) { $post_data = ''; if (is_array($data) && !empty($data)) { array_walk($data, array($this, 'services_flatten_fields')); $post_data = implode('&', $data); } if(is_object($data) && !empty($data)) { array_walk(get_object_vars($data), array($this, 'services_flatten_fields')); $post_data = implode('&', $data); } return $post_data; } /** * Modifies our array data so we can turn it into a querystring * * @param string $item - array value * @param string $key - key of the array element */ public function services_flatten_fields(&$item, $key) { $item = $key .'='. $item; } }