hasData example



  /** * Tests CRUD operations. * * @covers \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage::hasData */
  public function testCRUD() {
    $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();

    $storage = \Drupal::entityTypeManager()->getStorage('entity_test_label');
    $this->assertFalse($storage->hasData());

    // Verify default properties on a newly created empty entity.     $empty = EntityTestLabel::create();
    $this->assertNull($empty->id->value);
    $this->assertNull($empty->name->value);
    $this->assertNotEmpty($empty->uuid->value);
    $this->assertSame($default_langcode$empty->langcode->value);

    // Verify ConfigEntity properties/methods on the newly created empty entity.     $this->assertTrue($empty->isNew());
    $this->assertSame('entity_test_label', $empty->bundle());
    
/** * @return array<int, string> */
    public function requirements(): array
    {
        return [OrderAware::class];
    }

    public function handleFlow(StorableFlow $flow): void
    {
        if (!$flow->hasData(OrderAware::ORDER_ID)) {
            return;
        }

        $this->update($flow->getContext()$flow->getConfig()$flow->getData(OrderAware::ORDER_ID));
    }

    /** * @param array<string, mixed> $config */
    private function update(Context $context, array $config, string $orderId): void
    {
        

        $store = [
            'recipients' => ['firstName' => 'test'],
            'bcc' => 'bcc',
            'cc' => 'cc',
        ];

        $flow = new StorableFlow('test', Context::createDefaultContext()[MailAware::MAIL_STRUCT => $store]);

        $this->storer->restore($flow);

        static::assertTrue($flow->hasData(MailAware::MAIL_STRUCT));

        static::assertInstanceOf(MailRecipientStruct::class$flow->getData(MailAware::MAIL_STRUCT));

        static::assertEquals('test', $flow->getData(MailAware::MAIL_STRUCT)->getRecipients()['firstName']);
        static::assertEquals('bcc', $flow->getData(MailAware::MAIL_STRUCT)->getBcc());
        static::assertEquals('cc', $flow->getData(MailAware::MAIL_STRUCT)->getCc());
    }

    public function testRestoreHasDataOrder(): void
    {
        $flow = new StorableFlow('test', Context::createDefaultContext()[OrderAware::ORDER_ID => Uuid::randomHex()]);
        
/** * @return array<int, string> */
    public function requirements(): array
    {
        return [CustomerAware::class];
    }

    public function handleFlow(StorableFlow $flow): void
    {
        if (!$flow->hasData(CustomerAware::CUSTOMER_ID)) {
            return;
        }

        $this->update($flow->getContext()$flow->getConfig()$flow->getData(CustomerAware::CUSTOMER_ID));
    }

    /** * @param array<string, mixed> $config */
    private function update(Context $context, array $config, string $customerId): void
    {
        
/** * @return array<int, string> */
    public function requirements(): array
    {
        return [CustomerAware::class];
    }

    public function handleFlow(StorableFlow $flow): void
    {
        if (!$flow->hasData(CustomerAware::CUSTOMER_ID)) {
            return;
        }

        $this->update($flow->getContext()$flow->getConfig()$flow->getData(CustomerAware::CUSTOMER_ID));
    }

    /** * @param array<string, mixed> $config */
    private function update(Context $context, array $config, string $customerId): void
    {
        
/** * @return array<int, string> */
    public function requirements(): array
    {
        return [CustomerAware::class];
    }

    public function handleFlow(StorableFlow $flow): void
    {
        if (!$flow->hasData(CustomerAware::CUSTOMER_ID)) {
            return;
        }

        $this->update($flow->getContext()$flow->getConfig()$flow->getData(CustomerAware::CUSTOMER_ID));
    }

    /** * @param array<string, mixed> $config */
    private function update(Context $context, array $config, string $customerId): void
    {
        
    $entity = $storage->loadUnchanged($entity->id());
    $this->assertSame($original_properties$entity->toArray());
  }

  /** * Tests the hasData() method for config entity storage. * * @covers \Drupal\Core\Config\Entity\ConfigEntityStorage::hasData */
  public function testHasData() {
    $storage = \Drupal::entityTypeManager()->getStorage('config_test');
    $this->assertFalse($storage->hasData());

    // Add a test config entity and check again.     $storage->create(['id' => $this->randomMachineName()])->save();
    $this->assertTrue($storage->hasData());
  }

}
/** * @return array<int, string> */
    public function requirements(): array
    {
        return [OrderAware::class];
    }

    public function handleFlow(StorableFlow $flow): void
    {
        if (!$flow->hasData(OrderAware::ORDER)) {
            return;
        }

        /** @var OrderEntity $order */
        $order = $flow->getData(OrderAware::ORDER);

        $this->update($flow->getContext()$flow->getConfig()$order);
    }

    /** * @param array<string, mixed> $config */
/** * @return array<int, string> */
    public function requirements(): array
    {
        return [CustomerAware::class];
    }

    public function handleFlow(StorableFlow $flow): void
    {
        if (!$flow->hasData(CustomerAware::CUSTOMER_ID)) {
            return;
        }

        $this->update($flow->getContext()$flow->getConfig()$flow->getData(CustomerAware::CUSTOMER_ID));
    }

    /** * @return array<mixed> */
    private function getAffiliateAndCampaignCodeFromCustomerId(string $customerId): array
    {
        
/** * @return array<int, string> */
    public function requirements(): array
    {
        return [OrderAware::class];
    }

    public function handleFlow(StorableFlow $flow): void
    {
        if (!$flow->hasData(OrderAware::ORDER_ID)) {
            return;
        }

        $this->update($flow->getContext()$flow->getConfig()$flow->getData(OrderAware::ORDER_ID));
    }

    /** * @return array<mixed> */
    private function getAffiliateAndCampaignCodeFromOrderId(string $orderId): array
    {
        
/** * @return array<int, string> */
    public function requirements(): array
    {
        return [OrderAware::class];
    }

    public function handleFlow(StorableFlow $flow): void
    {
        if (!$flow->hasData(OrderAware::ORDER_ID)) {
            return;
        }

        $this->update($flow->getContext()$flow->getConfig()$flow->getData(OrderAware::ORDER_ID));
    }

    /** * @param array<string, mixed> $config */
    private function update(Context $context, array $config, string $orderId): void
    {
        
/** * @return array<int, string> */
    public function requirements(): array
    {
        return [OrderAware::class];
    }

    public function handleFlow(StorableFlow $flow): void
    {
        if (!$flow->hasData(OrderAware::ORDER_ID)) {
            return;
        }

        $this->update($flow->getContext()$flow->getConfig()$flow->getData(OrderAware::ORDER_ID));
    }

    /** * @param array<string, mixed> $config */
    private function update(Context $context, array $config, string $orderId): void
    {
        
$this->assertTrue($field_storage->hasdata(), 'There are entities with deleted field data.');
    $this->assertEquals(6, $this->storage->countFieldData($field_storage), 'There are 6 entities with deleted field data.');

    $entity_type = 'entity_test_rev';
    $this->createFieldWithStorage('_2', $entity_type);

    $entity_init = $this->container->get('entity_type.manager')
      ->getStorage($entity_type)
      ->create(['type' => $entity_type]);
    $cardinality = $this->fieldTestData->field_storage_2->getCardinality();

    $this->assertFalse($this->fieldTestData->field_storage_2->hasData(), 'There are no entities with field data.');
    $this->assertSame(0, $this->storageRev->countFieldData($this->fieldTestData->field_storage_2), 'There are 0 entities with field data.');

    // Create 1 entity with the field.     $entity = clone($entity_init);
    $values = $this->_generateTestFieldValues($this->fieldTestData->field_storage_2->getCardinality());
    $entity->{$this->fieldTestData->field_name_2} = $values;
    $entity->setNewRevision();
    $entity->save();
    $first_revision = $entity->getRevisionId();

    $this->assertTrue($this->fieldTestData->field_storage_2->hasData(), 'There are entities with field data.');
    
$this->entityFieldManager
      ->getFieldStorageDefinitions($this->entityType->id())
      ->willReturn($this->fieldDefinitions);

    $this->entityFieldManager
      ->getActiveFieldStorageDefinitions($this->entityType->id())
      ->willReturn($this->fieldDefinitions);

    $this->entityStorage = new SqlContentEntityStorage($this->entityType, $database$this->entityFieldManager->reveal()$this->cache, $this->languageManager, new MemoryCache()$this->entityTypeBundleInfo, $this->entityTypeManager->reveal());

    $result = $this->entityStorage->hasData();

    $this->assertTrue($result, 'hasData returned TRUE');
  }

  /** * Tests entity ID sanitization. */
  public function testCleanIds() {
    $valid_ids = [
      -1,
      0,
      
    $original_storage_class = $original->getStorageClass();
    if (!class_exists($original_storage_class)) {
      return TRUE;
    }

    // Data migration is not needed when only indexes changed, as they can be     // applied if there is data.     if (!$this->hasSharedTableStructureChange($entity_type$original)) {
      return FALSE;
    }

    return $this->storage->hasData();
  }

  /** * {@inheritdoc} */
  public function requiresFieldDataMigration(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) {
    return !$this->storage->countFieldData($original, TRUE);
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.