You are here

protected function RestfulSubResourcesCreateEntityTestCase::processRequests in RESTful 7

Same name and namespace in other branches
  1. 7.2 tests/RestfulSubResourcesCreateEntityTestCase.test \RestfulSubResourcesCreateEntityTestCase::processRequests()

Assert valid and invalid requests.

Parameters

string $method: The method name.

string $path: The path.

array $request: The request array.

1 call to RestfulSubResourcesCreateEntityTestCase::processRequests()
RestfulSubResourcesCreateEntityTestCase::testCreateAndUpdateEntity in tests/RestfulSubResourcesCreateEntityTestCase.test
Test creating and updating an entity with sub-resources.

File

tests/RestfulSubResourcesCreateEntityTestCase.test, line 175
Contains RestfulSubResourcesCreateEntityTestCase.

Class

RestfulSubResourcesCreateEntityTestCase
@file Contains RestfulSubResourcesCreateEntityTestCase.

Code

protected function processRequests($method = 'post', $path = '', array $request = array()) {
  $handler = $this->handler;
  $response = $handler
    ->{$method}($path, $request);
  $result = $response[0];
  $this
    ->assertTrue($result['id'], 'Parent entity created.');
  $this
    ->assertTrue($result['entity_reference_single']['id'], 'Single sub-resource created or updated.');
  $this
    ->assertTrue($result['entity_reference_multiple'][0]['id'] && $result['entity_reference_multiple'][1]['id'], 'Multiple sub-resource created or updated.');

  // Validation fail on the parent.
  $request['label'] = 'no';
  $this
    ->assertInvalidRequest($method, $path, $request);

  // Validation fail on the single resource.
  $request['label'] = 'parent';
  if (is_array($request['entity_reference_single'])) {
    $request['entity_reference_single']['label'] = 'no';
    $this
      ->assertInvalidRequest($method, $path, $request);
    $request['entity_reference_single']['label'] = 'child1';
  }

  // Validation fail on the multiple resource.
  if (!empty($request['entity_reference_multiple'][0]['label']) && is_array($request['entity_reference_multiple'][0]['label'])) {
    $request['entity_reference_multiple'][0]['label'] = 'no';
    $this
      ->assertInvalidRequest($method, $path, $request);
  }
}