Skip to content

Commit

Permalink
Merge pull request #175 from BitBagCommerce/dev
Browse files Browse the repository at this point in the history
Prepare 2.0.0 release
  • Loading branch information
bitbager authored Jul 16, 2018
2 parents 18aa1e2 + d0f5b67 commit 4f48af4
Show file tree
Hide file tree
Showing 31 changed files with 263 additions and 86 deletions.
44 changes: 44 additions & 0 deletions spec/Assigner/ChannelsAssignerSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace spec\BitBag\SyliusCmsPlugin\Assigner;

use BitBag\SyliusCmsPlugin\Assigner\ChannelsAssigner;
use BitBag\SyliusCmsPlugin\Assigner\ChannelsAssignerInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Channel\Model\ChannelsAwareInterface;
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;

final class ChannelsAssignerSpec extends ObjectBehavior
{
function let(ChannelRepositoryInterface $channelRepository): void
{
$this->beConstructedWith($channelRepository);
}

function it_is_initializable(): void
{
$this->shouldHaveType(ChannelsAssigner::class);
}

function it_implements_channels_assigner_interface(): void
{
$this->shouldHaveType(ChannelsAssignerInterface::class);
}

function it_assigns_channels(
ChannelRepositoryInterface $channelRepository,
ChannelInterface $webChannel,
ChannelInterface $posChannel,
ChannelsAwareInterface $channelsAware
): void
{
$channelRepository->findOneBy(['code' => 'web'])->willReturn($webChannel);
$channelRepository->findOneBy(['code' => 'pos'])->willReturn($posChannel);

$channelsAware->addChannel($webChannel)->shouldBeCalled();
$channelsAware->addChannel($posChannel)->shouldBeCalled();

$this->assign($channelsAware, ['web', 'pos']);
}
}
44 changes: 44 additions & 0 deletions spec/Assigner/ProductsAssignerSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace spec\BitBag\SyliusCmsPlugin\Assigner;

use BitBag\SyliusCmsPlugin\Assigner\ProductsAssigner;
use BitBag\SyliusCmsPlugin\Assigner\ProductsAssignerInterface;
use BitBag\SyliusCmsPlugin\Entity\ProductsAwareInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
use Sylius\Component\Core\Model\ProductInterface;

final class ProductsAssignerSpec extends ObjectBehavior
{
function let(ProductRepositoryInterface $productRepository): void
{
$this->beConstructedWith($productRepository);
}

function it_is_initializable(): void
{
$this->shouldHaveType(ProductsAssigner::class);
}

function it_implements_products_assigner_interface(): void
{
$this->shouldHaveType(ProductsAssignerInterface::class);
}

function it_assigns_products(
ProductRepositoryInterface $productRepository,
ProductInterface $mugProduct,
ProductInterface $tshirtProduct,
ProductsAwareInterface $productsAware
): void
{
$productRepository->findOneBy(['code' => 'mug'])->willReturn($mugProduct);
$productRepository->findOneBy(['code' => 't-shirt'])->willReturn($tshirtProduct);

$productsAware->addProduct($mugProduct)->shouldBeCalled();
$productsAware->addProduct($tshirtProduct)->shouldBeCalled();

$this->assign($productsAware, ['mug', 't-shirt']);
}
}
44 changes: 44 additions & 0 deletions spec/Assigner/SectionsAssignerSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace spec\BitBag\SyliusCmsPlugin\Assigner;

use BitBag\SyliusCmsPlugin\Assigner\SectionsAssigner;
use BitBag\SyliusCmsPlugin\Assigner\SectionsAssignerInterface;
use BitBag\SyliusCmsPlugin\Entity\SectionInterface;
use BitBag\SyliusCmsPlugin\Repository\SectionRepositoryInterface;
use PhpSpec\ObjectBehavior;
use BitBag\SyliusCmsPlugin\Entity\SectionableInterface;

