Commit 2c45033b authored by borisson_'s avatar borisson_ Committed by StryKaizer

Issue #2956902 by borisson_: Add Rest integration tests for our entities

parent ddd9348c
# See core/core.link_relation_types.yml
settings-form:
description: A form where a resource of this type can be edited. See customize-form.
clone-form:
description: A form where a resource of this type can be duplicated. See duplicate-form.
......@@ -282,9 +282,13 @@ class FacetsSummary extends ConfigEntityBase implements FacetsSummaryInterface {
*/
public function calculateDependencies() {
parent::calculateDependencies();
$facet_dependencies = $this->getFacetSource()->calculateDependencies();
if (!empty($facet_dependencies)) {
$this->addDependencies($facet_dependencies);
if ($this->getFacetSource() === NULL) {
return $this;
}
$facet_source_dependencies = $this->getFacetSource()->calculateDependencies();
if (!empty($facet_source_dependencies)) {
$this->addDependencies($facet_source_dependencies);
}
return $this;
......
<?php
namespace Drupal\Tests\facets_summary\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* Rest test for json, anonymous, index entity.
*
* @group facets
*/
class FacetSummaryJsonAnonTest extends FacetSummaryResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
}
<?php
namespace Drupal\Tests\facets_summary\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* Rest test for json, basic auth, index entity.
*
* @group facets
*/
class FacetSummaryJsonBasicAuthTest extends FacetSummaryResourceTestBase {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
<?php
namespace Drupal\Tests\facets_summary\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* Rest test for json, cookie, index entity.
*
* @group facets
*/
class FacetSummaryJsonCookieTest extends FacetSummaryResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
<?php
namespace Drupal\Tests\facets_summary\Functional\Rest;
use Drupal\facets\Entity\FacetSource;
use Drupal\facets_summary\Entity\FacetsSummary;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
/**
* Class FacetSummaryResourceTestBase.
*/
abstract class FacetSummaryResourceTestBase extends EntityResourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['facets_summary'];
/**
* {@inheritdoc}
*/
public static $entityTypeId = 'facets_summary';
/**
* {@inheritdoc}
*/
protected static $labelFieldName = 'name';
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
$this->grantPermissionsToTestedRole(['administer facets']);
}
/**
* {@inheritdoc}
*/
public function createEntity() {
$entity = FacetsSummary::create();
$entity->set('id', 'tapir')
->set('name', 'Tapir')
->set('uuid', 'tapir-uuid')
->save();
return $entity;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
return [
'dependencies' => [],
'facet_source_id' => NULL,
'facets' => [],
'id' => 'tapir',
'langcode' => 'en',
'name' => 'Tapir',
'processor_configs' => [],
'status' => TRUE,
'uuid' => 'tapir-uuid',
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
// @todo Update after https://www.drupal.org/node/2300677.
}
}
<?php
namespace Drupal\Tests\facets_summary\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* Rest test for xml, anonymous, index entity.
*
* @group facets
*/
class FacetSummaryXmlAnonTest extends FacetSummaryResourceTestBase {
use AnonResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
}
<?php
namespace Drupal\Tests\facets_summary\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* Rest test for xml, basic auth, index entity.
*
* @group facets
*/
class FacetSummaryXmlBasicAuthTest extends FacetSummaryResourceTestBase {
use BasicAuthResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
<?php
namespace Drupal\Tests\facets_summary\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* Rest test for xml, cookie, index entity.
*
* @group facets
*/
class FacetSummaryXmlCookieTest extends FacetSummaryResourceTestBase {
use CookieResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
......@@ -36,8 +36,7 @@ use Drupal\facets\FacetSourceInterface;
* "breadcrumb"
* },
* links = {
* "canonical" = "/admin/config/search/facets/facet-sources/",
* "edit-form" = "/admin/config/search/facets/facet-sources/{facets_facet_source}/edit"
* "edit-form" = "/admin/config/search/facets/facet-sources/{facets_facet_source}/edit",
* }
* )
*/
......
<?php
namespace Drupal\Tests\facets\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* Rest test for json, anonymous, index entity.
*
* @group facets
*/
class FacetJsonAnonTest extends FacetResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
}
<?php
namespace Drupal\Tests\facets\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* Rest test for json, basic auth, index entity.
*
* @group facets
*/
class FacetJsonBasicAuthTest extends FacetResourceTestBase {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
<?php
namespace Drupal\Tests\facets\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* Rest test for json, cookie, index entity.
*
* @group facets
*/
class FacetJsonCookieTest extends FacetResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
<?php
namespace Drupal\Tests\facets\Functional\Rest;
use Drupal\facets\Entity\Facet;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
/**
* Class FacetResourceTestBase.
*/
abstract class FacetResourceTestBase extends EntityResourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['facets'];
/**
* {@inheritdoc}
*/
public static $entityTypeId = 'facets_facet';
/**
* {@inheritdoc}
*/
protected static $labelFieldName = 'name';
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
$this->grantPermissionsToTestedRole(['administer facets']);
}
/**
* {@inheritdoc}
*/
public function createEntity() {
$facet = Facet::create();
$facet->set('id', 'owl');
$facet->set('uuid', 'uuid-owl');
$facet->setWidget('links', ['show_numbers' => TRUE]);
$facet->addProcessor([
'processor_id' => 'url_processor_handler',
'weights' => ['pre_query' => -10, 'build' => -10],
'settings' => [],
]);
$facet->setEmptyBehavior(['behavior' => 'none']);
$facet->save();
return $facet;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
return [
'dependencies' => [],
'empty_behavior' => ['behavior' => 'none'],
'enable_parent_when_child_gets_disabled' => TRUE,
'exclude' => NULL,
'expand_hierarchy' => FALSE,
'facet_source_id' => NULL,
'field_identifier' => NULL,
'hard_limit' => NULL,
'id' => 'owl',
'langcode' => 'en',
'min_count' => 1,
'name' => NULL,
'only_visible_when_facet_source_is_visible' => NULL,
'processor_configs' => [
'url_processor_handler' => [
'processor_id' => 'url_processor_handler',
'settings' => [],
'weights' => [
'build' => -10,
'pre_query' => -10,
],
],
],
'query_operator' => NULL,
'show_only_one_result' => FALSE,
'status' => TRUE,
'url_alias' => NULL,
'use_hierarchy' => FALSE,
'uuid' => 'uuid-owl',
'weight' => NULL,
'widget' => [
'config' => [
'show_numbers' => TRUE,
],
'type' => 'links',
],
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
// @todo Update after https://www.drupal.org/node/2300677.
}
}
<?php
namespace Drupal\Tests\facets\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* Rest test for json, anonymous, index entity.
*
* @group facets
*/
class FacetSourceJsonAnonTest extends FacetSourceResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
}
<?php
namespace Drupal\Tests\facets\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* Rest test for json, basic auth, index entity.
*
* @group facets
*/
class FacetSourceJsonBasicAuthTest extends FacetSourceResourceTestBase {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
<?php
namespace Drupal\Tests\facets\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* Rest test for json, cookie, index entity.
*
* @group facets
*/
class FacetSourceJsonCookieTest extends FacetSourceResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
<?php
namespace Drupal\Tests\facets\Functional\Rest;
use Drupal\facets\Entity\FacetSource;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
/**
* Class FacetSourceResourceTestBase.
*/
abstract class FacetSourceResourceTestBase extends EntityResourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['facets'];
/**
* {@inheritdoc}
*/
public static $entityTypeId = 'facets_facet_source';
/**
* {@inheritdoc}
*/
protected static $labelFieldName = 'name';
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
$this->grantPermissionsToTestedRole(['administer facets']);
}
/**
* {@inheritdoc}
*/
public function createEntity() {
$entity = FacetSource::create();
$entity->set('id', 'red_panda')
->set('name', 'Red panda')
->set('uuid', 'red-panda-uuid')
->save();
return $entity;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
return [
'breadcrumb' => [],
'dependencies' => [],
'filter_key' => null,
'id' => 'red_panda',
'langcode' => 'en',
'name' => 'Red panda',
'uuid' => 'red-panda-uuid',
'status' => true,
'url_processor' => 'query_string',
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
// @todo Update after https://www.drupal.org/node/2300677.
}
}
<?php
namespace Drupal\Tests\facets\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* Rest test for xml, anonymous, index entity.
*
* @group facets
*/
class FacetSourceXmlAnonTest extends FacetSourceResourceTestBase {
use AnonResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
}
<?php
namespace Drupal\Tests\facets\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;