You are here

public function RestClientTest::testGetRecordTypes in Salesforce Suite 8.3

Same name and namespace in other branches
  1. 8.4 tests/src/Unit/RestClientTest.php \Drupal\Tests\salesforce\Unit\RestClientTest::testGetRecordTypes()
  2. 5.0.x tests/src/Unit/RestClientTest.php \Drupal\Tests\salesforce\Unit\RestClientTest::testGetRecordTypes()

@covers ::getRecordTypes

@expectedException Exception

File

tests/src/Unit/RestClientTest.php, line 454

Class

RestClientTest
@coversDefaultClass \Drupal\salesforce\Rest\RestClient @group salesforce

Namespace

Drupal\Tests\salesforce\Unit

Code

public function testGetRecordTypes() {
  $this
    ->initClient(array_merge($this->methods, [
    'query',
  ]));
  $sObjectType = $this
    ->randomMachineName();
  $developerName = $this
    ->randomMachineName();
  $rawQueryResult = [
    'totalSize' => 1,
    'done' => TRUE,
    'records' => [
      0 => [
        'attributes' => [
          'type' => 'Foo',
          'url' => 'Bar',
        ],
        'SobjectType' => $sObjectType,
        'DeveloperName' => $developerName,
        'Id' => $this->salesforce_id,
      ],
    ],
  ];
  $recordTypes = [
    $sObjectType => [
      $developerName => new SObject($rawQueryResult['records'][0]),
    ],
  ];
  $cache = (object) [
    'created' => time(),
    'data' => $recordTypes,
  ];
  $this->cache
    ->expects($this
    ->at(1))
    ->method('get')
    ->willReturn(FALSE);
  $this->cache
    ->expects($this
    ->at(2))
    ->method('get')
    ->willReturn($cache);
  $this->cache
    ->expects($this
    ->at(3))
    ->method('get')
    ->willReturn($cache);
  $this->client
    ->expects($this
    ->once())
    ->method('query')
    ->willReturn(new SelectQueryResult($rawQueryResult));
  $this
    ->assertEquals($recordTypes, $this->client
    ->getRecordTypes());
  $this
    ->assertEquals($recordTypes[$sObjectType], $this->client
    ->getRecordTypes($sObjectType));
  $this->client
    ->getRecordTypes('fail');
}