Skip to content

Commit

Permalink
[WIP] Tests (#78)
Browse files Browse the repository at this point in the history
* #73 initialize test structure

* #73: add routing config

* #73: add unit tests for manager

* #73: add register / login / logout functional tests

* #73: add register / login / logout functional tests

* #73: add form and area tests

* #73: add form and area tests

* #73: add restriction tests

* #73: add restriction tests

* #73: remove .htaccess involving tests

* #73: add pimcore 5.6 to tests

* #73: fix tests for pimcore 5.6.0

* #73: fix tests for pimcore 5.6.0

* #73: fix tests for pimcore 5.6.0

* #73: fix tests for pimcore 5.6.0: improve query resource fetcher

* #73: make controller requested services public
  • Loading branch information
solverat authored Jan 14, 2019
1 parent f4cacf1 commit 3517be2
Show file tree
Hide file tree
Showing 101 changed files with 5,006 additions and 144 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ Vagrantfile
.vagrant
php-cgi.core
.sass-cache

# codeception (only stage *.dist.yml config files)
/codeception.yml
/tests/codeception.yml
/tests/*.suite.yml
/tests/_output/*
/tests/_data/*
!/tests/_data/.gitkeep
/tests/_support/_generated/*
69 changes: 69 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
sudo: required
language: php
addons:
chrome: stable
mariadb: '10.1'

env:
global:
- PIMCORE_ENVIRONMENT=test
- DACHCOM_BUNDLE_TEST=1
- PIMCORE_TEST_URL=http://localhost
- CHROME_DRIVER_VERSION=2.41
- SELENIUM_VERSION=3.6.0
- WEBDRIVER_HOST=localhost
- WEBDRIVER_URL="http://localhost:8080/"
- PIMCORE_TEST_DB_DSN="mysql://root@localhost/dachcom_bundle_test"
- PIMCORE_CLASS_DIRECTORY="${TRAVIS_BUILD_DIR}/lib/Members/tests/_output/var/classes/DataObject"
- SYMFONY_DEPRECATIONS_HELPER=weak
matrix:
include:
# pimcore 5.4.x
- sudo: required
php: 7.1
env:
- PIMCORE_SKELETON_BRANCH="tags/v1.0.4"
- sudo: required
php: 7.2
env:
- PIMCORE_SKELETON_BRANCH="tags/v1.0.4"
# pimcore 5.5.x
- sudo: required
php: 7.1
env:
- PIMCORE_SKELETON_BRANCH="tags/v1.0.5"
- sudo: required
php: 7.2
env:
- PIMCORE_SKELETON_BRANCH="tags/v1.0.5"
# pimcore 5.6.x
- sudo: required
php: 7.1
env:
- PIMCORE_SKELETON_BRANCH="tags/v1.1.0"
- sudo: required
php: 7.2
env:
- PIMCORE_SKELETON_BRANCH="tags/v1.1.0"
fast_finish: true

cache:
directories:
- $HOME/.composer/cache

install:
- tests/etc/travis/install

after_failure:
- cd $TRAVIS_BUILD_DIR
- cat ./lib/Members/tests/_output/*

script:
- '$HOME/chromedriver --url-base=/wd/hub &'
- 'php ${TRAVIS_BUILD_DIR}/bin/console server:start 127.0.0.1:8080'
- 'php ${TRAVIS_BUILD_DIR}/bin/console server:status'
- etc/travis/script

notifications:
email:
- [email protected]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Add frontend user authentication and document restriction to pimcore 5.0.
[![Software License](https://img.shields.io/badge/license-GPLv3-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Latest Release](https://img.shields.io/packagist/v/dachcom-digital/members.svg?style=flat-square)](https://packagist.org/packages/dachcom-digital/members)
[![Scrutinizer](https://img.shields.io/scrutinizer/g/dachcom-digital/pimcore-members.svg?style=flat-square)](https://www.scrutinizer-ci.com/g/dachcom-digital/pimcore-members/)
[![Travis](https://img.shields.io/travis/dachcom-digital/pimcore-members/master.svg?style=flat-square)](https://travis-ci.org/dachcom-digital/pimcore-members)

## Requirements
* Pimcore 5.
Expand Down
7 changes: 7 additions & 0 deletions codeception.dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
settings:
memory_limit: -1
colors: true
paths:
log: var/logs
include:
- tests
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
}
},
"require": {
"pimcore/core-version": "^5.0.0"
"pimcore/core-version": "^5.4.0"
}
}
3 changes: 2 additions & 1 deletion src/MembersBundle/Command/ClassInstallerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$helper = $this->getHelper('question');
$question = new ConfirmationQuestion('Do you want to install the classes now? (y/n) ', false);

if (!$helper->ask($input, $output, $question)) {
if ($input->isInteractive() === true && !$helper->ask($input, $output, $question)) {
return;
}

foreach ($this->getClasses() as $className => $path) {

$class = new ClassDefinition();
Expand Down
35 changes: 0 additions & 35 deletions src/MembersBundle/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ public function setConfig($config = [])
$this->config = $config;
}

/**
* @return array
*/
public function getConfigNode()
{
return $this->config;
}

/**
* @return mixed
*/
Expand All @@ -63,33 +55,6 @@ public function getConfig($slot)
return $this->config[$slot];
}

public function getLocalizedPath($slot, $locale = null)
{
$data = $this->getConfig($slot);

$event = new GenericEvent($this, [
'route' => $data
]);

\Pimcore::getEventDispatcher()->dispatch(
'members.path.route',
$event
);

if ($event->hasArgument('url')) {
$url = $event->getArgument('url');
} else {
$lang = '';
if (!empty($locale)) {
$lang = (string)$locale;
}

$url = str_replace('/%lang', '/' . $lang, $data);
}

return $url;
}

