getExpectedNormalizedEntity example


    $this->workflow->getTypePlugin()->addEntityTypeAndBundle($entity->getEntityTypeId()$entity->bundle());
    $this->workflow->save();

    return $entity;
  }

  /** * {@inheritdoc} */
  protected function getExpectedNormalizedEntity() {
    return array_merge(parent::getExpectedNormalizedEntity()[
      'moderation_state' => [
        [
          'value' => 'published',
        ],
      ],
      'vid' => [
        [
          'value' => (int) $this->entity->getRevisionId(),
        ],
      ],
    ]);
  }
// Modify the entity under test to use the provided parent terms.     $this->entity->set('parent', $parent_term_ids)->save();

    $this->initAuthentication();
    $url = $this->getEntityResourceUrl();
    $url->setOption('query', ['_format' => static::$format]);
    $request_options = $this->getAuthenticationRequestOptions('GET');
    $this->provisionEntityResource();
    $this->setUpAuthorization('GET');
    $response = $this->request('GET', $url$request_options);
    $expected = $this->getExpectedNormalizedEntity();
    static::recursiveKSort($expected);
    $actual = $this->serializer->decode((string) $response->getBody()static::$format);
    static::recursiveKSort($actual);
    $this->assertSame($expected$actual);
  }

  public function providerTestGetTermWithParent() {
    return [
      'root parent: [0] (= no parent)' => [
        [0],
      ],
      

    $entity_test->setOwnerId(0);
    $entity_test->save();

    return $entity_test;
  }

  /** * {@inheritdoc} */
  protected function getExpectedNormalizedEntity() {
    return parent::getExpectedNormalizedEntity() + [
      static::$fieldName => [
        [
          'value' => '2017-03-02T07:02:00+11:00',
          'end_value' => '2017-03-02T07:02:00+11:00',
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
protected function setUpAuthorization($method) {
    parent::setUpAuthorization($method);
    if (in_array($method['POST', 'PATCH'], TRUE)) {
      $this->grantPermissionsToTestedRole(['use text format my_text_format']);
    }
  }

  /** * {@inheritdoc} */
  protected function getExpectedNormalizedEntity() {
    $expected = parent::getExpectedNormalizedEntity();
    $expected['field_test_text'] = [
      [
        'value' => 'Cádiz is the oldest continuously inhabited city in Spain and a nice place to spend a Sunday with friends.',
        'format' => 'my_text_format',
        'processed' => '<p>Cádiz is the oldest continuously inhabited city in Spain and a nice place to spend a Sunday with friends.</p>' . "\n" . '<p>This is a dynamic llama.</p>',
      ],
    ];
    return $expected;
  }

  /** * {@inheritdoc} */

    $entity_test->setOwnerId(0);
    $entity_test->save();

    return $entity_test;
  }

  /** * {@inheritdoc} */
  protected function getExpectedNormalizedEntity() {
    return parent::getExpectedNormalizedEntity() + [
      static::$fieldName => [
        [
          'value' => $this->entity->get(static::$fieldName)->value,
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
  
->enableLayoutBuilder()
      ->setOverridable()
      ->save();
    $this->assertCount(1, $entity->getThirdPartySetting('layout_builder', 'sections'));
    return $entity;
  }

  /** * {@inheritdoc} */
  protected function getExpectedNormalizedEntity() {
    $expected = parent::getExpectedNormalizedEntity();
    array_unshift($expected['dependencies']['module'], 'layout_builder');
    $expected['hidden'][OverridesSectionStorage::FIELD_NAME] = TRUE;
    $expected['third_party_settings']['layout_builder'] = [
      'enabled' => TRUE,
      'allow_custom' => TRUE,
    ];
    return $expected;
  }

}
/** * Trait for EntityResourceTestBase subclasses testing $format='xml'. */
trait XmlEntityNormalizationQuirksTrait {

  use XmlNormalizationQuirksTrait;

  /** * {@inheritdoc} */
  protected function getExpectedNormalizedEntity() {
    $default_normalization = parent::getExpectedNormalizedEntity();

    if ($this->entity instanceof FieldableEntityInterface) {
      $normalization = $this->applyXmlFieldDecodingQuirks($default_normalization);
    }
    else {
      $normalization = $this->applyXmlConfigEntityDecodingQuirks($default_normalization);
    }
    $normalization = $this->applyXmlDecodingQuirks($normalization);

    return $normalization;
  }

  
$this->setUpAuthorization('POST');

    // 404 when the field name is invalid.     $invalid_uri = Url::fromUri('base:file/upload/entity_test/entity_test/field_rest_file_test_invalid');
    $response = $this->fileRequest($invalid_uri$this->testFileData);
    $this->assertResourceErrorResponse(404, 'Field "field_rest_file_test_invalid" does not exist', $response);

    // This request will have the default 'application/octet-stream' content     // type header.     $response = $this->fileRequest($uri$this->testFileData);
    $this->assertSame(201, $response->getStatusCode());
    $expected = $this->getExpectedNormalizedEntity();
    $this->assertResponseData($expected$response);

    // Check the actual file data.     $this->assertSame($this->testFileData, file_get_contents('public://foobar/example.txt'));

    // Test the file again but using 'filename' in the Content-Disposition     // header with no 'file' prefix.     $response = $this->fileRequest($uri$this->testFileData, ['Content-Disposition' => 'filename="example.txt"']);
    $this->assertSame(201, $response->getStatusCode());
    $expected = $this->getExpectedNormalizedEntity(2, 'example_0.txt');
    $this->assertResponseData($expected$response);

    
$this->assertNotInstanceOf(ResourceResponseInterface::class$cached_response);
          $this->assertInstanceOf(CacheableResponseInterface::class$cached_response);
        }
      }
      $this->assertTrue($found_cached_200_response);
      $this->assertTrue($other_cached_responses_are_4xx);
    }

    // Sort the serialization data first so we can do an identical comparison     // for the keys with the array order the same (it needs to match with     // identical comparison).     $expected = $this->getExpectedNormalizedEntity();
    static::recursiveKSort($expected);
    $actual = $this->serializer->decode((string) $response->getBody()static::$format);
    static::recursiveKSort($actual);
    $this->assertEqualsCanonicalizing($expected$actual);

    // Not only assert the normalization, also assert deserialization of the     // response results in the expected object.     // Note: deserialization of the XML format is not supported, so only test     // this for other formats.     if (static::$format !== 'xml') {
      $unserialized = $this->serializer->deserialize((string) $response->getBody()get_class($this->entity)static::$format);
      
protected static $mimeType = 'application/json';

  /** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function getExpectedNormalizedEntity() {
    $expected = parent::getExpectedNormalizedEntity();
    // The 'internal_value' property in test field type is not exposed in the     // normalization because setInternal(FALSE) was not called for this     // property.     // @see \Drupal\entity_test\Plugin\Field\FieldType\InternalPropertyTestFieldItem::propertyDefinitions     $expected['field_test_internal'] = [
      [
        'value' => 'This value shall not be internal!',
        'non_internal_value' => 'Computed! This value shall not be internal!',
      ],
    ];
    return $expected;
  }

    $entity_test->setOwnerId(0);
    $entity_test->save();

    return $entity_test;
  }

  /** * {@inheritdoc} */
  protected function getExpectedNormalizedEntity() {
    return parent::getExpectedNormalizedEntity() + [
      static::$fieldName => [
        [
          'value' => '2017-03-02T07:02:00+11:00',
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
  
if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
      return parent::getExpectedUnauthorizedAccessMessage($method);
    }

    return "The 'administer entity_test content' permission is required.";
  }

  /** * {@inheritdoc} */
  protected function getExpectedNormalizedEntity() {
    $expected = parent::getExpectedNormalizedEntity();
    $expected['computed_reference_field'] = [];
    $expected['computed_string_field'] = [];
    unset($expected['field_test_text']$expected['langcode']$expected['type']$expected['uuid']);
    // @see \Drupal\entity_test\Plugin\Field\ComputedTestCacheableStringItemList::computeValue().     $expected['computed_test_cacheable_string_field'] = [
      [
        'value' => 'computed test cacheable string field',
      ],
    ];

    $expected['uuid'] = [
      
Home | Imprint | This part of the site doesn't use cookies.