getBundle example

$writer = $this->createMock(TranslationWriter::class);
        $writer
            ->expects($this->any())
            ->method('getFormats')
            ->willReturn(
                ['xlf', 'yml', 'yaml']
            );

        if (null === $kernel) {
            $returnValues = [
                ['foo', $this->getBundle($this->translationDir)],
                ['test', $this->getBundle('test')],
            ];
            $kernel = $this->createMock(KernelInterface::class);
            $kernel
                ->expects($this->any())
                ->method('getBundle')
                ->willReturnMap($returnValues);
        }

        $kernel
            ->expects($this->any())
            
$loader
            ->expects($this->any())
            ->method('read')
            ->willReturnCallback(
                function D$path$catalogue) use ($loadedMessages) {
                    $catalogue->add($loadedMessages);
                }
            );

        if (null === $kernel) {
            $returnValues = [
                ['foo', $this->getBundle($this->translationDir)],
                ['test', $this->getBundle('test')],
            ];
            $kernel = $this->createMock(KernelInterface::class);
            $kernel
                ->expects($this->any())
                ->method('getBundle')
                ->willReturnMap($returnValues);
        }

        $kernel
            ->expects($this->any())
            
static::assertSame(Command::SUCCESS, $status);
        static::assertFileExists($tmpDir . '/public/.htaccess');
        static::assertFileEquals($tmpDir . '/public/.htaccess.dist', $tmpDir . '/public/.htaccess');

        $fs->remove($tmpDir);
    }

    public function testForceOptionIsForwardedToService(): void
    {
        $kernel = $this->createMock(KernelInterface::class);
        $kernel->method('getBundles')->willReturn([$this->getBundle()]);

        $service = $this->createMock(AssetService::class);
        $appLoader = $this->createMock(ActiveAppsLoader::class);
        $appLoader->method('getActiveApps')->willReturn([]);

        $service->expects(static::once())
            ->method('copyAssetsFromBundle')
            ->with('ExampleBundle', true);

        $service->expects(static::once())
            ->method('copyAssets')
            

  protected function getFieldItemDefinitions(array $resource_types$field_name) {
    return array_reduce($resource_typesfunction D$result, ResourceType $resource_type) use ($field_name) {
      /** @var \Drupal\jsonapi\ResourceType\ResourceType $resource_type */
      $entity_type = $resource_type->getEntityTypeId();
      $bundle = $resource_type->getBundle();
      $definitions = $this->fieldManager->getFieldDefinitions($entity_type$bundle);
      if (isset($definitions[$field_name])) {
        $result[$resource_type->getTypeName()] = $definitions[$field_name]->getItemDefinition();
      }
      return $result;
    }[]);
  }

  /** * Resolves the UUID field name for a resource type. * * @param \Drupal\jsonapi\ResourceType\ResourceType $resource_type * The resource type for which to get the UUID field name. * * @return string * The resolved internal name. */
