/**
  * {@inheritdoc}
  */
 public function setUp()
 {
     $entity_type_id_key = $this->randomMachineName();
     $entity_type_id = $this->randomMachineName();
     $this->database = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
     $this->fieldStorageDefinitions = array($entity_type_id_key => $this->getMock(FieldDefinitionInterface::class));
     $this->entityManager = $this->getMock(EntityManagerInterface::class);
     $this->entityManager->expects($this->atLeastOnce())->method('getFieldStorageDefinitions')->with($entity_type_id)->willReturn($this->fieldStorageDefinitions);
     $this->entityType = $this->getMock(ContentEntityTypeInterface::class);
     $this->entityType->expects($this->atLeastOnce())->method('id')->willReturn($entity_type_id);
     $this->storage = $this->getMockBuilder(SqlContentEntityStorage::class)->disableOriginalConstructor()->getMock();
     $this->sut = new PaymentStorageSchema($this->entityManager, $this->entityType, $this->storage, $this->database);
 }
 /**
  * Tests entity ID sanitization.
  */
 public function testCleanIds()
 {
     $valid_ids = array(-1, 0, 1, '-1', '0', '1', 0123, -0x1a, 0x1afc, -0b111, 0b101, '0123', '00123', '000123', '-0123', '-00123', '-000123', -10.0, -1.0, 0.0, 1.0, 10.0, -10.0, -1.0, 0.0, 1.0, 10.0);
     $this->fieldDefinitions = $this->mockFieldDefinitions(array('id'));
     $this->fieldDefinitions['id']->expects($this->any())->method('getType')->will($this->returnValue('integer'));
     $this->setUpEntityStorage();
     $this->entityType->expects($this->any())->method('getKey')->will($this->returnValueMap(array(array('id', 'id'))));
     $method = new \ReflectionMethod($this->entityStorage, 'cleanIds');
     $method->setAccessible(TRUE);
     $this->assertEquals($valid_ids, $method->invoke($this->entityStorage, $valid_ids));
     $invalid_ids = array('--1', '-0x1A', '0x1AFC', '-0b111', '0b101', 'a', FALSE, TRUE, NULL, '32acb', 123.123, 123.678);
     $this->assertEquals(array(), $method->invoke($this->entityStorage, $invalid_ids));
 }
 /**
  * @covers ::doLoadMultiple
  * @covers ::buildCacheId
  * @covers ::getFromPersistentCache
  * @covers ::setPersistentCache
  */
 public function testLoadMultiplePersistentCacheMiss()
 {
     $this->setUpModuleHandlerNoImplementations();
     $id = 1;
     $entity = $this->getMockBuilder('\\Drupal\\Tests\\Core\\Entity\\ContentEntityDatabaseStorageTestEntityInterface')->getMockForAbstractClass();
     $entity->expects($this->any())->method('id')->will($this->returnValue($id));
     $this->entityType->expects($this->any())->method('isPersistentlyCacheable')->will($this->returnValue(TRUE));
     $this->entityType->expects($this->atLeastOnce())->method('id')->will($this->returnValue($this->entityTypeId));
     $this->entityType->expects($this->atLeastOnce())->method('getClass')->will($this->returnValue(get_class($entity)));
     // In case of a cache miss, the entity is loaded from the storage and then
     // set in the cache.
     $key = 'values:' . $this->entityTypeId . ':1';
     $this->cache->expects($this->once())->method('getMultiple')->with(array($key))->will($this->returnValue(array()));
     $this->cache->expects($this->once())->method('set')->with($key, $entity, CacheBackendInterface::CACHE_PERMANENT, array($this->entityTypeId . '_values' => TRUE, 'entity_field_info' => TRUE));
     $entity_storage = $this->getMockBuilder('Drupal\\Core\\Entity\\ContentEntityDatabaseStorage')->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache))->setMethods(array('getFromStorage'))->getMock();
     $entity_storage->expects($this->once())->method('getFromStorage')->with(array($id))->will($this->returnValue(array($id => $entity)));
     $entities = $entity_storage->loadMultiple(array($id));
     $this->assertEquals($entity, $entities[$id]);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->entityType = $this->getMock('\\Drupal\\Core\\Entity\\ContentEntityTypeInterface');
     $this->entityType->expects($this->any())->method('id')->willReturn('entity_test');
 }