/**
* @param string $bundleName
*
Expand Down
142 changes: 88 additions & 54 deletions src/MembersBundle/CoreExtension/GroupMultiselect.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,58 @@

use Pimcore\Model\Element;
use Pimcore\Model\DataObject;
use Pimcore\Model\DataObject\ClassDefinition\Data\Relations\AbstractRelations;
use MembersBundle\Pimcore\DataObject\ClassDefinition\Data\Traits\ResourceDataTrait;
use MembersBundle\Pimcore\DataObject\ClassDefinition\Data\QueryResourcePersistenceAwareInterface;

class GroupMultiselect extends DataObject\ClassDefinition\Data\Relations\AbstractRelations
class GroupMultiselect extends AbstractRelations implements QueryResourcePersistenceAwareInterface
{
use ResourceDataTrait;

/**
* Static type of this element.
*
* @var string
*/
public $fieldtype = 'membersGroupMultiselect';

/**
* Type for the column to query
*
* @var string
*/
public $queryColumnType = 'text';

/**
* Type for the generated phpdoc
*
* @var string
*/
public $phpdocType = 'array';

/**
* @var bool
*/
public $relationType = true;

/**
* {@inheritdoc}
*/
public function getQueryColumnType()
{
return 'text';
}

/**
* {@inheritdoc}
*/
public function setQueryColumnType($queryColumnType)
{
$this->queryColumnType = $queryColumnType;

return $this;
}

/**
* @param string $data
* @param null $object
Expand Down Expand Up @@ -49,6 +86,7 @@ public function getDataForEditmode($data, $object = null, $params = [])
* @param array $data
* @param null|DataObject\AbstractObject $object
* @param mixed $params
*
* @return array
*/
public function getDataFromEditmode($data, $object = null, $params = [])
Expand All @@ -75,40 +113,7 @@ public function getDataFromEditmode($data, $object = null, $params = [])
* @param $data
* @param null $object
* @param array $params
* @return array|null
*/
public function getDataForResource($data, $object = null, $params = [])
{
$return = [];

if (is_array($data) && count($data) > 0) {
$counter = 1;
foreach ($data as $group) {
$return[] = [
'src_id' => $object->getId(),
'dest_id' => $group->getId(),
'type' => 'object',
'fieldname' => $this->getName(),
'index' => $counter
];

$counter++;
}

return $return;
} elseif (is_array($data) and count($data) === 0) {
//give empty array if data was not null
return [];
} else {
//return null if data was null - this indicates data was not loaded
return null;
}
}

/**
* @param $data
* @param null $object
* @param array $params
*
* @return null|string
* @throws \Exception
*/
Expand Down Expand Up @@ -140,6 +145,7 @@ public function getDataForQueryResource($data, $object = null, $params = [])
/**
* @param $object
* @param array $params
*
* @return array|mixed|null
*/
public function preGetData($object, $params = [])
Expand All @@ -158,46 +164,74 @@ public function preGetData($object, $params = [])
* @param array $data
* @param null $object
* @param array $params
*
* @return array
*/
public function getDataFromResource($data = [], $object = null, $params = [])
public function loadData($data, $object = null, $params = [])
{
$elements = [];
if (is_array($data) && count($data) > 0) {
foreach ($data as $element) {
$e = null;
if ($element['type'] == 'object') {
$e = DataObject::getById($element['dest_id']);
}
if ($e instanceof Element\ElementInterface) {
$elements[] = $e;
}
}
}

return $elements;
return $this->getDataFromResource($data, $object, $params);
}

/**
* @param array $data
* @param null $object
* @param array $params
*
* @return array
*/
public function loadData($data, $object = null, $params = [])
public function prepareDataForPersistence($data, $object = null, $params = [])
{
return $this->getDataFromResource($data, $object, $params);
$return = [];

if (is_array($data) && count($data) > 0) {
$counter = 1;
foreach ($data as $object) {
if ($object instanceof Element\ElementInterface) {
$return[] = [
'dest_id' => $object->getId(),
'type' => Element\Service::getElementType($object),
'fieldname' => $this->getName(),
'index' => $counter
];
}
$counter++;
}

return $return;
} elseif (is_array($data) and count($data) === 0) {
//give empty array if data was not null
return [];
} else {
//return null if data was null - this indicates data was not loaded
return null;
}
}

/**
* BC Layer for pimcore < 5.6
*
* @param array $data
* @param null $object
* @param array $params
*
* @return array
*/
public function prepareDataForPersistence($data, $object = null, $params = [])
public function getDataFromResource($data = [], $object = null, $params = [])
{
return $this->getDataFromResource($data, $object, $params);
$elements = [];
if (is_array($data) && count($data) > 0) {
foreach ($data as $element) {
$e = null;
if ($element['type'] == 'object') {
$e = DataObject::getById($element['dest_id']);
}
if ($e instanceof Element\ElementInterface) {
$elements[] = $e;
}
}
}

return $elements;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public function action(Info $info)
/** @var $formFactory \MembersBundle\Form\Factory\FactoryInterface */
$form = $this->formFactory->createUnnamedForm($formParams);

$view->form = $form->createView();
$view->getParameters()->set('form', $form->createView());
foreach ($params as $key => $param) {
$view->{$key} = $param;
$view->getParameters()->set($key, $param);
}
}

Expand Down
Loading

0 comments on commit 3517be2

Please sign in to comment.