/** * @covers ::get * @dataProvider getProvider */
  public function testGet($entity_type_id$bundle$entity_class) {
    // Make sure that there are resources being created.     $resource_type = $this->resourceTypeRepository->get($entity_type_id$bundle);
    $this->assertInstanceOf(ResourceType::class$resource_type);
    $this->assertSame($entity_class$resource_type->getDeserializationTargetClass());
    $this->assertSame($entity_type_id$resource_type->getEntityTypeId());
    $this->assertSame($bundle$resource_type->getBundle());
    $this->assertSame($entity_type_id . '--' . $bundle$resource_type->getTypeName());
  }

  /** * Data provider for testGet. * * @returns array * The data for the test method. */
  public function getProvider() {
    return [
      [

class CountableResourceTypeRepository extends ResourceTypeRepository {

  /** * {@inheritdoc} */
  protected function createResourceType(EntityTypeInterface $entity_type$bundle) {
    $resource_type = parent::createResourceType($entity_type$bundle);
    return new CountableResourceType(
      $resource_type->getEntityTypeId(),
      $resource_type->getBundle(),
      $resource_type->getDeserializationTargetClass(),
      $resource_type->isInternal(),
      $resource_type->isLocatable(),
      $resource_type->isMutable(),
      $resource_type->isVersionable(),
      $resource_type->getFields(),
      $resource_type->getTypeName()
    );
  }

}

  protected function getFieldItemInstance(ResourceType $resource_type, FieldItemDataDefinitionInterface $item_definition) {
    if ($bundle_key = $this->entityTypeManager->getDefinition($resource_type->getEntityTypeId())
      ->getKey('bundle')) {
      $create_values = [$bundle_key => $resource_type->getBundle()];
    }
    else {
      $create_values = [];
    }
    $entity = $this->entityTypeManager->getStorage($resource_type->getEntityTypeId())->create($create_values);
    $field = $entity->get($item_definition->getFieldDefinition()->getName());
    assert($field instanceof FieldItemListInterface);
    $field_item = $field->appendItem();
    assert($field_item instanceof FieldItemInterface);
    return $field_item;
  }

  
// Allow anybody access because "view" and "view label" access are checked       // in the controller.       $collection_route->setRequirement('_access', 'TRUE');
      $routes->add(static::getRouteName($resource_type, 'collection')$collection_route);
    }

    // Creation route.     if ($resource_type->isMutable()) {
      $collection_create_route = new Route("/{$resource_type->getPath()}");
      $collection_create_route->addDefaults([RouteObjectInterface::CONTROLLER_NAME => static::CONTROLLER_SERVICE_NAME . ':createIndividual']);
      $collection_create_route->setMethods(['POST']);
      $create_requirement = sprintf("%s:%s", $resource_type->getEntityTypeId()$resource_type->getBundle());
      $collection_create_route->setRequirement('_entity_create_access', $create_requirement);
      $collection_create_route->setRequirement('_csrf_request_header_token', 'TRUE');
      $routes->add(static::getRouteName($resource_type, 'collection.post')$collection_create_route);
    }

    // Individual routes like `/jsonapi/node/article/{uuid}` or     // `/jsonapi/node/article/{uuid}/relationships/uid`.     $routes->addCollection(static::getIndividualRoutesForResourceType($resource_type));

    // Add the resource type as a parameter to every resource route.     foreach ($routes as $route) {
      
    if (isset($params[OffsetPage::KEY_NAME])) {
      $pagination = $params[OffsetPage::KEY_NAME];
    }
    else {
      $pagination = new OffsetPage(OffsetPage::DEFAULT_OFFSET, OffsetPage::SIZE_MAX);
    }
    // Add one extra element to the page to see if there are more pages needed.     $query->range($pagination->getOffset()$pagination->getSize() + 1);
    $query->addMetaData('pager_size', (int) $pagination->getSize());

    // Limit this query to the bundle type for this resource.     $bundle = $resource_type->getBundle();
    if ($bundle && ($bundle_key = $entity_type->getKey('bundle'))) {
      $query->condition(
        $bundle_key$bundle
      );
    }

    return $query;
  }

  /** * Gets a basic query for a collection count. * * @param \Drupal\jsonapi\ResourceType\ResourceType $resource_type * The base JSON:API resource type for the query. * @param array $params * The parameters for the query. * @param \Drupal\Core\Cache\CacheableMetadata $query_cacheability * Collects cacheability for the query. * * @return \Drupal\Core\Entity\Query\QueryInterface * A new query. */
