Skip to content

Commit

Permalink
Merge pull request #3 from johnkrovitch/feature/tests
Browse files Browse the repository at this point in the history
Feature/tests
  • Loading branch information
johnkrovitch authored Nov 30, 2019
2 parents ddec035 + 18796af commit be8cdc5
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 28 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"php": "^7.2",
"johnkrovitch/orm-pack": "^0.1",
"lag/string-utils": "^1.2",
"oneup/uploader-bundle": "^2.1",
"symfony/form": "^3.0|^4.0",
"symfony/validator": "^3.0|^4.0",
"symfony/yaml": "^3.0|^4.0"
Expand Down
1 change: 1 addition & 0 deletions etc/make/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ tests.integration:
# PHPUnit
phpunit.run:
bin/phpunit
@echo "Results file generated file://$(shell pwd)/var/phpunit/coverage/index.html"

.PHONY: php-cs-fixer.install php-cs-fixer.run phpstan.run
# php-cs-fixer
Expand Down
20 changes: 10 additions & 10 deletions src/Form/Type/JQueryUploadType.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ class JQueryUploadType extends AbstractType
*/
protected $useMediaLibrary;

/**
* JQueryUploadType constructor.
*/
public function __construct(
UploaderHelper $uploaderHelper,
JQueryUploadTransformer $mediaUploadTransformer
) {
$this->uploaderHelper = $uploaderHelper;
$this->mediaUploadTransformer = $mediaUploadTransformer;
}
// /**
// * JQueryUploadType constructor.
// */
// public function __construct(
// UploaderHelper $uploaderHelper,
// JQueryUploadTransformer $mediaUploadTransformer
// ) {
// $this->uploaderHelper = $uploaderHelper;
// $this->mediaUploadTransformer = $mediaUploadTransformer;
// }

public function buildForm(FormBuilderInterface $builder, array $options)
{
Expand Down
109 changes: 109 additions & 0 deletions src/Form/Type/TinyMceType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

namespace JK\MediaBundle\Form\Type;

use Exception;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

class TinyMceType extends AbstractType
{
const ALLOWED_PLUGINS = [
'advlist',
'anchor',
'autolink',
'charmap',
'code',
'colorpicker',
'emoticons',
'fullscreen',
'directionality',
'hr',
'image',
'insertdatetime',
'imagetools',
'media',
'nonbreaking',
'link',
'lists',
'pagebreak',
'print',
'paste',
'preview',
'save',
'searchreplace',
'table',
'textpattern',
'template',
'textcolor',
'wordcount',
'visualblocks',
'visualchars',
];

/**
* @return string
*/
public function getParent()
{
return TextareaType::class;
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefaults([
'tinymce' => [],
])
->setAllowedTypes('tinymce', 'array')
->setNormalizer('tinymce', function (Options $options, $value) {
$resolver = new OptionsResolver();
$resolver
->setDefaults([
'branding' => false,
'language' => 'fr_FR',
'selector' => '#'.uniqid('tinymce-'),
'toolbar1' => 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter '
.'alignright alignjustify | bullist numlist outdent indent | link image toolbar2: print preview '
.'media | forecolor backcolor emoticons code | add_gallery add_image edit_image',
'image_advtab' => true,
'relative_urls' => false,
'convert_urls' => false,
'theme' => 'modern',
'skin' => 'lightgray',
'imagetools_toolbar' => 'rotateleft rotateright | flipv fliph | editimage imageoptions',
'body_class' => 'mceForceColors container',
'browser_spellcheck' => true,
'plugins' => self::ALLOWED_PLUGINS,
'height' => 400,
])
->setNormalizer('plugins', function (Options $options, $value) {
foreach ($value as $plugin) {
if (!in_array($plugin, self::ALLOWED_PLUGINS)) {
throw new Exception('Invalid tinymce plugins '.$plugin);
}
}

return $value;
})
->setAllowedTypes('plugins', 'array')
->setAllowedTypes('branding', 'boolean')
->setAllowedTypes('selector', 'string')
->setAllowedTypes('theme', 'string')
->setAllowedTypes('skin', 'string')
->setAllowedTypes('toolbar1', 'string')
->setAllowedTypes('image_advtab', 'boolean')
->setAllowedTypes('convert_urls', 'boolean')
->setAllowedTypes('imagetools_toolbar', 'string')
->setAllowedTypes('content_css', 'string')
->setAllowedTypes('body_class', 'string')
->setAllowedTypes('browser_spellcheck', 'boolean')
;

return $resolver->resolve($value);
})
;
}
}
18 changes: 11 additions & 7 deletions src/Resources/config/services/forms.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
services:
### Form Types ###
JK\MediaBundle\Form\Type\JQueryUploadType:
class: JK\MediaBundle\Form\Type\JQueryUploadType
arguments:
- '@oneup_uploader.templating.uploader_helper'
- '@JK\MediaBundle\Form\Transformer\JQueryUploadTransformer'
tags:
- {name: form.type}
# JK\MediaBundle\Form\Type\JQueryUploadType:
# class: JK\MediaBundle\Form\Type\JQueryUploadType
# arguments:
# - '@oneup_uploader.templating.uploader_helper'
# - '@JK\MediaBundle\Form\Transformer\JQueryUploadTransformer'
# tags:
# - {name: form.type}

JK\MediaBundle\Form\Type\MediaType:
class: JK\MediaBundle\Form\Type\MediaType
Expand All @@ -16,6 +16,10 @@ services:
tags:
- {name: form.type}

JK\MediaBundle\Form\Type\TinyMceType:
tags:
- {name: form.type}

### Form Transformers ###
JK\MediaBundle\Form\Transformer\JQueryUploadTransformer:
class: JK\MediaBundle\Form\Transformer\JQueryUploadTransformer
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services/uploaders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ services:
$uploadDirectory: '%jk_media.upload_path%'
$factory: '@JK\MediaBundle\Factory\MediaFactoryInterface'
$repository: '@JK\MediaBundle\Repository\MediaRepositoryInterface'
$mapping: ''
$mapping: []

JK\MediaBundle\Upload\Uploader\UploaderInterface: '@JK\MediaBundle\Upload\Uploader\Uploader'
7 changes: 0 additions & 7 deletions tests/MediaBundle/Fixtures/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ framework:

twig: ~

oneup_uploader:
mappings:
media_gallery:
frontend: blueimp
storage:
directory: '%kernel.root_dir%/../web/uploads/gallery'

doctrine:
dbal:
# configure these for your database server
Expand Down
1 change: 1 addition & 0 deletions tests/MediaBundle/JKMediaBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function testBuild()
continue;
}
$this->assertTrue($container->has($id), 'The service "'.$id.'" is not found');
$container->get($id);
}
}
}
3 changes: 1 addition & 2 deletions tests/MediaBundle/Kernel/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ public function registerBundles()
$bundles = [
// Dependencies
new FrameworkBundle(),

new DoctrineBundle(),
new TwigBundle(),

// My Bundle to test
new JKMediaBundle(),
new OneupUploaderBundle(),
];

return $bundles;
Expand Down

0 comments on commit be8cdc5

Please sign in to comment.