Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 75 additions & 71 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,85 +4,89 @@ sudo: required

cache:
directories:
- $HOME/.composer/cache
- vendor
- $HOME/.composer/cache
- bin/.phpunit

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.2

env:
# plugin code
global:
PLUGIN_CODE=CategoryContent
matrix:
# ec-cube master
- ECCUBE_VERSION=master DB=mysql USER=root DBNAME=myapp_test DBPASS=' ' DBUSER=root
- ECCUBE_VERSION=master DB=pgsql USER=postgres DBNAME=myapp_test DBPASS=password DBUSER=postgres
- ECCUBE_VERSION=master DB=sqlite
# ec-cube 3.0.11
- ECCUBE_VERSION=3.0.11 DB=mysql USER=root DBNAME=myapp_test DBPASS=' ' DBUSER=root
- ECCUBE_VERSION=3.0.11 DB=pgsql USER=postgres DBNAME=myapp_test DBPASS=password DBUSER=postgres
matrix:
fast_finish: true
include:
- php: 5.3
dist: precise
exclude:
allow_failures:
- php: 5.3
env: ECCUBE_VERSION=master DB=sqlite
- php: 5.4
env: ECCUBE_VERSION=master DB=sqlite
- php: 5.5
env: ECCUBE_VERSION=master DB=sqlite
- php: 5.6
env: ECCUBE_VERSION=master DB=sqlite
- php: 7.0
env: ECCUBE_VERSION=master DB=sqlite

install:
- gem install mime-types -v 2.99.1
- gem install mailcatcher
BRANCH=4.0

