FieldCollectionRESTTest.php in Field collection 8
File
src/Tests/FieldCollectionRESTTest.php
View source
<?php
namespace Drupal\field_collection\Tests;
use Drupal\rest\Tests\RESTTestBase;
use Drupal\Component\Serialization\Json;
use Drupal\Tests\field_collection\Functional\FieldCollectionTestTrait;
class FieldCollectionRESTTest extends RESTTestBase {
use FieldCollectionTestTrait;
public static $modules = [
'rest',
'node',
'field_collection',
];
public function setUp() {
parent::setUp();
$this
->setUpFieldCollectionTest();
}
public function testRead() {
$this
->enableService('entity:node', 'GET', 'json');
$permissions = $this
->entityPermissions('node', 'view');
$account = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($account);
list($node, $field_collection_item) = $this
->createNodeWithFieldCollection('article');
$url = $node
->toUrl('canonical');
$url
->setRouteParameter('node', $node
->id());
$url
->setRouteParameter('_format', 'json');
$response = $this
->httpRequest($url, 'GET', NULL, 'application/json');
$data = Json::decode($response);
$field_collection_data = $data['field_test_collection'][0];
$this
->assertEqual($field_collection_data['uuid'][0]['value'], $field_collection_item
->uuid(), 'Field collection item UUID is correct');
$this
->assertEqual($field_collection_data['item_id'][0]['value'], $field_collection_item
->id(), 'Field collection item ID is correct');
$this
->assertEqual($field_collection_data['host_type'][0]['value'], 'node', 'Field collection item host type is correct');
$this
->assertEqual($field_collection_data['revision_id'][0]['value'], $field_collection_item
->getRevisionId(), 'Field collection item revision id is correct');
$this
->assertEqual($field_collection_data['field_name'][0]['target_id'], 'field_test_collection', 'Field collection item field name is correct');
$this
->assertEqual($field_collection_data['field_inner'][0]['value'], '1', 'Field collection item inner field value is correct');
}
}