You are here

RestfulCreateTaxonomyTermTestCase.test in RESTful 7.2

Same filename and directory in other branches
  1. 7 tests/RestfulCreateTaxonomyTermTestCase.test

Contains RestfulCreateTaxonomyTermTestCase

File

tests/RestfulCreateTaxonomyTermTestCase.test
View source
<?php

/**
 * @file
 * Contains RestfulCreateTaxonomyTermTestCase
 */
use Drupal\restful\Http\Request;
use Drupal\restful\Http\RequestInterface;
class RestfulCreateTaxonomyTermTestCase extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Taxonomy term integration',
      'description' => 'Test the creation of a taxonomy term entity type.',
      'group' => 'RESTful',
    );
  }
  public function setUp() {
    parent::setUp('restful_test');
  }

  /**
   * Test the creation of a taxonomy term entity type.
   */
  public function testCreate() {
    $resource_manager = restful()
      ->getResourceManager();
    $user1 = $this
      ->drupalCreateUser(array(
      'create article content',
    ));
    $this
      ->drupalLogin($user1);
    $handler = $resource_manager
      ->getPlugin('test_tags:1.0');
    $handler
      ->setAccount($user1);
    $text1 = $this
      ->randomName();
    $request = array(
      'label' => $text1,
    );
    $handler
      ->setRequest(Request::create('', array(), RequestInterface::METHOD_POST, NULL, FALSE, NULL, array(), array(), array(), $request));
    $handler
      ->setPath('');
    $result = drupal_json_decode(restful()
      ->getFormatterManager()
      ->format($handler
      ->process(), 'json'));
    $result = $result['data'];
    $id = $result[0]['id'];
    $this
      ->assertTrue($id, 'Term was created by a non-admin user.');
  }

}