before_script:
# archive plugin
- tar cvzf ${HOME}/${PLUGIN_CODE}.tar.gz ./*
# clone ec-cube
- git clone https://github.com/EC-CUBE/ec-cube.git
- cd ec-cube
# checkout version
- sh -c "if [ ! '${ECCUBE_VERSION}' = 'master' ]; then git checkout -b ${ECCUBE_VERSION} refs/tags/${ECCUBE_VERSION}; fi"
# update composer
- composer selfupdate
- composer install --dev --no-interaction -o
# install ec-cube
- sh -c "if [ '$DB' = 'mysql' ]; then sh ./eccube_install.sh mysql none; fi"
- sh -c "if [ '$DB' = 'pgsql' ]; then sh ./eccube_install.sh pgsql none; fi"
- sh -c "if [ '$DB' = 'sqlite' ]; then sh ./eccube_install.sh sqlite3 none; fi"
# install plugin
- php app/console plugin:develop install --path=${HOME}/${PLUGIN_CODE}.tar.gz
# enable plugin
- php app/console plugin:develop enable --code=${PLUGIN_CODE}
# mail catcher
- mailcatcher
before_install: &php_setup |
phpenv config-rm xdebug.ini || true
echo "opcache.enable_cli=1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
echo "apc.enable_cli=1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini

script:
# exec phpunit on ec-cube
- phpunit app/Plugin/${PLUGIN_CODE}/Tests
- if [[ $TRAVIS_PHP_VERSION =~ ^[7] ]]; then ./vendor/bin/phpunit -c app/Plugin/${PLUGIN_CODE}/phpunit.xml.dist --coverage-clover=coverage.clover ; fi
install_eccube: &install_eccube |
tar cvzf ${HOME}/${PLUGIN_CODE}.tar.gz ./*
git clone https://github.com/EC-CUBE/ec-cube.git
cd ec-cube
git checkout -b ${BRANCH} origin/${BRANCH}
composer selfupdate
composer install --dev --no-interaction -o --apcu-autoloader

after_script:
# disable plugin
- php app/console plugin:develop disable --code=${PLUGIN_CODE}
# uninstall plugin
- php app/console plugin:develop uninstall --code=${PLUGIN_CODE}
# re install plugin
- php app/console plugin:develop install --code=${PLUGIN_CODE}
# re enable plugin
- php app/console plugin:develop enable --code=${PLUGIN_CODE}
eccube_setup: &eccube_setup |
echo "APP_ENV=test" > .env
bin/console doctrine:database:create
bin/console doctrine:schema:create
bin/console eccube:fixtures:load
bin/console eccube:plugin:install --path=${HOME}/${PLUGIN_CODE}.tar.gz
bin/console eccube:plugin:enable --code=${PLUGIN_CODE}

after_success:
# for coveralls
- if [[ $TRAVIS_PHP_VERSION =~ ^[7] ]]; then php vendor/bin/coveralls -v -x coverage.clover ; fi
jobs:
fast_finish: true
include:
- stage: Inspection
php: 7.1
env: DATABASE_URL=postgres://postgres:password@localhost/cube4_dev DATABASE_SERVER_VERSION=9
install:
- *install_eccube
- *eccube_setup
script: vendor/bin/php-cs-fixer fix --config=.php_cs.dist --dry-run app/Plugin/${PLUGIN_CODE}
- &unit_test
stage: Unit Test
env: DATABASE_URL=mysql://root:@localhost/cube4_dev DATABASE_SERVER_VERSION=5
before_install:
- *php_setup
- gem install mime-types -v 2.99.1
- gem install mailcatcher
install:
- *install_eccube
- *eccube_setup
# mail catcher
- mailcatcher
script:
- ./bin/phpunit app/Plugin/${PLUGIN_CODE}/Tests
after_script:
# disable plugin
- bin/console eccube:plugin:disable --code=${PLUGIN_CODE}
# uninstall plugin
- bin/console eccube:plugin:uninstall --code=${PLUGIN_CODE}
# re install plugin
- bin/console eccube:plugin:install --code=${PLUGIN_CODE}
# re enable plugin
- bin/console eccube:plugin:enable --code=${PLUGIN_CODE}
- <<: *unit_test
env: DATABASE_URL=postgres://postgres:password@localhost/cube4_dev DATABASE_SERVER_VERSION=9
- &coverage
stage: Code Coverage
env: DATABASE_URL=postgres://postgres:password@localhost/cube4_dev DATABASE_SERVER_VERSION=9 COVERAGE=1
before_install:
- *php_setup
- gem install mime-types -v 2.99.1
- gem install mailcatcher
install:
- *install_eccube
- *eccube_setup
# mail catcher
- mailcatcher
script:
- ./bin/phpunit -c app/Plugin/${PLUGIN_CODE}/phpunit.xml.dist --coverage-clover=coverage.clover
after_success:
- php vendor/bin/php-coveralls -v -x coverage.clover
85 changes: 85 additions & 0 deletions CategoryContentEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
*
* http://www.lockon.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\CategoryContent;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormEvent;
use Eccube\Entity\Category;
use Eccube\Event\TemplateEvent;

/**
* Class CategoryContentEvent.
*/
class CategoryContentEvent implements EventSubscriberInterface
{
/**
* {@inheritdoc}
*
* @return array
*/
public static function getSubscribedEvents()
{
return [
FormEvents::PRE_SUBMIT => ['onFormPreSubmit', 10],
'@admin/Product/category.twig' => ['onTemplateAdminProductCategory', 10],
'Product/list.twig' => ['onTemplateProductList', 10],
];
}

/**
* On pre submit
*
* @param FormEvent $event
*/
public function onFormPreSubmit(FormEvent $event)
{
/** @var Category $Category */
$Category = $event->getForm()->getData();

if (!$Category instanceof Category || !$Category->getId()) {
return;
}

$submitData = $event->getData();
if (!isset($submitData['category_content_content'])) {
$submitData['category_content_content'] = $Category->getCategoryContentContent();
}
if (!isset($submitData['name'])) {
$submitData['name'] = $Category->getName();
}

$event->setData($submitData);
}

/**
* Append JS to add edit content button
*
* @param TemplateEvent $templateEvent
*/
public function onTemplateAdminProductCategory(TemplateEvent $templateEvent)
{
$templateEvent->addSnippet('@CategoryContent/admin/category.twig');
}

/**
* Append JS to display category content
*
* @param TemplateEvent $templateEvent
*/
public function onTemplateProductList(TemplateEvent $templateEvent)
{
$templateEvent->addSnippet('@CategoryContent/default/category_content.twig');
}
}
31 changes: 31 additions & 0 deletions CategoryContentTwigBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
*
* http://www.lockon.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\CategoryContent;

use Eccube\Common\EccubeTwigBlock;

class CategoryContentTwigBlock implements EccubeTwigBlock
{
/**
* {@inheritdoc}
*
* @return array
*/
public static function getTwigBlock()
{
return [
'@CategoryContent/default/block_category_content.twig',
];
}
}
71 changes: 0 additions & 71 deletions Entity/CategoryContent.php

This file was deleted.

Loading