final class SectionsAssignerSpec extends ObjectBehavior
{
function let(SectionRepositoryInterface $sectionRepository): void
{
$this->beConstructedWith($sectionRepository);
}

function it_is_initializable(): void
{
$this->shouldHaveType(SectionsAssigner::class);
}

function it_implements_sections_assigner_interface(): void
{
$this->shouldHaveType(SectionsAssignerInterface::class);
}

function it_assigns_sections(
SectionRepositoryInterface $sectionRepository,
SectionInterface $aboutSection,
SectionInterface $blogSection,
SectionableInterface $sectionsAware
): void
{
$sectionRepository->findOneBy(['code' => 'about'])->willReturn($aboutSection);
$sectionRepository->findOneBy(['code' => 'blog'])->willReturn($blogSection);

$sectionsAware->addSection($aboutSection)->shouldBeCalled();
$sectionsAware->addSection($blogSection)->shouldBeCalled();

$this->assign($sectionsAware, ['about', 'blog']);
}
}
3 changes: 0 additions & 3 deletions spec/Entity/MediaSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ function it_allows_access_via_properties(File $uploadedFile): void
$this->setFile($uploadedFile);
$this->getFile()->shouldReturn($uploadedFile);

$this->setOriginalPath('/media/video');
$this->getOriginalPath()->shouldReturn('/media/video');

$this->setMimeType('video/mp4');
$this->getMimeType()->shouldReturn('video/mp4');
}
Expand Down
2 changes: 1 addition & 1 deletion spec/Entity/MediaTranslationSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function it_implements_media_translation_interface(): void
$this->shouldHaveType(TranslationInterface::class);
}