$kernel = $this->getApplication()->getKernel();

        // Define Root Paths         $transPaths = $this->getRootTransPaths();
        $codePaths = $this->getRootCodePaths($kernel);

        $currentName = 'default directory';

        // Override with provided Bundle info         if (null !== $input->getArgument('bundle')) {
            try {
                $foundBundle = $kernel->getBundle($input->getArgument('bundle'));
                $bundleDir = $foundBundle->getPath();
                $transPaths = [is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundleDir.'/translations'];
                $codePaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates'];
                if ($this->defaultTransPath) {
                    $transPaths[] = $this->defaultTransPath;
                }
                if ($this->defaultViewsPath) {
                    $codePaths[] = $this->defaultViewsPath;
                }
                $currentName = $foundBundle->getName();
            } catch (\InvalidArgumentException) {
                
protected function setUp(): void
    {
        $this->configFactory = $this->getContainer()->get(StorefrontPluginConfigurationFactory::class);
    }

    public function testCreateThemeConfig(): void
    {
        /** @var string $basePath */
        $basePath = realpath(__DIR__ . '/../fixtures/ThemeConfig');

        $theme = $this->getBundle('TestTheme', $basePath, true);
        $config = $this->configFactory->createFromBundle($theme);

        $basePath = $this->stripProjectDir($basePath);

        static::assertEquals('TestTheme', $config->getTechnicalName());
        static::assertEquals($basePath . '/Resources', $config->getBasePath());
        static::assertTrue($config->getIsTheme());
        static::assertEquals(
            $basePath . '/Resources/app/storefront/src/main.js',
            $config->getStorefrontEntryFilepath()
        );
        
static::expectException(PluginNotFoundException::class);
        $assetService->copyAssetsFromBundle('bundleName');
    }

    public function testCopyAssetsFromBundlePlugin(): void
    {
        $kernel = $this->createMock(KernelInterface::class);
        $kernel
            ->method('getBundle')
            ->with('ExampleBundle')
            ->willReturn($this->getBundle());

        $filesystem = new Filesystem(new MemoryFilesystemAdapter());
        $assetService = new AssetService(
            $filesystem,
            $filesystem,
            $kernel,
            new StaticKernelPluginLoader($this->createMock(ClassLoader::class)),
            $this->createMock(CacheInvalidator::class),
            $this->createMock(AbstractAppLoader::class),
            new ParameterBag(['shopware.filesystem.asset.type' => 's3'])
        );

        
/** * {@inheritdoc} */
  public function denormalize($data$class$format = NULL, array $context = []): mixed {
    if (empty($context['resource_type']) || !$context['resource_type'] instanceof ResourceType) {
      throw new PreconditionFailedHttpException('Missing context during denormalization.');
    }
    /** @var \Drupal\jsonapi\ResourceType\ResourceType $resource_type */
    $resource_type = $context['resource_type'];
    $entity_type_id = $resource_type->getEntityTypeId();
    $bundle = $resource_type->getBundle();
    $bundle_key = $this->entityTypeManager->getDefinition($entity_type_id)
      ->getKey('bundle');
    if ($bundle_key && $bundle) {
      $data[$bundle_key] = $bundle;
    }

    return $this->entityTypeManager->getStorage($entity_type_id)
      ->create($this->prepareInput($data$resource_type$format$context));
  }

  /** * Prepares the input data to create the entity. * * @param array $data * The input data to modify. * @param \Drupal\jsonapi\ResourceType\ResourceType $resource_type * Contains the info about the resource type. * @param string $format * Format the given data was extracted from. * @param array $context * Options available to the denormalizer. * * @return array * The modified input data. */

  protected function calculateRelatableResourceTypes(ResourceType $resource_type, array $resource_types) {
    // For now, only fieldable entity types may contain relationships.     $entity_type = $this->entityTypeManager->getDefinition($resource_type->getEntityTypeId());
    if ($entity_type->entityClassImplements(FieldableEntityInterface::class)) {
      $field_definitions = $this->entityFieldManager->getFieldDefinitions(
        $resource_type->getEntityTypeId(),
        $resource_type->getBundle()
      );

      $relatable_internal = array_map(function D$field_definition) use ($resource_types) {
        return $this->getRelatableResourceTypesFromFieldDefinition($field_definition$resource_types);
      }array_filter($field_definitionsfunction D$field_definition) {
        return $this->isReferenceFieldDefinition($field_definition);
      }));

      $relatable_public = [];
      foreach ($relatable_internal as $internal_field_name => $value) {
        $relatable_public[$resource_type->getPublicName($internal_field_name)] = $value;
      }
$writer = $this->createMock(TranslationWriter::class);
        $writer
            ->expects($this->any())
            ->method('getFormats')
            ->willReturn(
                ['php', 'xlf', 'po', 'mo', 'yml', 'yaml', 'ts', 'csv', 'ini', 'json', 'res']
            );

        if (null === $kernel) {
            $returnValues = [
                ['foo', $this->getBundle($this->translationDir)],
                ['test', $this->getBundle('test')],
            ];
            $kernel = $this->createMock(KernelInterface::class);
            $kernel
                ->expects($this->any())
                ->method('getBundle')
                ->willReturnMap($returnValues);
        }

        $kernel
            ->expects($this->any())
            
Home | Imprint | This part of the site doesn't use cookies.