Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/dev/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrebenchuk committed Aug 31, 2015
2 parents cb2c0bf + 9f6fd3e commit 9e804ba
Show file tree
Hide file tree
Showing 39 changed files with 1,671 additions and 144 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"lexik/maintenance-bundle": "v1.0.3",
"sylius/flow-bundle": "0.6.*",
"composer/composer": "1.0.0-p1",
"akeneo/batch-bundle": "~0.3",
"akeneo/batch-bundle": "0.4.2",
"nesbot/Carbon": "1.8.*",
"monolog/monolog": "1.8.*",
"ocramius/proxy-manager": "0.4.*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ class ActivityListChainProvider
/** @var EntityRoutingHelper */
protected $routingHelper;

/** @var array */
/** @var string[] */
protected $targetClasses;

/** @var string[] */
protected $activities;

/** @var string[] */
protected $ownerActivities;

/** @var HtmlTagHelper */
protected $htmlTagHelper;

Expand Down Expand Up @@ -76,6 +82,10 @@ public function __construct(
public function addProvider(ActivityListProviderInterface $provider)
{
$this->providers[$provider->getActivityClass()] = $provider;

$this->activities = null;
$this->ownerActivities = null;
$this->targetClasses = null;
}

/**
Expand All @@ -91,7 +101,7 @@ public function getProviders()
/**
* Get array with all target classes (entities where activity can be assigned to)
*
* @return array
* @return string[]
*/
public function getTargetEntityClasses()
{
Expand Down Expand Up @@ -121,7 +131,11 @@ public function getTargetEntityClasses()
*/
public function getSupportedActivities()
{
return array_keys($this->providers);
if (null === $this->activities) {
$this->activities = array_keys($this->providers);
}

return $this->activities;
}

/**
Expand All @@ -131,11 +145,14 @@ public function getSupportedActivities()
*/
public function getSupportedOwnerActivities()
{
$ownerClasses = [];
foreach ($this->providers as $provider) {
$ownerClasses[] = $provider->getAclClass();
if (null === $this->ownerActivities) {
$this->ownerActivities = [];
foreach ($this->providers as $provider) {
$this->ownerActivities[] = $provider->getAclClass();
}
}
return $ownerClasses;

return $this->ownerActivities;
}

/**
Expand All @@ -147,7 +164,11 @@ public function getSupportedOwnerActivities()
*/
public function isSupportedEntity($entity)
{
return in_array($this->doctrineHelper->getEntityClass($entity), array_keys($this->providers));
return in_array(
$this->doctrineHelper->getEntityClass($entity),
$this->getSupportedActivities(),
true
);
}

/**
Expand All @@ -159,7 +180,11 @@ public function isSupportedEntity($entity)
*/
public function isSupportedTargetEntity($entity)
{
return in_array($this->doctrineHelper->getEntityClass($entity), $this->getTargetEntityClasses());
return in_array(
$this->doctrineHelper->getEntityClass($entity),
$this->getTargetEntityClasses(),
true
);
}

/**
Expand All @@ -171,11 +196,11 @@ public function isSupportedTargetEntity($entity)
*/
public function isSupportedOwnerEntity($entity)
{
$ownerClasses = [];
foreach ($this->providers as $provider) {
$ownerClasses[] = $provider->getAclClass();
}
return in_array($this->doctrineHelper->getEntityClass($entity), $ownerClasses);
return in_array(
$this->doctrineHelper->getEntityClass($entity),
$this->getSupportedOwnerActivities(),
true
);
}

/**
Expand Down
35 changes: 25 additions & 10 deletions src/Oro/Bundle/DataGridBundle/Datasource/ResultRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
namespace Oro\Bundle\DataGridBundle\Datasource;

use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;

use Doctrine\Common\Inflector\Inflector;

class ResultRecord implements ResultRecordInterface
{
/**
* @var array
*/
/** @var array */
private $valueContainers = [];

/** @var PropertyAccessorInterface */
private $propertyAccessor;

/**
* @param mixed $data
*/
Expand Down Expand Up @@ -52,14 +54,15 @@ public function addData($data)
*/
public function getValue($name)
{
$propertyAccessor = PropertyAccess::createPropertyAccessor();
foreach ($this->valueContainers as $data) {
if (is_array($data) && array_key_exists($name, $data)) {
return $data[$name];
}

if (is_object($data)) {
return $propertyAccessor->getValue($data, Inflector::camelize($name));
if (is_array($data)) {
if (strpos($name, '[') === 0) {
return $this->getPropertyAccessor()->getValue($data, $name);
} elseif (array_key_exists($name, $data)) {
return $data[$name];
}
} elseif (is_object($data)) {
return $this->getPropertyAccessor()->getValue($data, Inflector::camelize($name));
}
}

Expand All @@ -79,4 +82,16 @@ public function getRootEntity()

return null;
}

/**
* @return PropertyAccessorInterface
*/
protected function getPropertyAccessor()
{
if (null === $this->propertyAccessor) {
$this->propertyAccessor = PropertyAccess::createPropertyAccessor();
}

return $this->propertyAccessor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function ($item) use ($translator) {
protected function getRawValue(ResultRecordInterface $record)
{
try {
$value = $record->getValue($this->getOr(self::DATA_NAME_KEY, $this->get(self::NAME_KEY)));
$value = $record->getValue($this->getOr(self::DATA_NAME_KEY) ?: $this->get(self::NAME_KEY));
} catch (\LogicException $e) {
// default value
$value = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getRawValue(ResultRecordInterface $record)
$label = null;

try {
$label = $record->getValue($this->getOr(self::DATA_NAME_KEY, $this->get(self::NAME_KEY)));
$label = $record->getValue($this->getOr(self::DATA_NAME_KEY) ?: $this->get(self::NAME_KEY));
} catch (\LogicException $e) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getRawValue(ResultRecordInterface $record)
$this->getOr(self::CONTEXT_KEY, []),
[
'record' => $record,
'value' => $record->getValue($this->getOr(self::DATA_NAME_KEY, $this->get(self::NAME_KEY))),
'value' => $record->getValue($this->getOr(self::DATA_NAME_KEY) ?: $this->get(self::NAME_KEY)),
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function setOptions(ActionConfiguration $options)
$options['route_parameters'] = [];
}

if (empty($options['confirmation'])) {
if (!isset($options['confirmation'])) {
$options['confirmation'] = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ define(function(require) {
listenFilterManager: function() {
var debouncedLayoutUpdate = _.debounce(_.bind(this.updateLayout, this), 10);
this.listenTo(this.main.filterManager, 'afterUpdateList', debouncedLayoutUpdate);
this.listenTo( this.main.filterManager, 'updateFilter', debouncedLayoutUpdate);
this.listenTo(this.main.filterManager, 'updateFilter', debouncedLayoutUpdate);
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ResultRecordTest extends \PHPUnit_Framework_TestCase
{
public function testAddData()
{
$originalContainer = ['first' => 1];
$originalContainer = ['first' => 1];
$additionalContainer = ['second' => 2];

$resultRecord = new ResultRecord($originalContainer);
Expand All @@ -20,4 +20,58 @@ public function testAddData()
$this->assertEquals($originalContainer['first'], $resultRecord->getValue('first'));
$this->assertEquals($additionalContainer['second'], $resultRecord->getValue('second'));
}

/**
* @dataProvider getValueProvider
*/
public function testGetValue($data, $itemName, $expectedValue)
{
$resultRecord = new ResultRecord($data);

$this->assertEquals($expectedValue, $resultRecord->getValue($itemName));
}

public function getValueProvider()
{
$obj = new \stdClass();
$obj->item1 = 'val1';

return [
[
'data' => [],
'itemName' => 'item1',
'expectedValue' => null
],
[
'data' => ['item1' => 'val1'],
'itemName' => 'item1',
'expectedValue' => 'val1'
],
[
'data' => $obj,
'itemName' => 'item1',
'expectedValue' => 'val1'
],
[
'data' => $obj,
'itemName' => 'item_1',
'expectedValue' => 'val1'
],
[
'data' => [],
'itemName' => '[item1][subItem1]',
'expectedValue' => null
],
[
'data' => ['item1' => []],
'itemName' => '[item1][subItem1]',
'expectedValue' => null
],
[
'data' => ['item1' => ['subItem1' => 'val1']],
'itemName' => '[item1][subItem1]',
'expectedValue' => 'val1'
],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Oro\Bundle\DataGridBundle\Tests\Unit\Extension\MassAction\Actions\Ajax;

use Oro\Bundle\DataGridBundle\Extension\Action\ActionConfiguration;
use Oro\Bundle\DataGridBundle\Extension\MassAction\Actions\Ajax\AjaxMassAction;

class AjaxMassActionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var AjaxMassAction
*/
protected $action;

/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->action = new AjaxMassAction();
}

/**
* @param array $source
* @param array $expected
* @dataProvider setOptionsDataProvider
*/
public function testSetOptions(array $source, array $expected)
{
$this->action->setOptions(ActionConfiguration::create($source));

$actual = $this->action->getOptions();
foreach ($expected as $name => $value) {
$this->assertEquals($value, $actual->offsetGet($name));
}
}

/**
* @return array
*/
public function setOptionsDataProvider()
{
return [
'confirmation is empty' => [
'source' => [
'handler' => 'test.handler',
],
'expected' => [
'confirmation' => true,
],
],
'confirmation is false' => [
'source' => [
'handler' => 'test.handler',
'confirmation' => false,
],
'expected' => [
'confirmation' => false,
],
],
];
}
}
Loading

0 comments on commit 9e804ba

Please sign in to comment.