function it_allows_access_via_properties(PageImageInterface $pageImage): void
function it_allows_access_via_properties(): void
{
$this->setName('Video');
$this->getName()->shouldReturn('Video');
Expand Down
44 changes: 44 additions & 0 deletions spec/Twig/Parser/ContentParserSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace spec\BitBag\SyliusCmsPlugin\Twig\Parser;

use BitBag\SyliusCmsPlugin\Twig\Extension\RenderBlockExtension;
use BitBag\SyliusCmsPlugin\Twig\Parser\ContentParser;
use BitBag\SyliusCmsPlugin\Twig\Parser\ContentParserInterface;
use PhpSpec\ObjectBehavior;

final class ContentParserSpec extends ObjectBehavior
{
function let(\Twig_Environment $twigEnvironment): void
{
$this->beConstructedWith($twigEnvironment, ['bitbag_cms_render_block']);
}

function it_is_initializable(): void
{
$this->shouldHaveType(ContentParser::class);
}

function it_implements_content_parser_interface(): void
{
$this->shouldHaveType(ContentParserInterface::class);
}

function it_parses_string_functions(
\Twig_Environment $twigEnvironment,
\Twig_Function $renderBlockFunction,
RenderBlockExtension $renderBlockExtension
): void
{
$twigEnvironment->getFunctions()->willReturn([
'bitbag_cms_render_block' => $renderBlockFunction,
]);
$renderBlockFunction->getCallable()->willReturn([$renderBlockExtension, 'renderBlock']);

$input = "Let's render! {{ bitbag_cms_render_block('intro', '@BitBagSyliusCmsPlugin/Shop/Block/show.html.twig') }}";

$renderBlockExtension->renderBlock('intro', '@BitBagSyliusCmsPlugin/Shop/Block/show.html.twig')->shouldBeCalled();

$this->parse($input);
}
}
2 changes: 1 addition & 1 deletion src/Assigner/ChannelsAssigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(ChannelRepositoryInterface $channelRepository)
public function assign(ChannelsAwareInterface $channelsAware, array $channelsCodes): void
{
foreach ($channelsCodes as $channelCode) {
/** @var ChannelInterface $channel */
/** @var ChannelInterface $channel|null */
$channel = $this->channelRepository->findOneBy(['code' => $channelCode]);

if (null !== $channel) {
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Action/Admin/ProductSearchAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function __construct(ProductRepositoryInterface $productRepository, ViewH

public function __invoke(Request $request): Response
{
$resource = $this->productRepository->findByNamePart($request->get('phrase', ''));
$view = View::create($resource);
$product = $this->productRepository->findByNamePart($request->get('phrase', ''));
$view = View::create($product);

$this->viewHandler->setExclusionStrategyGroups(['Autocomplete']);
$view->getContext()->enableMaxDepth();
Expand Down
9 changes: 7 additions & 2 deletions src/Controller/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
use Sylius\Component\Resource\ResourceActions;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
Expand Down Expand Up @@ -60,9 +62,12 @@ public function downloadMediaAction(Request $request): Response

$this->eventDispatcher->dispatch(ResourceActions::SHOW, $configuration, $media);

$response = new BinaryFileResponse($media->getOriginalPath());
$mediaPath = $this->getParameter('kernel.project_dir') . '/web' . $media->getPath();
$mediaFile = new File($mediaPath);
$mediaName = $media->getName() . '.' . $mediaFile->guessExtension();
$response = new BinaryFileResponse($mediaPath);

$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $mediaName);
$response->headers->set('Content-Type', $media->getMimeType());

return $response;
Expand Down
14 changes: 0 additions & 14 deletions src/Entity/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,8 @@ public function setPath(?string $path): void
$this->path = $path;
}

public function getOriginalPath(): ?string
{
return $this->originalPath;
}

public function setOriginalPath(?string $originalPath): void
{
$this->originalPath = $originalPath;
}

public function getFile(): ?File
{
if (null === $this->type && null !== $this->path) {
$this->file = new File($this->path);
}

return $this->file;
}

Expand Down
4 changes: 0 additions & 4 deletions src/Entity/MediaInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ public function getPath(): ?string;

public function setPath(?string $path): void;

public function getOriginalPath(): ?string;

public function setOriginalPath(?string $originalPath): void;

public function getFile(): ?File;

public function setFile(?File $file): void;
Expand Down
11 changes: 6 additions & 5 deletions src/Fixture/Factory/MediaFixtureFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use BitBag\SyliusCmsPlugin\Entity\MediaTranslationInterface;
use BitBag\SyliusCmsPlugin\MediaProvider\ProviderInterface;
use BitBag\SyliusCmsPlugin\Repository\MediaRepositoryInterface;
use BitBag\SyliusCmsPlugin\Resolver\MediaProviderResolverInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Symfony\Component\HttpFoundation\File\File;

Expand All @@ -29,8 +30,8 @@ final class MediaFixtureFactory implements FixtureFactoryInterface
/** @var FactoryInterface */
private $mediaTranslationFactory;

/** @var ProviderInterface */
private $imageProvider;
/** @var MediaProviderResolverInterface */
private $mediaProviderResolver;

/** @var MediaRepositoryInterface */
private $mediaRepository;
Expand All @@ -44,14 +45,14 @@ final class MediaFixtureFactory implements FixtureFactoryInterface
public function __construct(
FactoryInterface $mediaFactory,
FactoryInterface $mediaTranslationFactory,
ProviderInterface $imageProvider,
MediaProviderResolverInterface $mediaProviderResolver,
MediaRepositoryInterface $mediaRepository,
ProductsAssignerInterface $productsAssigner,
SectionsAssignerInterface $sectionsAssigner
) {
$this->mediaFactory = $mediaFactory;
$this->mediaTranslationFactory = $mediaTranslationFactory;
$this->imageProvider = $imageProvider;
$this->mediaProviderResolver = $mediaProviderResolver;
$this->mediaRepository = $mediaRepository;
$this->productsAssigner = $productsAssigner;
$this->sectionsAssigner = $sectionsAssigner;
Expand Down Expand Up @@ -86,7 +87,7 @@ private function createMedia(string $code, array $mediaData): void
$media->setEnabled($mediaData['enabled']);
$media->setFile(new File($mediaData['path']));

$this->imageProvider->upload($media);
$this->mediaProviderResolver->resolveProvider($media)->upload($media);

foreach ($mediaData['translations'] as $localeCode => $translation) {
/** @var MediaTranslationInterface $mediaTranslation */
Expand Down
4 changes: 2 additions & 2 deletions src/Fixture/Factory/PageFixtureFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

namespace BitBag\SyliusCmsPlugin\Fixture\Factory;

use BitBag\SyliusCmsPlugin\Entity\PageInterface;
use BitBag\SyliusCmsPlugin\Entity\PageImage;
use BitBag\SyliusCmsPlugin\Entity\PageInterface;
use BitBag\SyliusCmsPlugin\Entity\PageTranslationInterface;
use BitBag\SyliusCmsPlugin\Entity\SectionInterface;
use BitBag\SyliusCmsPlugin\Repository\PageRepositoryInterface;
Expand All @@ -39,7 +39,7 @@ final class PageFixtureFactory implements FixtureFactoryInterface
/** @var SectionRepositoryInterface */
private $sectionRepository;

/** @var ProductRepositoryInterface */
/** @var ImageUploaderInterface */
private $imageUploader;

/** @var ProductRepositoryInterface */
Expand Down
2 changes: 1 addition & 1 deletion src/Importer/PageImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
namespace BitBag\SyliusCmsPlugin\Importer;

use BitBag\SyliusCmsPlugin\Downloader\ImageDownloaderInterface;
use BitBag\SyliusCmsPlugin\Entity\PageInterface;
use BitBag\SyliusCmsPlugin\Entity\PageImage;
use BitBag\SyliusCmsPlugin\Entity\PageInterface;
use BitBag\SyliusCmsPlugin\Entity\PageTranslationInterface;
use BitBag\SyliusCmsPlugin\Resolver\ImporterChannelsResolverInterface;
use BitBag\SyliusCmsPlugin\Resolver\ImporterProductsResolverInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/MediaProvider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ public function render(MediaInterface $media, array $options = []): string

public function upload(MediaInterface $media): void
{
$this->uploader->upload($media, $this->pathPrefix);
$this->uploader->upload($media, $this->pathPrefix);
}
}
16 changes: 8 additions & 8 deletions src/Menu/ContentManagementMenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public function buildMenu(MenuBuilderEvent $menuBuilderEvent): void
->setLabelAttribute('icon', 'block layout')
;

$cmsRootMenuItem
->addChild('media', [
'route' => 'bitbag_sylius_cms_plugin_admin_media_index',
])
->setLabel('bitbag_sylius_cms_plugin.ui.media')
->setLabelAttribute('icon', 'file')
;

$cmsRootMenuItem
->addChild('pages', [
'route' => 'bitbag_sylius_cms_plugin_admin_page_index',
Expand All @@ -56,13 +64,5 @@ public function buildMenu(MenuBuilderEvent $menuBuilderEvent): void
->setLabel('bitbag_sylius_cms_plugin.ui.sections')
->setLabelAttribute('icon', 'grid layout')
;

$cmsRootMenuItem
->addChild('media', [
'route' => 'bitbag_sylius_cms_plugin_admin_media_index',
])
->setLabel('bitbag_sylius_cms_plugin.ui.media')
->setLabelAttribute('icon', 'file')
;
}
}
5 changes: 0 additions & 5 deletions src/Resources/config/doctrine/Media.orm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ BitBag\SyliusCmsPlugin\Entity\Media:
type: string
length: 250
unique: true
originalPath:
column: original_path
type: string
length: 250
unique: true
mimeType:
column: mime_typ
type: string
Expand Down
Loading

0 comments on commit 4f48af4

Please sign in to comment.