You are here

class ServiceResourceTest in Services 8.4

Same name and namespace in other branches
  1. 9.0.x tests/src/Unit/Entity/ServiceResourceTest.php \Drupal\Tests\services\Unit\Entity\ServiceResourceTest

@coversDefaultClass \Drupal\services\Entity\ServiceResource

@group services

Hierarchy

Expanded class hierarchy of ServiceResourceTest

File

tests/src/Unit/Entity/ServiceResourceTest.php, line 13

Namespace

Drupal\Tests\services\Unit\Entity
View source
class ServiceResourceTest extends UnitTestCase {
  public function testCanConstructDefaultResource() {

    /** @var \Drupal\services\Entity\ServiceResource $resource */
    $resource = new ServiceResource([
      'service_plugin_id' => 'test:plugin:id',
      'service_endpoint_id' => 'test_endpoint_id',
      'formats' => [
        'json',
      ],
      'authentication' => [
        'cookie',
      ],
      'no_cache' => 0,
    ], 'service_endpoint_resource');
    $this
      ->assertEquals('test_endpoint_id.test.plugin.id', $resource
      ->id(), 'ID constructed successfully.');
    $this
      ->assertEquals([
      'json',
    ], $resource
      ->getFormats(), 'Formats found.');
    $this
      ->assertEquals([
      'cookie',
    ], $resource
      ->getAuthentication(), 'Authentication found.');
    $this
      ->assertEquals(0, $resource
      ->getNoCache(), 'Cache setting found.');
  }
  public function testCanConstructResourceNoCacheFalse() {

    /** @var \Drupal\services\Entity\ServiceResource $resource */
    $resource = new ServiceResource([
      'service_plugin_id' => 'test:plugin:id',
      'service_endpoint_id' => 'test_endpoint_id',
      'formats' => [],
      'authentication' => [],
      'no_cache' => FALSE,
    ], 'service_endpoint_resource');
    $this
      ->assertEquals(0, $resource
      ->getNoCache(), 'Cache setting found.');
  }
  public function testCanConstructResourceNoCacheTrue() {

    /** @var \Drupal\services\Entity\ServiceResource $resource */
    $resource = new ServiceResource([
      'service_plugin_id' => 'test:plugin:id',
      'service_endpoint_id' => 'test_endpoint_id',
      'formats' => [],
      'authentication' => [],
      'no_cache' => TRUE,
    ], 'service_endpoint_resource');
    $this
      ->assertEquals(1, $resource
      ->getNoCache(), 'Cache setting found.');
  }
  public function testCanConstructResourceNoCache1() {

    /** @var \Drupal\services\Entity\ServiceResource $resource */
    $resource = new ServiceResource([
      'service_plugin_id' => 'test:plugin:id',
      'service_endpoint_id' => 'test_endpoint_id',
      'formats' => [],
      'authentication' => [],
      'no_cache' => 1,
    ], 'service_endpoint_resource');
    $this
      ->assertEquals(1, $resource
      ->getNoCache(), 'Cache setting found.');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
ServiceResourceTest::testCanConstructDefaultResource public function
ServiceResourceTest::testCanConstructResourceNoCache1 public function
ServiceResourceTest::testCanConstructResourceNoCacheFalse public function
ServiceResourceTest::testCanConstructResourceNoCacheTrue public function
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340