UnusedMediaSearchEvent example

$themeId1 => $themeConfig1,
            $themeId2 => $themeConfig2,
        ];

        $themeService = $this->createMock(ThemeService::class);
        $themeService->expects(static::exactly(2))
            ->method('getThemeConfiguration')
            ->willReturnCallback(function Dstring $themeId, ...$params) use ($themeConfigMap) {
                return $themeConfigMap[$themeId];
            });

        $event = new UnusedMediaSearchEvent([$mediaId1$mediaId2$mediaId3$mediaId4$mediaId5]);
        $listener = new UnusedMediaSubscriber($themeRepository$themeService);
        $listener->removeUsedMedia($event);

        static::assertEquals([$mediaId4$mediaId5]$event->getUnusedIds());
    }
}
'id' => $ids->create('media-' . $i),
                'fileName' => "Media $i",
                'fileExtension' => 'jpg',
                'mimeType' => 'image/jpeg',
                'fileSize' => 12345,
            ];
        }
        $this->mediaRepository->create($media, Context::createDefaultContext());

        $mediaIds = array_values($ids->all());

        $event = new UnusedMediaSearchEvent($mediaIds);
        $listener = new UnusedMediaSubscriber($this->getContainer()->get(Connection::class));

        $listener->removeUsedMedia($event);

        static::assertSame($mediaIds$event->getUnusedIds());
    }

    public function testMediaIdsFromAllPossibleLocationsAreRemovedFromEvent(): void
    {
        $mediaIds = $this->createContent();
        $event = new UnusedMediaSearchEvent($mediaIds);
        
$criteria->setOffset(($criteria->getOffset() + $limit) - \count($unusedIds));
        }
    }

    /** * @param array<string> $ids * * @return array<string> */
    private function dispatchEvent(array $ids): array
    {
        $event = new UnusedMediaSearchEvent(array_values($ids));
        $this->eventDispatcher->dispatch($event);

        return $event->getUnusedIds();
    }

    /** * Here we attempt to exclude entity associations that are extending the behaviour of the media entity rather than * referencing media. For example, `MediaThumbnailDefinition` adds thumbnail support, whereas `ProductMediaDefinition` * adds support for images to products. */
    private function isInsideTopLevelDomain(string $domain, EntityDefinition $definition): bool
    {
parent::setUp();

        $this->mediaRepository = $this->getContainer()->get('media.repository');
        $this->customFieldSetRepository = $this->getContainer()->get('custom_field_set.repository');
    }

    public function testMediaIdsAreNotRemovedWhenMediaIsNotReferenced(): void
    {
        $mediaIds = array_values($this->createMedia(10)->all());

        $event = new UnusedMediaSearchEvent($mediaIds);
        $listener = new CustomFieldsUnusedMediaSubscriber(
            $this->getContainer()->get(Connection::class),
            $this->getContainer()->get(DefinitionInstanceRegistry::class)
        );

        $listener->removeUsedMedia($event);

        static::assertSame($mediaIds$event->getUnusedIds());
    }

    public function testMediaIdsFromAllPossibleLocationsAreRemovedFromEvent(): void
    {
/** * @internal * * @covers \Shopware\Core\Content\Media\Event\UnusedMediaSearchEvent */
#[Package('buyers-experience')] class UnusedMediaSearchEventTest extends TestCase
{
    public function testGetIds(): void
    {
        $event = new UnusedMediaSearchEvent(['1', '2', '3']);
        static::assertEquals(['1', '2', '3']$event->getUnusedIds());
    }

    /** * @dataProvider removeIdsProvider * * @param array<string> $idsToRemove * @param array<string> $expectedIds */
    public function testRemoveIds(array $idsToRemove, array $expectedIds): void
    {
        
Home | Imprint | This part of the site doesn't use cookies.