Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/dev/1.8' into 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrebenchuk committed Sep 28, 2015
2 parents 67fe240 + a64265c commit 0c8d1af
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
use Oro\Bundle\SecurityBundle\Annotation\AclAncestor;
use Oro\Bundle\SecurityBundle\Exception\ForbiddenException;
use Oro\Bundle\SoapBundle\Controller\Api\Rest\RestController;
use Oro\Bundle\SoapBundle\Request\Parameters\Filter\ChainParameterFilter;
use Oro\Bundle\SoapBundle\Request\Parameters\Filter\BooleanParameterFilter;
use Oro\Bundle\SoapBundle\Request\Parameters\Filter\EntityClassParameterFilter;
use Oro\Bundle\SoapBundle\Request\Parameters\Filter\StringToArrayParameterFilter;

use OroCRM\Bundle\ChannelBundle\Event\ChannelDeleteEvent;
use OroCRM\Bundle\ChannelBundle\Event\ChannelBeforeDeleteEvent;
Expand All @@ -43,6 +47,19 @@ class ChannelController extends RestController
* nullable=true,
* description="Number of items per page. Defaults to 10."
* )
* @QueryParam(
* name="entity",
* requirements=".+",
* nullable=true,
* description="The entity alias. One or several aliases separated by comma. Defaults to all entities"
* )
* @QueryParam(
* name="active",
* requirements="true|false",
* nullable=true,
* strict=true,
* description="The channel active status. Default for all(active, inactive) channel statuses"
* )
* @ApiDoc(
* description="Get all channels",
* resource=true
Expand All @@ -52,10 +69,32 @@ class ChannelController extends RestController
*/
public function cgetAction()
{
$page = (int)$this->getRequest()->get('page', 1);
$limit = (int)$this->getRequest()->get('limit', self::ITEMS_PER_PAGE);
$page = (int)$this->getRequest()->get('page', 1);
$limit = (int)$this->getRequest()->get('limit', self::ITEMS_PER_PAGE);
$entities = $this->getRequest()->get('entity', null);

$filterParameters = [
'entity' => new ChainParameterFilter(
[
new StringToArrayParameterFilter(),
new EntityClassParameterFilter($this->get('oro_entity.entity_class_name_helper'))
]
),
'active' => new BooleanParameterFilter(),
];
$map = [
'entity' => 'entities.name',
'active' => 'status',
];

$joins = [];
if (!empty($entities)) {
$joins[] = 'entities';
}

$criteria = $this->getFilterCriteria($this->getSupportedQueryParameters('cgetAction'), $filterParameters, $map);

return $this->handleGetListRequest($page, $limit);
return $this->handleGetListRequest($page, $limit, $criteria, $joins);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class ChannelApiEntityManager extends ApiEntityManager
protected function getSerializationConfig()
{
$config = [
'fields' => [
'excluded_fields' => ['data'],
'fields' => [
'dataSource' => ['fields' => 'id'],
'entities' => ['fields' => 'name'],
'status' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace OroCRM\Bundle\ContactBundle\Tests\Functional\Api\Rest;

use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase;
use OroCRM\Bundle\ChannelBundle\Entity\Channel;

/**
* @outputBuffering enabled
Expand All @@ -13,7 +14,7 @@ class ChannelApiControllerTest extends WebTestCase
protected function setUp()
{
$this->initClient([], $this->generateWsseAuthHeader());
$this->loadFixtures(['OroCRM\Bundle\ChannelBundle\Tests\Functional\Fixture\LoadChannel']);
$this->loadFixtures(['OroCRM\Bundle\ChannelBundle\Tests\Functional\Fixture\LoadChannels']);
}

public function testCget()
Expand All @@ -23,6 +24,49 @@ public function testCget()

$channels = $this->getJsonResponseContent($this->client->getResponse(), 200);

$this->assertNotEmpty($channels);
$this->assertCount(2, $channels);
}

public function testCgetWithActiveFilter()
{
/** @var Channel $activeChannel */
$activeChannel = $this->getReference('channel_1');

/** @var Channel $inactiveChannel */
$inactiveChannel = $this->getReference('channel_2');

//fetch active channels
$url = $this->getUrl('orocrm_api_get_channels', ['active' => 'false']);
$this->client->request('GET', $url);

$channels = $this->getJsonResponseContent($this->client->getResponse(), 200);

$this->assertNotEmpty($channels);
$this->assertCount(1, $channels);
$this->assertEquals($channels[0]['name'], $inactiveChannel->getName());

//fetch inactive channels
$url = $this->getUrl('orocrm_api_get_channels', ['active' => 'true']);
$this->client->request('GET', $url);

$channels = $this->getJsonResponseContent($this->client->getResponse(), 200);

$this->assertNotEmpty($channels);
$this->assertCount(1, $channels);
$this->assertEquals($channels[0]['name'], $activeChannel->getName());
}

public function testCgetWithEntityFilter()
{
$url = $this->getUrl(
'orocrm_api_get_channels',
['entity' => 'OroCRM\Bundle\ChannelBundle\Entity\CustomerIdentity']
);
$this->client->request('GET', $url);

$channels = $this->getJsonResponseContent($this->client->getResponse(), 200);

$this->assertNotEmpty($channels);
$this->assertCount(1, $channels);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace OroCRM\Bundle\ChannelBundle\Tests\Functional\Fixture;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\Persistence\ObjectManager;

use Oro\Bundle\OrganizationBundle\Entity\Organization;

use OroCRM\Bundle\ChannelBundle\Entity\Channel;

class LoadChannels extends AbstractFixture
{
/** @var ObjectManager */
protected $em;

/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
$this->em = $manager;
$date = new \DateTime('now');

$channel = new Channel();
$channel
->setName('first channel')
->setStatus(true)
->setOwner($this->loadOwner())
->setChannelType('testType')
->setCreatedAt($date)
->setUpdatedAt($date)
->setCustomerIdentity('test1')
->setEntities(['test1', 'test2']);

$manager->persist($channel);

$this->setReference('channel_1', $channel);

$channel2 = new Channel();
$channel2
->setName('second channel')
->setOwner($this->loadOwner())
->setChannelType('testType')
->setCreatedAt($date)
->setUpdatedAt($date)
->setCustomerIdentity('test1')
->setEntities(['OroCRM\Bundle\ChannelBundle\Entity\CustomerIdentity']);

$manager->persist($channel2);

$this->setReference('channel_2', $channel2);

$manager->flush();
}

/**
* @return Organization|null
*/
protected function loadOwner()
{
return $this->em->getRepository('OroOrganizationBundle:Organization')->getFirst();
}
}
4 changes: 2 additions & 2 deletions src/OroCRM/Bundle/MagentoBundle/Resources/config/datagrid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,8 @@ datagrid:
options:
field_options:
choices:
false: orocrm.magento.datagrid.columns.order_is_guest.no
true: orocrm.magento.datagrid.columns.order_is_guest.yes
'false': orocrm.magento.datagrid.columns.order_is_guest.no
'true': orocrm.magento.datagrid.columns.order_is_guest.yes
data_name: o.isGuest
createdAt:
type: datetime
Expand Down

0 comments on commit 0c8d1af

Please sign in to comment.