diff --git a/CHANGELOG.md b/CHANGELOG.md index c717fb1c23d..be46d6b80e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +CHANGELOG for 1.0.0-alpha4 +=================== +* 1.0.0-alpha4 (2013-07-31) + * Address Types Management. Added ability to set different type for addresses in Contact address book + CHANGELOG for 1.0.0-alpha3 =================== diff --git a/src/OroCRM/Bundle/AccountBundle/Controller/AccountController.php b/src/OroCRM/Bundle/AccountBundle/Controller/AccountController.php index 83ed41fc2bf..431afb854b2 100644 --- a/src/OroCRM/Bundle/AccountBundle/Controller/AccountController.php +++ b/src/OroCRM/Bundle/AccountBundle/Controller/AccountController.php @@ -117,11 +117,18 @@ public function updateAction(Account $entity = null) return $this->get('oro_grid.renderer')->renderResultsJsonResponse($datagridView); } - $backUrl = $this->generateUrl('orocrm_account_index'); - if ($this->get('orocrm_account.form.handler.account')->process($entity)) { $this->getFlashBag()->add('success', 'Account successfully saved'); - return $this->redirect($backUrl); + + return $this->get('oro_ui.router')->actionRedirect( + array( + 'route' => 'orocrm_account_update', + 'parameters' => array('id' => $entity->getId()), + ), + array( + 'route' => 'orocrm_account_index', + ) + ); } return array( diff --git a/src/OroCRM/Bundle/AccountBundle/Datagrid/AccountContactUpdateDatagridManager.php b/src/OroCRM/Bundle/AccountBundle/Datagrid/AccountContactUpdateDatagridManager.php index 62ba165bdb0..6312fc7df0a 100644 --- a/src/OroCRM/Bundle/AccountBundle/Datagrid/AccountContactUpdateDatagridManager.php +++ b/src/OroCRM/Bundle/AccountBundle/Datagrid/AccountContactUpdateDatagridManager.php @@ -2,7 +2,6 @@ namespace OroCRM\Bundle\AccountBundle\Datagrid; -use Oro\Bundle\GridBundle\Datagrid\FlexibleDatagridManager; use Oro\Bundle\GridBundle\Field\FieldDescriptionCollection; use Oro\Bundle\GridBundle\Field\FieldDescription; use Oro\Bundle\GridBundle\Field\FieldDescriptionInterface; @@ -10,9 +9,15 @@ use Oro\Bundle\GridBundle\Sorter\SorterInterface; use Oro\Bundle\GridBundle\Datagrid\ParametersInterface; use Oro\Bundle\GridBundle\Datagrid\ProxyQueryInterface; +use Oro\Bundle\GridBundle\Datagrid\ORM\QueryFactory\EntityQueryFactory; class AccountContactUpdateDatagridManager extends AccountContactDatagridManager { + /** + * @var string + */ + protected $hasAccountExpression; + /** * {@inheritDoc} */ @@ -22,16 +27,17 @@ protected function configureFields(FieldDescriptionCollection $fieldsCollection) $fieldHasAccount->setName('has_account'); $fieldHasAccount->setOptions( array( - 'type' => FieldDescriptionInterface::TYPE_BOOLEAN, - 'label' => $this->translate('Assigned'), - 'field_name' => 'hasCurrentAccount', - 'expression' => 'hasCurrentAccount', - 'nullable' => false, - 'editable' => true, - 'sortable' => true, - 'filter_type' => FilterInterface::TYPE_BOOLEAN, - 'filterable' => true, - 'show_filter' => true, + 'type' => FieldDescriptionInterface::TYPE_BOOLEAN, + 'label' => $this->translate('Assigned'), + 'field_name' => 'hasCurrentAccount', + 'expression' => $this->getHasAccountExpression(), + 'nullable' => false, + 'editable' => true, + 'sortable' => true, + 'filter_type' => FilterInterface::TYPE_BOOLEAN, + 'filterable' => true, + 'show_filter' => true, + 'filter_by_where' => true, ) ); $fieldsCollection->add($fieldHasAccount); @@ -46,24 +52,34 @@ protected function prepareQuery(ProxyQueryInterface $query) { $this->applyJoinWithAddressAndCountry($query); - $entityAlias = $query->getRootAlias(); + $query->addSelect($this->getHasAccountExpression() . ' AS hasCurrentAccount', true); + } - if ($this->getAccount()->getId()) { - $query->addSelect( - "CASE WHEN " . - "(:account MEMBER OF $entityAlias.accounts OR $entityAlias.id IN (:data_in)) AND " . - "$entityAlias.id NOT IN (:data_not_in) ". - "THEN 1 ELSE 0 END AS hasCurrentAccount", - true - ); - } else { - $query->addSelect( - "CASE WHEN " . - "$entityAlias.id IN (:data_in) AND $entityAlias.id NOT IN (:data_not_in) ". - "THEN 1 ELSE 0 END AS hasCurrentAccount", - true - ); + /** + * @return string + */ + protected function getHasAccountExpression() + { + if (null === $this->hasAccountExpression) { + /** @var EntityQueryFactory $queryFactory */ + $queryFactory = $this->queryFactory; + $entityAlias = $queryFactory->getAlias(); + + if ($this->getAccount()->getId()) { + $this->hasAccountExpression = + "CASE WHEN " . + "(:account MEMBER OF $entityAlias.accounts OR $entityAlias.id IN (:data_in)) AND " . + "$entityAlias.id NOT IN (:data_not_in) ". + "THEN true ELSE false END"; + } else { + $this->hasAccountExpression = + "CASE WHEN " . + "$entityAlias.id IN (:data_in) AND $entityAlias.id NOT IN (:data_not_in) ". + "THEN true ELSE false END"; + } } + + return $this->hasAccountExpression; } /** diff --git a/src/OroCRM/Bundle/AccountBundle/Entity/Account.php b/src/OroCRM/Bundle/AccountBundle/Entity/Account.php index 27c0271f6bf..905244bd262 100644 --- a/src/OroCRM/Bundle/AccountBundle/Entity/Account.php +++ b/src/OroCRM/Bundle/AccountBundle/Entity/Account.php @@ -11,8 +11,10 @@ use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap; -use Oro\Bundle\FlexibleEntityBundle\Entity\Mapping\AbstractEntityFlexible; use OroCRM\Bundle\ContactBundle\Entity\Contact; + +use Oro\Bundle\TagBundle\Entity\Taggable; +use Oro\Bundle\FlexibleEntityBundle\Entity\Mapping\AbstractEntityFlexible; use Oro\Bundle\DataAuditBundle\Metadata\Annotation as Oro; /** @@ -21,7 +23,7 @@ * @ORM\HasLifecycleCallbacks() * @Oro\Loggable */ -class Account extends AbstractEntityFlexible +class Account extends AbstractEntityFlexible implements Taggable { /** * @ORM\Id @@ -62,6 +64,11 @@ class Account extends AbstractEntityFlexible */ protected $values; + /** + * @var ArrayCollection $tags + */ + protected $tags; + public function __construct() { parent::__construct(); @@ -185,4 +192,32 @@ public function doPreUpdate() { $this->updated = new \DateTime('now', new \DateTimeZone('UTC')); } + + /** + * {@inheritdoc} + */ + public function getTaggableId() + { + return $this->getId(); + } + + /** + * {@inheritdoc} + */ + public function getTags() + { + $this->tags = $this->tags ?: new ArrayCollection(); + + return $this->tags; + } + + /** + * {@inheritdoc} + */ + public function setTags($tags) + { + $this->tags = $tags; + + return $this; + } } diff --git a/src/OroCRM/Bundle/AccountBundle/Form/Handler/AccountHandler.php b/src/OroCRM/Bundle/AccountBundle/Form/Handler/AccountHandler.php index 1b58dd34f70..9a13c39ae02 100644 --- a/src/OroCRM/Bundle/AccountBundle/Form/Handler/AccountHandler.php +++ b/src/OroCRM/Bundle/AccountBundle/Form/Handler/AccountHandler.php @@ -4,12 +4,14 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; - use Doctrine\Common\Persistence\ObjectManager; + +use Oro\Bundle\TagBundle\Entity\TagManager; use OroCRM\Bundle\AccountBundle\Entity\Account; use OroCRM\Bundle\ContactBundle\Entity\Contact; +use Oro\Bundle\TagBundle\Form\Handler\TagHandlerInterface; -class AccountHandler +class AccountHandler implements TagHandlerInterface { /** * @var FormInterface @@ -26,6 +28,11 @@ class AccountHandler */ protected $manager; + /** + * @var TagManager + */ + protected $tagManager; + /** * * @param FormInterface $form @@ -50,7 +57,7 @@ public function process(Account $entity) $this->form->setData($entity); if (in_array($this->request->getMethod(), array('POST', 'PUT'))) { - $this->form->bind($this->request); + $this->form->submit($this->request); if ($this->form->isValid()) { $appendContacts = $this->form->get('appendContacts')->getData(); @@ -75,8 +82,10 @@ protected function onSuccess(Account $entity, array $appendContacts, array $remo { $this->appendContacts($entity, $appendContacts); $this->removeContacts($entity, $removeContacts); + $this->manager->persist($entity); $this->manager->flush(); + $this->tagManager->saveTagging($entity); } /** @@ -104,4 +113,12 @@ protected function removeContacts(Account $account, array $contacts) $account->removeContact($contact); } } + + /** + * {@inheritdoc} + */ + public function setTagManager(TagManager $tagManager) + { + $this->tagManager = $tagManager; + } } diff --git a/src/OroCRM/Bundle/AccountBundle/Form/Type/AccountType.php b/src/OroCRM/Bundle/AccountBundle/Form/Type/AccountType.php index 23e8dc33b02..023a150b7f4 100644 --- a/src/OroCRM/Bundle/AccountBundle/Form/Type/AccountType.php +++ b/src/OroCRM/Bundle/AccountBundle/Form/Type/AccountType.php @@ -27,6 +27,12 @@ public function addEntityFields(FormBuilderInterface $builder) ) ); + // tags + $builder->add( + 'tags', + 'oro_tag_select' + ); + // contacts $builder->add( 'appendContacts', diff --git a/src/OroCRM/Bundle/AccountBundle/Resources/config/assets.yml b/src/OroCRM/Bundle/AccountBundle/Resources/config/assets.yml deleted file mode 100644 index 6000d9cb935..00000000000 --- a/src/OroCRM/Bundle/AccountBundle/Resources/config/assets.yml +++ /dev/null @@ -1,4 +0,0 @@ -js: - - '@OroUIBundle/Resources/public/lib/bootstrap/js/bootstrap-scrollspy.js' - - '@OroUIBundle/Resources/public/lib/backbone.bootstrap-modal.js' - - '@OroUIBundle/Resources/public/lib/jquery/select2.min.js' \ No newline at end of file diff --git a/src/OroCRM/Bundle/AccountBundle/Resources/config/navigation.yml b/src/OroCRM/Bundle/AccountBundle/Resources/config/navigation.yml index 138af99dbbf..65b03524259 100644 --- a/src/OroCRM/Bundle/AccountBundle/Resources/config/navigation.yml +++ b/src/OroCRM/Bundle/AccountBundle/Resources/config/navigation.yml @@ -10,6 +10,7 @@ oro_menu_config: route: 'orocrm_account_index' extras: routes: ['orocrm_account_*'] + description: List of accounts shortcut_new_account: label: Create new account @@ -36,7 +37,7 @@ oro_menu_config: shortcut_list_accounts: ~ oro_titles: - orocrm_account_index: Accounts - orocrm_account_view: %%account.name%% - Accounts + orocrm_account_index: ~ + orocrm_account_view: %%account.name%% orocrm_account_create: Create Account - orocrm_account_update: %%account.name%% - Accounts + orocrm_account_update: %%account.name%% diff --git a/src/OroCRM/Bundle/AccountBundle/Resources/config/services.yml b/src/OroCRM/Bundle/AccountBundle/Resources/config/services.yml index 9febce0e18c..c6a8ec88313 100644 --- a/src/OroCRM/Bundle/AccountBundle/Resources/config/services.yml +++ b/src/OroCRM/Bundle/AccountBundle/Resources/config/services.yml @@ -62,6 +62,8 @@ services: - @orocrm_account.form.account - @request - @doctrine.orm.entity_manager + tags: + - { name: oro_tag.tag_manager } # Form type orocrm_account.form.type.account_select: @@ -124,6 +126,8 @@ services: - @orocrm_account.form.account.api - @request - @doctrine.orm.entity_manager + tags: + - { name: oro_tag.tag_manager } orocrm_account.form.autocomplete.account.search_handler: parent: oro_form.autocomplete.search_handler diff --git a/src/OroCRM/Bundle/AccountBundle/Resources/views/Account/searchResult.html.twig b/src/OroCRM/Bundle/AccountBundle/Resources/views/Account/searchResult.html.twig index d26d8b2de1b..9f410ff7922 100644 --- a/src/OroCRM/Bundle/AccountBundle/Resources/views/Account/searchResult.html.twig +++ b/src/OroCRM/Bundle/AccountBundle/Resources/views/Account/searchResult.html.twig @@ -1,6 +1,6 @@ {# Available variables: - * entity - user entity OroCRM\Bundle\AccountBundle\Entity\Account + * entity - user entity OroCRM\Bundle\AccountBundle\Entity\Account or null * indexer_item - indexer item Oro\Bundle\SearchBundle\Query\Result\Item #} {% extends 'OroSearchBundle:Search:searchResultItem.html.twig' %} @@ -9,11 +9,9 @@ {% set format = oro_config_value('oro_user.name_format') %} {% set showImage = false %} -{% if entity %} - {% set recordUrl = indexer_item.recordUrl %} -{% endif %} - +{% set recordUrl = indexer_item.recordUrl %} {% set title = indexer_item.recordTitle %} + {% set entityType = 'Account'|trans %} {% set entityInfo = [ diff --git a/src/OroCRM/Bundle/AccountBundle/Resources/views/Account/update.html.twig b/src/OroCRM/Bundle/AccountBundle/Resources/views/Account/update.html.twig index 70c3f3fcf85..06a0beef009 100644 --- a/src/OroCRM/Bundle/AccountBundle/Resources/views/Account/update.html.twig +++ b/src/OroCRM/Bundle/AccountBundle/Resources/views/Account/update.html.twig @@ -1,5 +1,6 @@ {% extends 'OroUIBundle:actions:update.html.twig' %} -{% form_theme form with ['OroAddressBundle:Include:fields.html.twig', 'OroFormBundle:Form:fields.html.twig'] %} +{% import 'OroTagBundle::macros.html.twig' as _tag %} +{% form_theme form with ['OroAddressBundle:Include:fields.html.twig', 'OroFormBundle:Form:fields.html.twig', 'OroTagBundle:Form:fields.html.twig'] %} {% set format = oro_config_value('oro_user.name_format') %} {% set title = form.vars.value.id ? form.vars.value.fullname(format)|default('N/A') ~ ' - ' ~ 'Update Account'|trans : 'New Account'|trans %} {% oro_title_set({params : {"%account.name%": form.vars.value.name|default('N/A')} }) %} @@ -38,7 +39,8 @@ {{ UI.buttonSeparator() }} {% endif %} {{ UI.button({'path' : path('orocrm_account_index'), 'title' : 'Cancel', 'label' : 'Cancel'}) }} - {{ UI.buttonType({'type': 'submit', 'class': 'btn-success', 'label': 'Save'}) }} + {{ UI.saveAndStayButton() }} + {{ UI.saveAndCloseButton() }} {% endblock %} {% block pageHeader %} @@ -66,7 +68,8 @@ { 'title': 'Basic Information', 'data': [ - form_row(form.name) + form_row(form.name), + _tag.tagInputField('Tags', form) ] } ] diff --git a/src/OroCRM/Bundle/AccountBundle/Resources/views/Account/view.html.twig b/src/OroCRM/Bundle/AccountBundle/Resources/views/Account/view.html.twig index 135cfa0570a..2ef47730247 100644 --- a/src/OroCRM/Bundle/AccountBundle/Resources/views/Account/view.html.twig +++ b/src/OroCRM/Bundle/AccountBundle/Resources/views/Account/view.html.twig @@ -1,5 +1,6 @@ {% extends 'OroUIBundle:actions:view.html.twig' %} {% import 'OroUIBundle::macros.html.twig' as macros %} +{% import 'OroTagBundle::macros.html.twig' as _tag %} {% import 'OroAddressBundle:Include:viewMacro.html.twig' as addressView %} {% set format = oro_config_value('oro_user.name_format') %} {% oro_title_set({params : {"%account.name%": entity.name|default('N/A')} }) %} @@ -9,7 +10,6 @@ {% endblock %} {% block navButtons %} - {{ UI.button({'path': path('orocrm_account_index'), 'iClass': 'icon-chevron-left ', 'title': 'Back', 'label': 'Back'}) }} {% if resource_granted('orocrm_account_update') %} {{ UI.button({'path': path('orocrm_account_update', {'id': entity.id}), 'iClass': 'icon-edit', 'title': 'Edit account', 'label': 'Edit'}) }} {% endif %} @@ -71,6 +71,11 @@ {% set additional = additional|merge([{'title' : null, 'data' : attributes}]) %} {% endif %} + {% set dataSubBlocks = [UI.attibuteRow('Account Name', entity.name)] %} + {% if resource_granted('oro_tag_view_tag_cloud') %} + {% set dataSubBlocks = dataSubBlocks|merge([UI.renderAttribute('Tags', _tag.renderView(entity))]) %} + {% endif %} + {% set dataBlocks = [ { @@ -79,15 +84,15 @@ 'subblocks': [ { 'title': 'Basic Information', - 'data': [ - UI.attibuteRow('Account Name', entity.name), - ] + 'data' : dataSubBlocks } ] } ] %} + + {% if (accountAddresses|length) %} {% set dataBlocks = dataBlocks|merge([{'title' : 'Addresses', 'subblocks': accountAddresses}])%} {% endif %} diff --git a/src/OroCRM/Bundle/AccountBundle/Tests/Functional/API/RestAccountApiTest.php b/src/OroCRM/Bundle/AccountBundle/Tests/Functional/API/RestAccountApiTest.php index f79b6c074e3..e3068cdde29 100644 --- a/src/OroCRM/Bundle/AccountBundle/Tests/Functional/API/RestAccountApiTest.php +++ b/src/OroCRM/Bundle/AccountBundle/Tests/Functional/API/RestAccountApiTest.php @@ -12,11 +12,16 @@ */ class RestAccountApiTest extends WebTestCase { - public $client = null; + /** @var Client */ + protected $client; public function setUp() { - $this->client = static::createClient(array(), ToolsAPI::generateWsseHeader()); + if (!isset($this->client)) { + $this->client = static::createClient(array(), ToolsAPI::generateWsseHeader()); + } else { + $this->client->restart(); + } } public function testCreateAccount() @@ -32,7 +37,7 @@ public function testCreateAccount() ) ) ); - $this->client->request('POST', 'http://localhost/api/rest/latest/account', $request); + $this->client->request('POST', $this->client->generate('oro_api_post_account'), $request); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 201); @@ -44,9 +49,9 @@ public function testCreateAccount() * @depends testCreateAccount * @return array */ - public function testGetContact($request) + public function testGetAccount($request) { - $this->client->request('GET', 'http://localhost/api/rest/latest/accounts'); + $this->client->request('GET', $this->client->generate('oro_api_get_accounts')); $result = $this->client->getResponse(); $result = json_decode($result->getContent(), true); $flag = 1; @@ -58,7 +63,7 @@ public function testGetContact($request) } $this->assertEquals(0, $flag); - $this->client->request('GET', 'http://localhost/api/rest/latest/accounts' . '/' . $account['id']); + $this->client->request('GET', $this->client->generate('oro_api_get_account', array('id' => $account['id']))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 200); @@ -68,16 +73,16 @@ public function testGetContact($request) /** * @param $account * @param $request - * @depends testGetContact + * @depends testGetAccount * @depends testCreateAccount */ - public function testUpdateContact($account, $request) + public function testUpdateAccount($account, $request) { $request['account']['attributes']['description'] .= "_Updated"; - $this->client->request('PUT', 'http://localhost/api/rest/latest/accounts' . '/' . $account['id'], $request); + $this->client->request('PUT', $this->client->generate('oro_api_put_account', array('id' => $account['id'])), $request); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 204); - $this->client->request('GET', 'http://localhost/api/rest/latest/accounts' . '/' . $account['id']); + $this->client->request('GET', $this->client->generate('oro_api_get_account', array('id' => $account['id']))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 200); $result = json_decode($result->getContent(), true); @@ -86,14 +91,14 @@ public function testUpdateContact($account, $request) /** * @param $contact - * @depends testGetContact + * @depends testGetAccount */ - public function testDeleteContact($contact) + public function testDeleteAccount($contact) { - $this->client->request('DELETE', 'http://localhost/api/rest/latest/accounts' . '/' . $contact['id']); + $this->client->request('DELETE', $this->client->generate('oro_api_delete_account', array('id' => $contact['id']))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 204); - $this->client->request('GET', 'http://localhost/api/rest/latest/accounts' . '/' . $contact['id']); + $this->client->request('GET', $this->client->generate('oro_api_get_account', array('id' => $contact['id']))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 404); } diff --git a/src/OroCRM/Bundle/AccountBundle/Tests/Functional/API/SoapAccountApiTest.php b/src/OroCRM/Bundle/AccountBundle/Tests/Functional/API/SoapAccountApiTest.php index 7350f8e2415..5509c9e9524 100644 --- a/src/OroCRM/Bundle/AccountBundle/Tests/Functional/API/SoapAccountApiTest.php +++ b/src/OroCRM/Bundle/AccountBundle/Tests/Functional/API/SoapAccountApiTest.php @@ -12,21 +12,26 @@ */ class SoapAccountApiTest extends WebTestCase { - /** @var \SoapClient */ - protected $clientSoap = null; + /** @var Client */ + protected $client; public function setUp() { $this->markTestSkipped('BAP-717'); - $this->clientSoap = static::createClient(array(), ToolsAPI::generateWsseHeader()); + if (!isset($this->client)) { + $this->client = static::createClient(array(), ToolsAPI::generateWsseHeader()); - $this->clientSoap->soap( - "http://localhost/api/soap", - array( - 'location' => 'http://localhost/api/soap', - 'soap_version' => SOAP_1_2 - ) - ); + $this->client->soap( + "http://localhost/api/soap", + array( + 'location' => 'http://localhost/api/soap', + 'soap_version' => SOAP_1_2 + ) + ); + + } else { + $this->client->restart(); + } } /** @@ -37,8 +42,8 @@ public function setUp() */ public function testCreateAccount($request, $response) { - $result = $this->clientSoap->soapClient->createAccount($request); - ToolsAPI::assertEqualsResponse($response, $result, $this->clientSoap->soapClient->__getLastResponse()); + $result = $this->client->soapClient->createAccount($request); + ToolsAPI::assertEqualsResponse($response, $result, $this->client->soapClient->__getLastResponse()); return $request; } @@ -51,7 +56,7 @@ public function testCreateAccount($request, $response) */ public function testGetAccounts($request) { - $accounts = $this->clientSoap->soapClient->getAccounts(1, 1000); + $accounts = $this->client->soapClient->getAccounts(1, 1000); $accounts = ToolsAPI::classToArray($accounts); $result = false; foreach ($accounts as $account) { @@ -72,7 +77,7 @@ public function testGetAccounts($request) */ public function testUpdateAccount($request, $response) { - $accounts = $this->clientSoap->soapClient->getAccounts(1, 1000); + $accounts = $this->client->soapClient->getAccounts(1, 1000); $accounts = ToolsAPI::classToArray($accounts); $result = false; foreach ($accounts as $account) { @@ -83,9 +88,9 @@ public function testUpdateAccount($request, $response) } } $request['attributes']['description'] .= '_Updated'; - $result = $this->clientSoap->soapClient->updateAccount($accountId, $request); + $result = $this->client->soapClient->updateAccount($accountId, $request); $this->assertTrue($result); - $account = $this->clientSoap->soapClient->getAccount($accountId); + $account = $this->client->soapClient->getAccount($accountId); $account = ToolsAPI::classToArray($account); $result = false; if ($account['attributes']['description'] == $request['attributes']['description']) { @@ -103,9 +108,9 @@ public function testUpdateAccount($request, $response) * @depends testUpdateAccount * @throws \Exception|\SoapFault */ - public function testDeleteContactGroup($request, $response) + public function testDeleteAccount($request, $response) { - $accounts = $this->clientSoap->soapClient->getAccounts(1, 1000); + $accounts = $this->client->soapClient->getAccounts(1, 1000); $accounts = ToolsAPI::classToArray($accounts); $result = false; foreach ($accounts as $account) { @@ -115,10 +120,10 @@ public function testDeleteContactGroup($request, $response) break; } } - $result = $this->clientSoap->soapClient->deleteAccount($accountId); + $result = $this->client->soapClient->deleteAccount($accountId); $this->assertTrue($result); try { - $this->clientSoap->soapClient->getAccount($accountId); + $this->client->soapClient->getAccount($accountId); } catch (\SoapFault $e) { if ($e->faultcode != 'NOT_FOUND') { throw $e; diff --git a/src/OroCRM/Bundle/AccountBundle/Tests/Unit/Form/Handler/AccountHandlerTest.php b/src/OroCRM/Bundle/AccountBundle/Tests/Unit/Form/Handler/AccountHandlerTest.php index 653058b8a62..8bc91ceae3d 100644 --- a/src/OroCRM/Bundle/AccountBundle/Tests/Unit/Form/Handler/AccountHandlerTest.php +++ b/src/OroCRM/Bundle/AccountBundle/Tests/Unit/Form/Handler/AccountHandlerTest.php @@ -51,6 +51,11 @@ protected function setUp() $this->entity = new Account(); $this->handler = new AccountHandler($this->form, $this->request, $this->manager); + $this->handler->setTagManager( + $this->getMockBuilder('Oro\Bundle\TagBundle\Entity\TagManager') + ->disableOriginalConstructor() + ->getMock() + ); } @@ -61,7 +66,7 @@ public function testProcessUnsupportedRequest() ->with($this->entity); $this->form->expects($this->never()) - ->method('bind'); + ->method('submit'); $this->assertFalse($this->handler->process($this->entity)); } @@ -79,7 +84,7 @@ public function testProcessSupportedRequest($method) ->with($this->entity); $this->form->expects($this->once()) - ->method('bind') + ->method('submit') ->with($this->request); $this->assertFalse($this->handler->process($this->entity)); @@ -110,7 +115,7 @@ public function testProcessValidData() ->with($this->entity); $this->form->expects($this->once()) - ->method('bind') + ->method('submit') ->with($this->request); $this->form->expects($this->once()) diff --git a/src/OroCRM/Bundle/AccountBundle/Tests/Unit/Form/Type/AccountApiTypeTest.php b/src/OroCRM/Bundle/AccountBundle/Tests/Unit/Form/Type/AccountApiTypeTest.php index c32fcfac6c9..115a7585f39 100644 --- a/src/OroCRM/Bundle/AccountBundle/Tests/Unit/Form/Type/AccountApiTypeTest.php +++ b/src/OroCRM/Bundle/AccountBundle/Tests/Unit/Form/Type/AccountApiTypeTest.php @@ -55,9 +55,13 @@ public function testAddEntityFields() ->will($this->returnSelf()); $builder->expects($this->at(2)) ->method('add') - ->with('appendContacts', 'oro_entity_identifier') + ->with('tags', 'oro_tag_select') ->will($this->returnSelf()); $builder->expects($this->at(3)) + ->method('add') + ->with('appendContacts', 'oro_entity_identifier') + ->will($this->returnSelf()); + $builder->expects($this->at(4)) ->method('add') ->with('removeContacts', 'oro_entity_identifier') ->will($this->returnSelf()); diff --git a/src/OroCRM/Bundle/AccountBundle/Tests/Unit/Form/Type/AccountTypeTest.php b/src/OroCRM/Bundle/AccountBundle/Tests/Unit/Form/Type/AccountTypeTest.php index 181057cf44b..68e263673ed 100644 --- a/src/OroCRM/Bundle/AccountBundle/Tests/Unit/Form/Type/AccountTypeTest.php +++ b/src/OroCRM/Bundle/AccountBundle/Tests/Unit/Form/Type/AccountTypeTest.php @@ -35,9 +35,13 @@ public function testAddEntityFields() ->will($this->returnSelf()); $builder->expects($this->at(2)) ->method('add') - ->with('appendContacts', 'oro_entity_identifier') + ->with('tags', 'oro_tag_select') ->will($this->returnSelf()); $builder->expects($this->at(3)) + ->method('add') + ->with('appendContacts', 'oro_entity_identifier') + ->will($this->returnSelf()); + $builder->expects($this->at(4)) ->method('add') ->with('removeContacts', 'oro_entity_identifier') ->will($this->returnSelf()); diff --git a/src/OroCRM/Bundle/ContactBundle/Controller/Api/Rest/ContactAddressController.php b/src/OroCRM/Bundle/ContactBundle/Controller/Api/Rest/ContactAddressController.php new file mode 100644 index 00000000000..6e03222b1ca --- /dev/null +++ b/src/OroCRM/Bundle/ContactBundle/Controller/Api/Rest/ContactAddressController.php @@ -0,0 +1,126 @@ +getManager()->find($id); + + if ($contact) { + $address = $contact->getAddressByTypeName($typeName); + } else { + $address = null; + } + + $responseData = $address ? json_encode($this->getPreparedItem($address)) : ''; + + return new Response($responseData, $address ? Codes::HTTP_OK : Codes::HTTP_NOT_FOUND); + } + + /** + * REST GET primary address + * + * @param string $id + * + * @ApiDoc( + * description="Get contact primary address", + * resource=true + * ) + * @AclAncestor("orocrm_contact_view") + * @return Response + */ + public function getPrimaryAction($id) + { + /** @var Contact $contact */ + $contact = $this->getManager()->find($id); + + if ($contact) { + $address = $contact->getPrimaryAddress(); + } else { + $address = null; + } + + $responseData = $address ? json_encode($this->getPreparedItem($address)) : ''; + + return new Response($responseData, $address ? Codes::HTTP_OK : Codes::HTTP_NOT_FOUND); + } + + /** + * {@inheritdoc} + */ + public function getManager() + { + return $this->get('orocrm_contact.contact.manager.api'); + } + + /** + * {@inheritdoc} + */ + public function getForm() + { + throw new \BadMethodCallException('Form is not available.'); + } + + /** + * {@inheritdoc} + */ + public function getFormHandler() + { + throw new \BadMethodCallException('FormHandler is not available.'); + } + + /** + * {@inheritDoc} + */ + protected function getPreparedItem($entity) + { + // convert addresses to plain array + $addressTypesData = array(); + + /** @var $entity ContactAddress */ + foreach ($entity->getTypes() as $addressType) { + $addressTypesData[] = parent::getPreparedItem($addressType); + } + + $result = parent::getPreparedItem($entity); + $result['types'] = $addressTypesData; + + unset($result['owner']); + + return $result; + } +} diff --git a/src/OroCRM/Bundle/ContactBundle/Controller/Api/Rest/ContactController.php b/src/OroCRM/Bundle/ContactBundle/Controller/Api/Rest/ContactController.php index e8fe6614824..66703317df2 100644 --- a/src/OroCRM/Bundle/ContactBundle/Controller/Api/Rest/ContactController.php +++ b/src/OroCRM/Bundle/ContactBundle/Controller/Api/Rest/ContactController.php @@ -2,23 +2,27 @@ namespace OroCRM\Bundle\ContactBundle\Controller\Api\Rest; +use Symfony\Component\Form\FormInterface; +use Symfony\Component\HttpFoundation\Response; + use FOS\RestBundle\Controller\Annotations\NamePrefix; use FOS\RestBundle\Controller\Annotations\RouteResource; use FOS\RestBundle\Controller\Annotations\QueryParam; +use FOS\RestBundle\Routing\ClassResourceInterface; + use Nelmio\ApiDocBundle\Annotation\ApiDoc; + use Oro\Bundle\AddressBundle\Entity\AddressType; -use Oro\Bundle\AddressBundle\Form\DataTransformer\AddressTypeToTypeTransformer; + use Oro\Bundle\UserBundle\Annotation\Acl; use Oro\Bundle\UserBundle\Annotation\AclAncestor; -use Symfony\Component\Form\FormInterface; -use Symfony\Component\HttpFoundation\Response; -use FOS\RestBundle\Routing\ClassResourceInterface; use Oro\Bundle\SoapBundle\Form\Handler\ApiFormHandler; use Oro\Bundle\SoapBundle\Controller\Api\Rest\FlexibleRestController; use Oro\Bundle\SoapBundle\Entity\Manager\ApiFlexibleEntityManager; + use OroCRM\Bundle\ContactBundle\Entity\Contact; -use Oro\Bundle\AddressBundle\Entity\TypedAddress; +use OroCRM\Bundle\ContactBundle\Entity\ContactAddress; /** * @RouteResource("contact") @@ -142,14 +146,6 @@ public function getFormHandler() return $this->get('orocrm_contact.form.handler.contact.api'); } - /** - * @return AddressTypeToTypeTransformer - */ - protected function getAddressTypeTransformer() - { - return $this->get('oro_address.typed.transformer'); - } - /** * {@inheritDoc} */ @@ -158,16 +154,18 @@ protected function getPreparedItem($entity) // convert addresses to plain array $addressData = array(); /** @var $entity Contact */ - /** @var $address TypedAddress */ - foreach ($entity->getMultiAddress() as $address) { + /** @var ContactAddress $address */ + foreach ($entity->getAddresses() as $address) { $addressArray = parent::getPreparedItem($address); - $addressArray['type'] = $this->getAddressTypeTransformer()->transform($address->getType()); + $addressArray['types'] = $address->getTypeNames(); + + unset($addressArray['owner']); + $addressData[] = $addressArray; } $result = parent::getPreparedItem($entity); $result['addresses'] = $addressData; - unset($result['multiAddress']); return $result; } @@ -183,18 +181,6 @@ protected function fixRequestAttributes($entity) $request = $this->getRequest()->request; $data = $request->get($requestVariable, array()); - $data['multiAddress'] = !empty($data['addresses']) ? $data['addresses'] : array(); - foreach ($data['multiAddress'] as &$address) { - /** @var bool|AddressType $addressType */ - $addressType = isset($address['type']) - ? $this->getAddressTypeTransformer()->reverseTransform($address['type']) - : null; - if ($addressType) { - $address['type'] = $addressType->getId(); - } - } - unset($data['addresses']); - $request->set($requestVariable, $data); } } diff --git a/src/OroCRM/Bundle/ContactBundle/Controller/Api/Soap/ContactController.php b/src/OroCRM/Bundle/ContactBundle/Controller/Api/Soap/ContactController.php index 4c1c0570811..51ea92fcbc1 100644 --- a/src/OroCRM/Bundle/ContactBundle/Controller/Api/Soap/ContactController.php +++ b/src/OroCRM/Bundle/ContactBundle/Controller/Api/Soap/ContactController.php @@ -5,10 +5,14 @@ use Symfony\Component\Form\FormInterface; use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap; +use Oro\Bundle\UserBundle\Annotation\AclAncestor; + use Oro\Bundle\SoapBundle\Controller\Api\Soap\FlexibleSoapController; use Oro\Bundle\SoapBundle\Entity\Manager\ApiFlexibleEntityManager; use Oro\Bundle\SoapBundle\Form\Handler\ApiFormHandler; +use OroCRM\Bundle\ContactBundle\Entity\Contact; + class ContactController extends FlexibleSoapController { /** @@ -16,6 +20,7 @@ class ContactController extends FlexibleSoapController * @Soap\Param("page", phpType="int") * @Soap\Param("limit", phpType="int") * @Soap\Result(phpType = "OroCRM\Bundle\ContactBundle\Entity\Contact[]") + * @AclAncestor("orocrm_contact_list") */ public function cgetAction($page = 1, $limit = 10) { @@ -26,12 +31,52 @@ public function cgetAction($page = 1, $limit = 10) * @Soap\Method("getContact") * @Soap\Param("id", phpType = "int") * @Soap\Result(phpType = "OroCRM\Bundle\ContactBundle\Entity\Contact") + * @AclAncestor("orocrm_contact_view") */ public function getAction($id) { return $this->handleGetRequest($id); } + /** + * @Soap\Method("getContactAddressByTypeName") + * @Soap\Param("id", phpType = "int") + * @Soap\Param("typeName", phpType = "string") + * @Soap\Result(phpType = "OroCRM\Bundle\ContactBundle\Entity\ContactAddress") + * @AclAncestor("orocrm_contact_view") + */ + public function getAddressByTypeNameAction($id, $typeName) + { + /** @var Contact $contact */ + $contact = $this->getEntity($id); + $address = $contact->getAddressByTypeName($typeName); + + if (!$address) { + throw new \SoapFault('NOT_FOUND', sprintf('Contact address with type "%s" can\'t be found', $typeName)); + } + + return $address; + } + + /** + * @Soap\Method("getContactPrimaryAddress") + * @Soap\Param("id", phpType = "int") + * @Soap\Result(phpType = "OroCRM\Bundle\ContactBundle\Entity\ContactAddress") + * @AclAncestor("orocrm_contact_view") + */ + public function getPrimaryAddressAction($id) + { + /** @var Contact $contact */ + $contact = $this->getEntity($id); + $address = $contact->getPrimaryAddress(); + + if (!$address) { + throw new \SoapFault('NOT_FOUND', sprintf('Contact has no primary address', $address)); + } + + return $address; + } + /** * @Soap\Method("createContact") * @Soap\Param("contact", phpType = "OroCRM\Bundle\ContactBundle\Entity\ContactSoap") diff --git a/src/OroCRM/Bundle/ContactBundle/Controller/ContactController.php b/src/OroCRM/Bundle/ContactBundle/Controller/ContactController.php index 4587bd2bf7b..a1b6d8c1104 100644 --- a/src/OroCRM/Bundle/ContactBundle/Controller/ContactController.php +++ b/src/OroCRM/Bundle/ContactBundle/Controller/ContactController.php @@ -99,11 +99,18 @@ public function updateAction(Contact $entity = null) return $this->get('oro_grid.renderer')->renderResultsJsonResponse($datagridView); } - $backUrl = $this->generateUrl('orocrm_contact_index'); - if ($this->get('orocrm_contact.form.handler.contact')->process($entity)) { $this->getFlashBag()->add('success', 'Contact successfully saved'); - return $this->redirect($backUrl); + + return $this->get('oro_ui.router')->actionRedirect( + array( + 'route' => 'orocrm_contact_update', + 'parameters' => array('id' => $entity->getId()), + ), + array( + 'route' => 'orocrm_contact_index', + ) + ); } return array( diff --git a/src/OroCRM/Bundle/ContactBundle/Controller/GroupController.php b/src/OroCRM/Bundle/ContactBundle/Controller/GroupController.php index 300cdd960ef..bf422901359 100644 --- a/src/OroCRM/Bundle/ContactBundle/Controller/GroupController.php +++ b/src/OroCRM/Bundle/ContactBundle/Controller/GroupController.php @@ -61,7 +61,16 @@ public function updateAction(Group $entity) $this->get('session')->getFlashBag()->add('success', 'Group successfully saved'); if (!$this->getRequest()->get('_widgetContainer')) { - return $this->redirect($this->generateUrl('orocrm_contact_group_index')); + + return $this->get('oro_ui.router')->actionRedirect( + array( + 'route' => 'orocrm_contact_group_update', + 'parameters' => array('id' => $entity->getId()), + ), + array( + 'route' => 'orocrm_contact_group_index', + ) + ); } } diff --git a/src/OroCRM/Bundle/ContactBundle/DataFixtures/ORM/LoadContactAttrData.php b/src/OroCRM/Bundle/ContactBundle/DataFixtures/ORM/LoadContactAttrData.php index 341afe52aa5..1dc0923e695 100644 --- a/src/OroCRM/Bundle/ContactBundle/DataFixtures/ORM/LoadContactAttrData.php +++ b/src/OroCRM/Bundle/ContactBundle/DataFixtures/ORM/LoadContactAttrData.php @@ -82,9 +82,9 @@ public function load(ObjectManager $manager) 'searchable' => true ), array( - 'code' => 'lead_source', + 'code' => 'source', 'type' => 'oro_flexibleentity_simpleselect', - 'label' => 'Lead Source', + 'label' => 'Source', 'options' => array( 'other', 'call', 'TV', 'website' ), diff --git a/src/OroCRM/Bundle/ContactBundle/Datagrid/ContactAccountUpdateDatagridManager.php b/src/OroCRM/Bundle/ContactBundle/Datagrid/ContactAccountUpdateDatagridManager.php index eb741836306..7998060bd90 100644 --- a/src/OroCRM/Bundle/ContactBundle/Datagrid/ContactAccountUpdateDatagridManager.php +++ b/src/OroCRM/Bundle/ContactBundle/Datagrid/ContactAccountUpdateDatagridManager.php @@ -4,7 +4,6 @@ use Doctrine\ORM\QueryBuilder; -use Oro\Bundle\GridBundle\Datagrid\FlexibleDatagridManager; use Oro\Bundle\GridBundle\Field\FieldDescriptionCollection; use Oro\Bundle\GridBundle\Field\FieldDescription; use Oro\Bundle\GridBundle\Field\FieldDescriptionInterface; @@ -12,9 +11,15 @@ use Oro\Bundle\GridBundle\Sorter\SorterInterface; use Oro\Bundle\GridBundle\Datagrid\ParametersInterface; use Oro\Bundle\GridBundle\Datagrid\ProxyQueryInterface; +use Oro\Bundle\GridBundle\Datagrid\ORM\QueryFactory\EntityQueryFactory; class ContactAccountUpdateDatagridManager extends ContactAccountDatagridManager { + /** + * @var string + */ + protected $hasContactExpression; + /** * {@inheritDoc} */ @@ -24,16 +29,17 @@ protected function configureFields(FieldDescriptionCollection $fieldsCollection) $fieldHasContact->setName('has_contact'); $fieldHasContact->setOptions( array( - 'type' => FieldDescriptionInterface::TYPE_BOOLEAN, - 'label' => $this->translate('Assigned'), - 'field_name' => 'hasCurrentContact', - 'expression' => 'hasCurrentContact', - 'nullable' => false, - 'editable' => true, - 'sortable' => true, - 'filter_type' => FilterInterface::TYPE_BOOLEAN, - 'filterable' => true, - 'show_filter' => true, + 'type' => FieldDescriptionInterface::TYPE_BOOLEAN, + 'label' => $this->translate('Assigned'), + 'field_name' => 'hasCurrentContact', + 'expression' => $this->getHasContactExpression(), + 'nullable' => false, + 'editable' => true, + 'sortable' => true, + 'filter_type' => FilterInterface::TYPE_BOOLEAN, + 'filterable' => true, + 'show_filter' => true, + 'filter_by_where' => true, ) ); $fieldsCollection->add($fieldHasContact); @@ -46,24 +52,34 @@ protected function configureFields(FieldDescriptionCollection $fieldsCollection) */ protected function prepareQuery(ProxyQueryInterface $query) { - $entityAlias = $query->getRootAlias(); + $query->addSelect($this->getHasContactExpression() . ' AS hasCurrentContact', true); + } - if ($this->getContact()->getId()) { - $query->addSelect( - "CASE WHEN " . - "(:contact MEMBER OF $entityAlias.contacts OR $entityAlias.id IN (:data_in)) AND " . - "$entityAlias.id NOT IN (:data_not_in) ". - 'THEN 1 ELSE 0 END AS hasCurrentContact', - true - ); - } else { - $query->addSelect( - "CASE WHEN ". - "$entityAlias.id IN (:data_in) AND $entityAlias.id NOT IN (:data_not_in) ". - "THEN 1 ELSE 0 END AS hasCurrentContact", - true - ); + /** + * @return string + */ + protected function getHasContactExpression() + { + if (null === $this->hasContactExpression) { + /** @var EntityQueryFactory $queryFactory */ + $queryFactory = $this->queryFactory; + $entityAlias = $queryFactory->getAlias(); + + if ($this->getContact()->getId()) { + $this->hasContactExpression = + "CASE WHEN " . + "(:contact MEMBER OF $entityAlias.contacts OR $entityAlias.id IN (:data_in)) AND " . + "$entityAlias.id NOT IN (:data_not_in) ". + "THEN true ELSE false END"; + } else { + $this->hasContactExpression = + "CASE WHEN " . + "$entityAlias.id IN (:data_in) AND $entityAlias.id NOT IN (:data_not_in) ". + "THEN true ELSE false END"; + } } + + return $this->hasContactExpression; } /** diff --git a/src/OroCRM/Bundle/ContactBundle/Datagrid/ContactDatagridManager.php b/src/OroCRM/Bundle/ContactBundle/Datagrid/ContactDatagridManager.php index c38449bd222..ced85024d67 100644 --- a/src/OroCRM/Bundle/ContactBundle/Datagrid/ContactDatagridManager.php +++ b/src/OroCRM/Bundle/ContactBundle/Datagrid/ContactDatagridManager.php @@ -13,10 +13,20 @@ use Oro\Bundle\GridBundle\Filter\FilterInterface; use Oro\Bundle\GridBundle\Action\ActionInterface; use Oro\Bundle\GridBundle\Property\UrlProperty; +use Oro\Bundle\GridBundle\Property\FixedProperty; use Oro\Bundle\GridBundle\Datagrid\ProxyQueryInterface; +use Oro\Bundle\GridBundle\Sorter\SorterInterface; class ContactDatagridManager extends FlexibleDatagridManager { + /** + * Expression to get region text or label, CONCAT is used as type cast function + * + * @var string + */ + protected $regionExpression + = "CONCAT(CASE WHEN address.stateText IS NOT NULL THEN address.stateText ELSE region.name END, '')"; + /** * {@inheritDoc} */ @@ -40,7 +50,7 @@ protected function configureFields(FieldDescriptionCollection $fieldsCollection) $fieldId->setOptions( array( 'type' => FieldDescriptionInterface::TYPE_INTEGER, - 'label' => $this->translate('ID'), + 'label' => $this->translate('orocrm.contact.datagrid.contact_id'), 'field_name' => 'id', 'filter_type' => FilterInterface::TYPE_NUMBER, 'show_column' => false @@ -48,23 +58,48 @@ protected function configureFields(FieldDescriptionCollection $fieldsCollection) ); $fieldsCollection->add($fieldId); - $this->configureFlexibleField($fieldsCollection, 'first_name'); - $this->configureFlexibleField($fieldsCollection, 'last_name'); - $this->configureFlexibleField($fieldsCollection, 'phone'); + $this->configureFlexibleField($fieldsCollection, 'first_name', array('show_filter' => true)); + $this->configureFlexibleField($fieldsCollection, 'last_name', array('show_filter' => true)); $this->configureFlexibleField($fieldsCollection, 'email', array('show_filter' => true)); + $this->configureFlexibleField($fieldsCollection, 'phone', array('show_filter' => true)); + + $rolesLabel = new FieldDescription(); + $rolesLabel->setName('groups'); + $rolesLabel->setProperty(new FixedProperty('groups', 'groupLabelsAsString')); + $rolesLabel->setOptions( + array( + 'type' => FieldDescriptionInterface::TYPE_TEXT, + 'label' => $this->translate('orocrm.contact.datagrid.groups'), + 'field_name' => 'groups', + 'expression' => 'contactGroup', + 'filter_type' => FilterInterface::TYPE_ENTITY, + 'sort_field_mapping' => array( + 'entityAlias' => 'contactGroup', + 'fieldName' => 'label', + ), + 'sortable' => true, + 'filterable' => true, + // entity filter options + 'class' => 'OroCRMContactBundle:Group', + 'property' => 'label', + 'filter_by_where' => true + ) + ); + $fieldsCollection->add($rolesLabel); + + $this->configureFlexibleField($fieldsCollection, 'source'); $fieldCountry = new FieldDescription(); $fieldCountry->setName('country'); $fieldCountry->setOptions( array( 'type' => FieldDescriptionInterface::TYPE_TEXT, - 'label' => $this->translate('Country'), + 'label' => $this->translate('orocrm.contact.datagrid.country'), 'field_name' => 'countryName', 'expression' => 'address.country', 'filter_type' => FilterInterface::TYPE_ENTITY, 'sortable' => true, 'filterable' => true, - 'show_filter' => true, // entity filter options 'multiple' => true, 'class' => 'OroAddressBundle:Country', @@ -79,12 +114,44 @@ protected function configureFields(FieldDescriptionCollection $fieldsCollection) ); $fieldsCollection->add($fieldCountry); + $fieldRegion = new FieldDescription(); + $fieldRegion->setName('region'); + $fieldRegion->setOptions( + array( + 'type' => FieldDescriptionInterface::TYPE_TEXT, + 'label' => $this->translate('orocrm.contact.datagrid.region'), + 'field_name' => 'regionLabel', + 'expression' => $this->regionExpression, + 'filter_type' => FilterInterface::TYPE_STRING, + 'sortable' => true, + 'filterable' => true, + 'filter_by_where' => true, + ) + ); + $fieldsCollection->add($fieldRegion); + + $fieldPostalCode = new FieldDescription(); + $fieldPostalCode->setName('postal_code'); + $fieldPostalCode->setOptions( + array( + 'type' => FieldDescriptionInterface::TYPE_TEXT, + 'label' => $this->translate('orocrm.contact.datagrid.postal_code'), + 'field_name' => 'addressPostalCode', + 'expression' => 'address.postalCode', + 'filter_type' => FilterInterface::TYPE_STRING, + 'sortable' => true, + 'filterable' => true, + 'filter_by_where' => true, + ) + ); + $fieldsCollection->add($fieldPostalCode); + $fieldCreated = new FieldDescription(); $fieldCreated->setName('created'); $fieldCreated->setOptions( array( 'type' => FieldDescriptionInterface::TYPE_DATETIME, - 'label' => $this->translate('Created At'), + 'label' => $this->translate('orocrm.contact.datagrid.created_at'), 'field_name' => 'created', 'filter_type' => FilterInterface::TYPE_DATETIME, 'sortable' => true, @@ -99,12 +166,11 @@ protected function configureFields(FieldDescriptionCollection $fieldsCollection) $fieldUpdated->setOptions( array( 'type' => FieldDescriptionInterface::TYPE_DATETIME, - 'label' => $this->translate('Updated At'), + 'label' => $this->translate('orocrm.contact.datagrid.updated_at'), 'field_name' => 'updated', 'filter_type' => FilterInterface::TYPE_DATETIME, 'sortable' => true, 'filterable' => true, - 'show_filter' => true, ) ); $fieldsCollection->add($fieldUpdated); @@ -120,7 +186,7 @@ protected function getRowActions() 'type' => ActionInterface::TYPE_REDIRECT, 'acl_resource' => 'orocrm_contact_view', 'options' => array( - 'label' => $this->translate('View'), + 'label' => $this->translate('orocrm.contact.datagrid.view'), 'link' => 'view_link', 'runOnRowClick' => true, ) @@ -131,7 +197,7 @@ protected function getRowActions() 'type' => ActionInterface::TYPE_REDIRECT, 'acl_resource' => 'orocrm_contact_view', 'options' => array( - 'label' => $this->translate('View'), + 'label' => $this->translate('orocrm.contact.datagrid.view'), 'icon' => 'user', 'link' => 'view_link', ) @@ -142,7 +208,7 @@ protected function getRowActions() 'type' => ActionInterface::TYPE_REDIRECT, 'acl_resource' => 'orocrm_contact_update', 'options' => array( - 'label' => $this->translate('Update'), + 'label' => $this->translate('orocrm.contact.datagrid.update'), 'icon' => 'edit', 'link' => 'update_link', ) @@ -153,7 +219,7 @@ protected function getRowActions() 'type' => ActionInterface::TYPE_DELETE, 'acl_resource' => 'orocrm_contact_delete', 'options' => array( - 'label' => $this->translate('Delete'), + 'label' => $this->translate('orocrm.contact.datagrid.delete'), 'icon' => 'trash', 'link' => 'delete_link', ) @@ -178,15 +244,31 @@ protected function applyJoinWithAddressAndCountry(ProxyQueryInterface $query) // need to translate countries $query->setQueryHint( Query::HINT_CUSTOM_OUTPUT_WALKER, - 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker' + 'Gedmo\Translatable\Query\TreeWalker\TranslationWalker' ); $entityAlias = $query->getRootAlias(); /** @var $query QueryBuilder */ - $query->leftJoin("$entityAlias.multiAddress", 'address', 'WITH', 'address.primary = 1') - ->leftJoin('address.country', 'country'); + $query + ->leftJoin("$entityAlias.addresses", 'address', 'WITH', 'address.primary = true') + ->leftJoin("$entityAlias.groups", 'contactGroup') + ->leftJoin('address.country', 'country') + ->leftJoin('address.state', 'region'); $query->addSelect('country.name as countryName', true); + $query->addSelect('address.postalCode as addressPostalCode', true); + $query->addSelect($this->regionExpression . ' AS regionLabel', true); + } + + /** + * @return array + */ + protected function getDefaultSorters() + { + return array( + 'first_name' => SorterInterface::DIRECTION_ASC, + 'last_name' => SorterInterface::DIRECTION_ASC, + ); } } diff --git a/src/OroCRM/Bundle/ContactBundle/Datagrid/GroupDatagridManager.php b/src/OroCRM/Bundle/ContactBundle/Datagrid/GroupDatagridManager.php index a3971dfd731..55eff2c74d6 100644 --- a/src/OroCRM/Bundle/ContactBundle/Datagrid/GroupDatagridManager.php +++ b/src/OroCRM/Bundle/ContactBundle/Datagrid/GroupDatagridManager.php @@ -42,12 +42,12 @@ protected function configureFields(FieldDescriptionCollection $fieldsCollection) $fieldsCollection->add($fieldId); $fieldName = new FieldDescription(); - $fieldName->setName('name'); + $fieldName->setName('label'); $fieldName->setOptions( array( 'type' => FieldDescriptionInterface::TYPE_TEXT, - 'label' => $this->translate('Name'), - 'field_name' => 'name', + 'label' => $this->translate('Label'), + 'field_name' => 'label', 'filter_type' => FilterInterface::TYPE_STRING, 'sortable' => true, 'filterable' => true, diff --git a/src/OroCRM/Bundle/ContactBundle/Entity/Contact.php b/src/OroCRM/Bundle/ContactBundle/Entity/Contact.php index 8bb6933c927..79c8e358087 100644 --- a/src/OroCRM/Bundle/ContactBundle/Entity/Contact.php +++ b/src/OroCRM/Bundle/ContactBundle/Entity/Contact.php @@ -5,22 +5,24 @@ use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; -use OroCRM\Bundle\AccountBundle\Entity\Account; use JMS\Serializer\Annotation\Type; use JMS\Serializer\Annotation\Exclude; use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap; +use OroCRM\Bundle\AccountBundle\Entity\Account; + +use Oro\Bundle\TagBundle\Entity\Taggable; +use Oro\Bundle\AddressBundle\Entity\AddressType; use Oro\Bundle\FlexibleEntityBundle\Entity\Mapping\AbstractEntityFlexible; -use Oro\Bundle\AddressBundle\Entity\TypedAddress; /** * @ORM\Entity(repositoryClass="Oro\Bundle\FlexibleEntityBundle\Entity\Repository\FlexibleEntityRepository") * @ORM\Table(name="orocrm_contact") * @ORM\HasLifecycleCallbacks() */ -class Contact extends AbstractEntityFlexible +class Contact extends AbstractEntityFlexible implements Taggable { /** * @ORM\Id @@ -32,7 +34,7 @@ class Contact extends AbstractEntityFlexible protected $id; /** - * @var Group[] + * @var Collection * * @ORM\ManyToMany(targetEntity="Group") * @ORM\JoinTable(name="orocrm_contact_to_contact_group", @@ -47,7 +49,7 @@ class Contact extends AbstractEntityFlexible /** * Accounts storage * - * @var ArrayCollection $accounts + * @var Collection * * @ORM\ManyToMany(targetEntity="OroCRM\Bundle\AccountBundle\Entity\Account", mappedBy="contacts") * @ORM\JoinTable(name="orocrm_contact_to_account") @@ -56,13 +58,13 @@ class Contact extends AbstractEntityFlexible protected $accounts; /** - * @var ArrayCollection $multiAddress - * @ORM\OneToMany(targetEntity="ContactAddress", mappedBy="owner", cascade={"all"}) + * @var Collection + * @ORM\OneToMany(targetEntity="ContactAddress", mappedBy="owner", cascade={"all"}, orphanRemoval=true) * @ORM\OrderBy({"primary" = "DESC"}) - * + * @Soap\ComplexType("OroCRM\Bundle\ContactBundle\Entity\ContactAddress[]", nillable=true) * @Exclude */ - protected $multiAddress; + protected $addresses; /** * @var \Oro\Bundle\FlexibleEntityBundle\Model\AbstractFlexibleValue[] @@ -80,12 +82,17 @@ class Contact extends AbstractEntityFlexible */ protected $nameFormat; + /** + * @var ArrayCollection + */ + private $tags; + public function __construct() { parent::__construct(); $this->groups = new ArrayCollection(); $this->accounts = new ArrayCollection(); - $this->multiAddress = new ArrayCollection(); + $this->addresses = new ArrayCollection(); } /** @@ -138,6 +145,33 @@ public function doPreUpdate() $this->updated = new \DateTime('now', new \DateTimeZone('UTC')); } + /** + * Get group labels separated with comma. + * + * @return string + */ + public function getGroupLabelsAsString() + { + return implode(', ', $this->getGroupLabels()); + } + + /** + * Get list of group labels + * + * @return array + */ + public function getGroupLabels() + { + $result = array(); + + /** @var Group $group */ + foreach ($this->getGroups() as $group) { + $result[] = $group->getLabel(); + } + + return $result; + } + /** * Gets the groups related to contact * @@ -221,17 +255,19 @@ public function removeAccount(Account $account) } /** - * Set addresses + * Set addresses. * - * @param ContactAddress[] $addresses + * This method could not be named setAddresses because of bug CRM-253. + * + * @param Collection|ContactAddress[] $addresses * @return Contact */ - public function setMultiAddress($addresses) + public function resetAddresses($addresses) { - $this->multiAddress->clear(); + $this->addresses->clear(); foreach ($addresses as $address) { - $this->addMultiAddress($address); + $this->addAddress($address); } return $this; @@ -243,10 +279,10 @@ public function setMultiAddress($addresses) * @param ContactAddress $address * @return Contact */ - public function addMultiAddress(ContactAddress $address) + public function addAddress(ContactAddress $address) { - if (!$this->multiAddress->contains($address)) { - $this->multiAddress->add($address); + if (!$this->addresses->contains($address)) { + $this->addresses->add($address); $address->setOwner($this); } @@ -256,13 +292,13 @@ public function addMultiAddress(ContactAddress $address) /** * Remove address * - * @param mixed $address + * @param ContactAddress $address * @return Contact */ - public function removeMultiAddress($address) + public function removeAddress(ContactAddress $address) { - if ($this->multiAddress->contains($address)) { - $this->multiAddress->removeElement($address); + if ($this->addresses->contains($address)) { + $this->addresses->removeElement($address); } return $this; @@ -271,11 +307,61 @@ public function removeMultiAddress($address) /** * Get addresses * - * @return ContactAddress[] + * @return Collection|ContactAddress[] */ - public function getMultiAddress() + public function getAddresses() { - return $this->multiAddress; + return $this->addresses; + } + + /** + * Gets primary address if it's available. + * + * @return ContactAddress|null + */ + public function getPrimaryAddress() + { + $result = null; + + foreach ($this->getAddresses() as $address) { + if ($address->isPrimary()) { + $result = $address; + break; + } + } + + return $result; + } + + /** + * Gets one address that has specified type. + * + * @param AddressType $type + * @return ContactAddress|null + */ + public function getAddressByType(AddressType $type) + { + return $this->getAddressByTypeName($type->getName()); + } + + /** + * Gets one address that has specified type name. + * + * @param string $typeName + * @return ContactAddress|null + */ + public function getAddressByTypeName($typeName) + { + $result = null; + + foreach ($this->getAddresses() as $address) { + if ($address->hasTypeWithName($typeName)) { + $result = $address; + break; + } + } + + return $result; } /** @@ -341,4 +427,32 @@ public function getAttributeData($attributeCode) return $value; } + + /** + * {@inheritdoc} + */ + public function getTaggableId() + { + return $this->getId(); + } + + /** + * {@inheritdoc} + */ + public function getTags() + { + $this->tags = $this->tags ?: new ArrayCollection(); + + return $this->tags; + } + + /** + * {@inheritdoc} + */ + public function setTags($tags) + { + $this->tags = $tags; + + return $this; + } } diff --git a/src/OroCRM/Bundle/ContactBundle/Entity/ContactAddress.php b/src/OroCRM/Bundle/ContactBundle/Entity/ContactAddress.php index 9f2cc10bc0e..cadd9941aaa 100644 --- a/src/OroCRM/Bundle/ContactBundle/Entity/ContactAddress.php +++ b/src/OroCRM/Bundle/ContactBundle/Entity/ContactAddress.php @@ -3,26 +3,48 @@ namespace OroCRM\Bundle\ContactBundle\Entity; use Doctrine\ORM\Mapping as ORM; -use Oro\Bundle\AddressBundle\Entity\TypedAddress; +use Doctrine\Common\Collections\Collection; use JMS\Serializer\Annotation\Exclude; +use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap; + +use Oro\Bundle\AddressBundle\Entity\AbstractTypedAddress; /** * @ORM\Table("orocrm_contact_address") * @ORM\HasLifecycleCallbacks() * @ORM\Entity(repositoryClass="Oro\Bundle\AddressBundle\Entity\Repository\AddressRepository") */ -class ContactAddress extends TypedAddress +class ContactAddress extends AbstractTypedAddress { /** - * @ORM\ManyToOne(targetEntity="Contact", inversedBy="multiAddress") + * @ORM\ManyToOne(targetEntity="Contact", inversedBy="addresses") * @ORM\JoinColumn(name="owner_id", referencedColumnName="id") */ protected $owner; + /** + * @var Collection + * + * @ORM\ManyToMany(targetEntity="Oro\Bundle\AddressBundle\Entity\AddressType") + * @ORM\JoinTable( + * name="orocrm_contact_address_to_address_type", + * joinColumns={@ORM\JoinColumn(name="contact_address_id", referencedColumnName="id")}, + * inverseJoinColumns={@ORM\JoinColumn(name="type_name", referencedColumnName="name")} + * ) + * @Soap\ComplexType("string[]", nillable=true) + * @Exclude + **/ + protected $types; + /** * @var \Oro\Bundle\FlexibleEntityBundle\Model\AbstractFlexibleValue[] * - * @ORM\OneToMany(targetEntity="Oro\Bundle\AddressBundle\Entity\Value\AddressValue", mappedBy="entity", cascade={"persist", "remove"}, orphanRemoval=true) + * @ORM\OneToMany( + * targetEntity="Oro\Bundle\AddressBundle\Entity\Value\AddressValue", + * mappedBy="entity", + * cascade={"persist", "remove"}, + * orphanRemoval=true + * ) * @Exclude */ protected $values; @@ -32,7 +54,7 @@ class ContactAddress extends TypedAddress * * @param Contact $owner */ - public function setOwner($owner) + public function setOwner(Contact $owner = null) { $this->owner = $owner; } diff --git a/src/OroCRM/Bundle/ContactBundle/Entity/Group.php b/src/OroCRM/Bundle/ContactBundle/Entity/Group.php index 940692cbdbc..4b30a60f26a 100644 --- a/src/OroCRM/Bundle/ContactBundle/Entity/Group.php +++ b/src/OroCRM/Bundle/ContactBundle/Entity/Group.php @@ -33,14 +33,14 @@ class Group * @Type("string") * @Oro\Versioned */ - protected $name; + protected $label; /** - * @param string $name [optional] Group name + * @param string|null $label [optional] Group name */ - public function __construct($name = '') + public function __construct($label = null) { - $this->name = $name; + $this->label = $label; } /** @@ -54,24 +54,24 @@ public function getId() /** * @return string */ - public function getName() + public function getLabel() { - return $this->name; + return $this->label; } /** * @param string $name * @return Group */ - public function setName($name) + public function setLabel($name) { - $this->name = $name; + $this->label = $name; return $this; } public function __toString() { - return (string)$this->getName(); + return (string)$this->getLabel(); } } diff --git a/src/OroCRM/Bundle/ContactBundle/Form/Handler/ContactHandler.php b/src/OroCRM/Bundle/ContactBundle/Form/Handler/ContactHandler.php index 4c31e3dbc1a..89496d21580 100644 --- a/src/OroCRM/Bundle/ContactBundle/Form/Handler/ContactHandler.php +++ b/src/OroCRM/Bundle/ContactBundle/Form/Handler/ContactHandler.php @@ -4,12 +4,14 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; - use Doctrine\Common\Persistence\ObjectManager; -use OroCRM\Bundle\ContactBundle\Entity\Contact; + +use Oro\Bundle\TagBundle\Entity\TagManager; use OroCRM\Bundle\AccountBundle\Entity\Account; +use OroCRM\Bundle\ContactBundle\Entity\Contact; +use Oro\Bundle\TagBundle\Form\Handler\TagHandlerInterface; -class ContactHandler +class ContactHandler implements TagHandlerInterface { /** * @var FormInterface @@ -26,6 +28,11 @@ class ContactHandler */ protected $manager; + /** + * @var TagManager + */ + protected $tagManager; + /** * * @param FormInterface $form @@ -50,7 +57,7 @@ public function process(Contact $entity) $this->form->setData($entity); if (in_array($this->request->getMethod(), array('POST', 'PUT'))) { - $this->form->bind($this->request); + $this->form->submit($this->request); if ($this->form->isValid()) { $appendAccounts = $this->form->get('appendAccounts')->getData(); @@ -75,8 +82,10 @@ protected function onSuccess(Contact $entity, array $appendAccounts, array $remo { $this->appendAccounts($entity, $appendAccounts); $this->removeAccounts($entity, $removeAccounts); + $this->manager->persist($entity); $this->manager->flush(); + $this->tagManager->saveTagging($entity); } /** @@ -104,4 +113,12 @@ protected function removeAccounts(Contact $contact, array $accounts) $contact->removeAccount($account); } } + + /** + * {@inheritdoc} + */ + public function setTagManager(TagManager $tagManager) + { + $this->tagManager = $tagManager; + } } diff --git a/src/OroCRM/Bundle/ContactBundle/Form/Handler/GroupHandler.php b/src/OroCRM/Bundle/ContactBundle/Form/Handler/GroupHandler.php index 90102f6ebfa..c312c97cbb7 100644 --- a/src/OroCRM/Bundle/ContactBundle/Form/Handler/GroupHandler.php +++ b/src/OroCRM/Bundle/ContactBundle/Form/Handler/GroupHandler.php @@ -50,7 +50,7 @@ public function process(Group $entity) $this->form->setData($entity); if (in_array($this->request->getMethod(), array('POST', 'PUT'))) { - $this->form->bind($this->request); + $this->form->submit($this->request); if ($this->form->isValid()) { $appendContacts = $this->form->get('appendContacts')->getData(); diff --git a/src/OroCRM/Bundle/ContactBundle/Form/Type/ContactAddressType.php b/src/OroCRM/Bundle/ContactBundle/Form/Type/ContactAddressType.php index b010cad59a2..267871336ec 100644 --- a/src/OroCRM/Bundle/ContactBundle/Form/Type/ContactAddressType.php +++ b/src/OroCRM/Bundle/ContactBundle/Form/Type/ContactAddressType.php @@ -2,9 +2,9 @@ namespace OroCRM\Bundle\ContactBundle\Form\Type; -use Oro\Bundle\AddressBundle\Form\Type\AddressTypedType; +use Oro\Bundle\AddressBundle\Form\Type\AbstractTypedAddressType; -class ContactAddressType extends AddressTypedType +class ContactAddressType extends AbstractTypedAddressType { /** * {@inheritdoc} diff --git a/src/OroCRM/Bundle/ContactBundle/Form/Type/ContactType.php b/src/OroCRM/Bundle/ContactBundle/Form/Type/ContactType.php index 3ea65d2502c..be95ebb6f28 100644 --- a/src/OroCRM/Bundle/ContactBundle/Form/Type/ContactType.php +++ b/src/OroCRM/Bundle/ContactBundle/Form/Type/ContactType.php @@ -38,7 +38,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) { parent::buildForm($builder, $options); $builder->addEventSubscriber( - new AddressCollectionTypeSubscriber('multiAddress', $this->addressClass) + new AddressCollectionTypeSubscriber('addresses', $this->addressClass) ); } @@ -50,9 +50,15 @@ public function addEntityFields(FormBuilderInterface $builder) // add default flexible fields parent::addEntityFields($builder); + // tags + $builder->add( + 'tags', + 'oro_tag_select' + ); + // Addresses $builder->add( - 'multiAddress', + 'addresses', 'oro_address_collection', array( 'required' => true, @@ -66,7 +72,7 @@ public function addEntityFields(FormBuilderInterface $builder) 'entity', array( 'class' => 'OroCRMContactBundle:Group', - 'property' => 'name', + 'property' => 'label', 'multiple' => true, 'expanded' => true, 'required' => false, diff --git a/src/OroCRM/Bundle/ContactBundle/Form/Type/GroupType.php b/src/OroCRM/Bundle/ContactBundle/Form/Type/GroupType.php index 67391f0a8c7..a2a99be4779 100644 --- a/src/OroCRM/Bundle/ContactBundle/Form/Type/GroupType.php +++ b/src/OroCRM/Bundle/ContactBundle/Form/Type/GroupType.php @@ -15,7 +15,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add( - 'name', + 'label', 'text', array( 'required' => true, diff --git a/src/OroCRM/Bundle/ContactBundle/Resources/config/assets.yml b/src/OroCRM/Bundle/ContactBundle/Resources/config/assets.yml deleted file mode 100644 index 6000d9cb935..00000000000 --- a/src/OroCRM/Bundle/ContactBundle/Resources/config/assets.yml +++ /dev/null @@ -1,4 +0,0 @@ -js: - - '@OroUIBundle/Resources/public/lib/bootstrap/js/bootstrap-scrollspy.js' - - '@OroUIBundle/Resources/public/lib/backbone.bootstrap-modal.js' - - '@OroUIBundle/Resources/public/lib/jquery/select2.min.js' \ No newline at end of file diff --git a/src/OroCRM/Bundle/ContactBundle/Resources/config/navigation.yml b/src/OroCRM/Bundle/ContactBundle/Resources/config/navigation.yml index 9d48e1a9398..120b80bfab3 100644 --- a/src/OroCRM/Bundle/ContactBundle/Resources/config/navigation.yml +++ b/src/OroCRM/Bundle/ContactBundle/Resources/config/navigation.yml @@ -10,11 +10,13 @@ oro_menu_config: route: 'orocrm_contact_index' extras: routes: ['/^orocrm_contact_(?!group\w+|group\w+)\w+$/'] + description: List of contacts contact_group_list: label: 'Contact Groups' route: 'orocrm_contact_group_index' extras: routes: ['orocrm_contact_group_*'] + description: List of contact groups shortcut_new_contact: label: Create new contact route: orocrm_contact_create @@ -26,6 +28,11 @@ oro_menu_config: route: orocrm_contact_index extras: description: List of contacts + shortcut_new_contact_group: + label: Create new contact group + route: orocrm_contact_group_create + extras: + description: Create new contact group instance tree: application_menu: @@ -39,13 +46,14 @@ oro_menu_config: children: shortcut_new_contact: ~ shortcut_list_contacts: ~ + shortcut_new_contact_group: ~ oro_titles: - orocrm_contact_index: Contacts - orocrm_contact_view: %%contact.name%% - Contacts + orocrm_contact_index: ~ + orocrm_contact_view: %%contact.name%% orocrm_contact_create: Create Contact - orocrm_contact_update: %%contact.name%% - Contacts + orocrm_contact_update: %%contact.name%% - orocrm_contact_group_index: Contact Groups + orocrm_contact_group_index: ~ orocrm_contact_group_create: Create Contact Group - orocrm_contact_group_update: %%group.name%% - Contact Group + orocrm_contact_group_update: %%group.label%% diff --git a/src/OroCRM/Bundle/ContactBundle/Resources/config/routing.yml b/src/OroCRM/Bundle/ContactBundle/Resources/config/routing.yml index 49c9ba659f1..3429b3d8fed 100644 --- a/src/OroCRM/Bundle/ContactBundle/Resources/config/routing.yml +++ b/src/OroCRM/Bundle/ContactBundle/Resources/config/routing.yml @@ -3,16 +3,9 @@ orocrm_contact_bundle: type: annotation prefix: /contact -orocrm_contact_api: - resource: "@OroCRMContactBundle/Controller/Api/Rest/ContactController.php" - type: rest - prefix: api/rest/{version}/ - defaults: - version: latest - -orocrm_contact_group_api: - resource: "@OroCRMContactBundle/Controller/Api/Rest/ContactGroupController.php" - type: rest - prefix: api/rest/{version}/ +orocrm_contact_bundle_api: + resource: "@OroCRMContactBundle/Resources/config/routing_api.yml" + type: rest + prefix: api/rest/{version} defaults: version: latest diff --git a/src/OroCRM/Bundle/ContactBundle/Resources/config/routing_api.yml b/src/OroCRM/Bundle/ContactBundle/Resources/config/routing_api.yml new file mode 100644 index 00000000000..47ac49de585 --- /dev/null +++ b/src/OroCRM/Bundle/ContactBundle/Resources/config/routing_api.yml @@ -0,0 +1,12 @@ +orocrm_contact_api: + resource: "@OroCRMContactBundle/Controller/Api/Rest/ContactController.php" + type: rest + +orocrm_contact_group_api: + resource: "@OroCRMContactBundle/Controller/Api/Rest/ContactGroupController.php" + type: rest + +orocrm_contact_address_api: + resource: "@OroCRMContactBundle/Controller/Api/Rest/ContactAddressController.php" + type: rest + parent: orocrm_contact_api diff --git a/src/OroCRM/Bundle/ContactBundle/Resources/config/services.yml b/src/OroCRM/Bundle/ContactBundle/Resources/config/services.yml index 4a5f8706d92..da8bbd10a05 100644 --- a/src/OroCRM/Bundle/ContactBundle/Resources/config/services.yml +++ b/src/OroCRM/Bundle/ContactBundle/Resources/config/services.yml @@ -78,6 +78,8 @@ services: - @orocrm_contact.form.contact - @request - @doctrine.orm.entity_manager + tags: + - { name: oro_tag.tag_manager } orocrm_contact.contact.manager: class: %orocrm_contact.contact.manager.api.class% @@ -144,6 +146,8 @@ services: - @orocrm_contact.form.contact.api - @request - @doctrine.orm.entity_manager + tags: + - { name: oro_tag.tag_manager } # Group API orocrm_contact.group.manager.api: diff --git a/src/OroCRM/Bundle/ContactBundle/Resources/config/validation.yml b/src/OroCRM/Bundle/ContactBundle/Resources/config/validation.yml index 254b47caaea..9150c6eb1f5 100644 --- a/src/OroCRM/Bundle/ContactBundle/Resources/config/validation.yml +++ b/src/OroCRM/Bundle/ContactBundle/Resources/config/validation.yml @@ -1,8 +1,8 @@ OroCRM\Bundle\ContactBundle\Entity\Group: constraints: - - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: name + - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: label properties: - name: + label: - NotBlank: ~ - Length: min: 3 @@ -10,5 +10,6 @@ OroCRM\Bundle\ContactBundle\Entity\Group: OroCRM\Bundle\ContactBundle\Entity\Contact: properties: - multiAddress: - - Oro\Bundle\AddressBundle\Validator\Constraints\ContainsPrimary: ~ \ No newline at end of file + addresses: + - Oro\Bundle\AddressBundle\Validator\Constraints\ContainsPrimary: ~ + - Oro\Bundle\AddressBundle\Validator\Constraints\UniqueAddressTypes: ~ diff --git a/src/OroCRM/Bundle/ContactBundle/Resources/translations/datagrid.en.xliff b/src/OroCRM/Bundle/ContactBundle/Resources/translations/datagrid.en.xliff deleted file mode 100644 index 91049a64843..00000000000 --- a/src/OroCRM/Bundle/ContactBundle/Resources/translations/datagrid.en.xliff +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - View - View - - - Update - Update - - - Delete - Delete - - - - - ID - ID - - - Created At - Created At - - - Updated At - Updated At - - - - - ID - ID - - - Name - Name - - - - - ID - ID - - - Has group - Has group - - - - - Assigned - Assigned - - - - - - diff --git a/src/OroCRM/Bundle/ContactBundle/Resources/translations/datagrid.en.yml b/src/OroCRM/Bundle/ContactBundle/Resources/translations/datagrid.en.yml new file mode 100644 index 00000000000..0d1f3affa23 --- /dev/null +++ b/src/OroCRM/Bundle/ContactBundle/Resources/translations/datagrid.en.yml @@ -0,0 +1,11 @@ +orocrm.contact.datagrid.contact_id: ID +orocrm.contact.datagrid.groups: Groups +orocrm.contact.datagrid.country: Country +orocrm.contact.datagrid.region: State +orocrm.contact.datagrid.postal_code: ZIP/Postal Code +orocrm.contact.datagrid.created_at: Created At +orocrm.contact.datagrid.updated_at: Updated At + +orocrm.contact.datagrid.view: View +orocrm.contact.datagrid.update: Update +orocrm.contact.datagrid.delete: Delete diff --git a/src/OroCRM/Bundle/ContactBundle/Resources/views/Contact/searchResult.html.twig b/src/OroCRM/Bundle/ContactBundle/Resources/views/Contact/searchResult.html.twig index 64554443a3a..a8ad1165a0c 100644 --- a/src/OroCRM/Bundle/ContactBundle/Resources/views/Contact/searchResult.html.twig +++ b/src/OroCRM/Bundle/ContactBundle/Resources/views/Contact/searchResult.html.twig @@ -1,6 +1,6 @@ {# Available variables: - * entity - user entity OroCRM\Bundle\ContactBundle\Entity\Contact + * entity - user entity OroCRM\Bundle\ContactBundle\Entity\Contact or null * indexer_item - indexer item Oro\Bundle\SearchBundle\Query\Result\Item #} {% extends 'OroSearchBundle:Search:searchResultItem.html.twig' %} @@ -9,12 +9,8 @@ {% set format = oro_config_value('oro_user.name_format') %} {% set showImage = false %} -{% if entity %} - {% set recordUrl = indexer_item.recordUrl %} - {% set title = entity.__toString %} -{% else %} - {% set title = indexer_item.recordTitle %} -{% endif %} +{% set recordUrl = indexer_item.recordUrl %} +{% set title = entity ? entity.__toString : indexer_item.recordTitle %} {% set entityType = 'Contact'|trans %} diff --git a/src/OroCRM/Bundle/ContactBundle/Resources/views/Contact/update.html.twig b/src/OroCRM/Bundle/ContactBundle/Resources/views/Contact/update.html.twig index 3aad0b22f76..ebf2a733bcb 100644 --- a/src/OroCRM/Bundle/ContactBundle/Resources/views/Contact/update.html.twig +++ b/src/OroCRM/Bundle/ContactBundle/Resources/views/Contact/update.html.twig @@ -1,5 +1,6 @@ {% extends 'OroUIBundle:actions:update.html.twig' %} -{% form_theme form with ['OroAddressBundle:Include:fields.html.twig', 'OroFormBundle:Form:fields.html.twig'] %} +{% import 'OroTagBundle::macros.html.twig' as _tag %} +{% form_theme form with ['OroAddressBundle:Include:fields.html.twig', 'OroFormBundle:Form:fields.html.twig', 'OroTagBundle:Form:fields.html.twig'] %} {% set format = oro_config_value('oro_user.name_format') %} {% set fullname = entity.fullname(format)|default('N/A') %} {% oro_title_set({params : {"%contact.name%": fullname} }) %} @@ -40,7 +41,8 @@ {{ UI.buttonSeparator() }} {% endif %} {{ UI.button({'path' : path('orocrm_contact_index'), 'title' : 'Cancel', 'label' : 'Cancel'}) }} - {{ UI.buttonType({'type': 'submit', 'class': 'btn-success', 'label': 'Save'}) }} + {{ UI.saveAndStayButton() }} + {{ UI.saveAndCloseButton() }} {% endblock %} {% block pageHeader %} @@ -68,13 +70,14 @@ { 'title': 'Basic Information', 'data': [ - form_row(form.values) + form_row(form.values), + _tag.tagInputField('Tags', form) ] }, { 'title': 'Addresses', 'data': [ - form_widget(form.multiAddress), + form_widget(form.addresses), ] }, ] diff --git a/src/OroCRM/Bundle/ContactBundle/Resources/views/Contact/view.html.twig b/src/OroCRM/Bundle/ContactBundle/Resources/views/Contact/view.html.twig index bc34b6c8070..75d3d58a79c 100644 --- a/src/OroCRM/Bundle/ContactBundle/Resources/views/Contact/view.html.twig +++ b/src/OroCRM/Bundle/ContactBundle/Resources/views/Contact/view.html.twig @@ -1,4 +1,5 @@ {% extends 'OroUIBundle:actions:view.html.twig' %} +{% import 'OroTagBundle::macros.html.twig' as _tag %} {% import 'OroUIBundle::macros.html.twig' as macros %} {% import 'OroAddressBundle:Include:viewMacro.html.twig' as addressView %} {% set format = oro_config_value('oro_user.name_format') %} @@ -11,7 +12,6 @@ {% endblock %} {% block navButtons %} - {{ UI.button({'path' : path('orocrm_contact_index'), 'iClass' : 'icon-chevron-left ', 'title' : 'Back', 'label' : 'Back'}) }} {% if resource_granted('orocrm_contact_update') %} {{ UI.button({'path' : path('orocrm_contact_update', { 'id': entity.id }), 'iClass' : 'icon-edit ', 'title' : 'Update contact', 'label' : 'Edit'}) }} {% endif %} @@ -44,11 +44,11 @@ {% set addresses = [] %} {% set yesNoChoices = {0: 'No'|trans, 1: 'Yes'|trans} %} - {% for addressValue in entity.multiAddress %} + {% for addressValue in entity.addresses %} {% set primaryData = attribute(addressValue, 'primary') %} {% set primaryData = yesNoChoices[primaryData]|default('No'|trans) %} {% set addresses = addresses|merge([ - addressView.renderAddressView(addressValue, [{'label': 'Type', 'data': 'type'}]), + addressView.renderAddressView(addressValue, [{'label': 'Types', 'value': addressValue.typeLabels|join(', ')}]), addressView.renderAddressView(addressValue, [{'label': 'Primary', 'value': primaryData}]), addressView.renderAddress(addressValue), '
' @@ -69,6 +69,13 @@ {% set dataSubBlocks = dataSubBlocks|merge([addressSubBlock]) %} {% endif %} + {% if resource_granted('oro_tag_view_tag_cloud') %} + {% set dataSubBlocks = dataSubBlocks|merge([{ + title: '', + data : [UI.renderAttribute('Tags', _tag.renderView(entity))] + }]) %} + {% endif %} + {% set dataBlocks = [ { 'title': 'General', diff --git a/src/OroCRM/Bundle/ContactBundle/Resources/views/Group/update.html.twig b/src/OroCRM/Bundle/ContactBundle/Resources/views/Group/update.html.twig index 37d46ffc119..6ce1c14dfeb 100644 --- a/src/OroCRM/Bundle/ContactBundle/Resources/views/Group/update.html.twig +++ b/src/OroCRM/Bundle/ContactBundle/Resources/views/Group/update.html.twig @@ -1,8 +1,7 @@ {% extends 'OroUIBundle:actions:update.html.twig' %} -{% form_theme form with 'OroUIBundle:Form:fields.html.twig' %} {% set title = form.vars.value.id ? form.vars.value.name|default('N/A') : 'Add Customer Group'|trans %} {% if form.vars.value.id %} - {% oro_title_set({params : {"%group.name%": form.vars.value.name} }) %} + {% oro_title_set({params : {"%group.label%": form.vars.value.label} }) %} {% endif %} {% set gridId = 'contacts-grid' %} {% set formAction = form.vars.value.id ? path('orocrm_contact_group_update', { id: form.vars.value.id }) : path('orocrm_contact_group_create') %} @@ -41,7 +40,8 @@ {{ UI.buttonSeparator() }} {% endif %} {{ UI.button({'path' : path('orocrm_contact_group_index'), 'title' : 'Cancel', 'label' : 'Cancel'}) }} - {{ UI.buttonType({'type': 'submit', 'class': 'btn-success', 'label': 'Save'}) }} + {{ UI.saveAndStayButton() }} + {{ UI.saveAndCloseButton() }} {% endblock navButtons %} {% block pageHeader %} @@ -50,7 +50,7 @@ 'entity': form.vars.value, 'indexPath': path('orocrm_contact_group_index'), 'indexLabel': 'Contact Groups', - 'entityTitle': form.vars.value.name|default('N/A') + 'entityTitle': form.vars.value.label|default('N/A') } %} {{ parent() }} @@ -69,7 +69,7 @@ { 'title': 'Basic Information', 'data': [ - form_row(form.name) + form_row(form.label) ] } ] diff --git a/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/ContactRequest/request#1.yml b/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/ContactRequest/request#1.yml index b06e2cde3d2..1d12c2f01ff 100644 --- a/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/ContactRequest/request#1.yml +++ b/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/ContactRequest/request#1.yml @@ -2,9 +2,20 @@ request: groups: ~ attributes: - first_name: Contact_fname_%str% - last_name: Contact_lname - name_prefix: Contact name prefix - description: Contact description + first_name: Contact_fname_%str% + last_name: Contact_lname + name_prefix: Contact name prefix + description: Contact description + addresses: + - + firstName: Contact_fname_%str%_address + lastName: Contact_lnamea_ddress + street: avenu 230 + city: New York + country: US + postalCode: 10001 + types: ['billing'] + primary: true + response: return: true \ No newline at end of file diff --git a/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/RestContactApiTest.php b/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/RestContactApiTest.php index 5a7dcdab0b2..c2a268c22b3 100755 --- a/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/RestContactApiTest.php +++ b/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/RestContactApiTest.php @@ -5,6 +5,7 @@ use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase; use Oro\Bundle\TestFrameworkBundle\Test\ToolsAPI; use Oro\Bundle\TestFrameworkBundle\Test\Client; +use Oro\Bundle\AddressBundle\Entity\AddressType; /** * @outputBuffering enabled @@ -12,26 +13,29 @@ */ class RestContactApiTest extends WebTestCase { - /** - * @var Client - */ - public $client = null; + /** @var Client */ + protected $client; /** * @var array */ protected $testAddress = array( - 'type' => 'shipping', 'street' => 'contact_street', 'city' => 'contact_city', 'country' => 'US', 'state' => 'US.FL', 'postalCode' => '12345', + 'primary' => true, + 'types' => array(AddressType::TYPE_BILLING, AddressType::TYPE_SHIPPING), ); public function setUp() { - $this->client = static::createClient(array(), ToolsAPI::generateWsseHeader()); + if (!isset($this->client)) { + $this->client = static::createClient(array(), ToolsAPI::generateWsseHeader()); + } else { + $this->client->restart(); + } } /** @@ -42,7 +46,7 @@ protected function assertAddresses(array $actualAddresses) $this->assertCount(1, $actualAddresses); $address = current($actualAddresses); - foreach (array('type', 'street', 'city') as $key) { + foreach (array('types', 'street', 'city') as $key) { $this->assertArrayHasKey($key, $address); $this->assertEquals($this->testAddress[$key], $address[$key]); } @@ -64,7 +68,7 @@ public function testCreateContact() "addresses" => array($this->testAddress) ) ); - $this->client->request('POST', 'http://localhost/api/rest/latest/contact', $request); + $this->client->request('POST', $this->client->generate('oro_api_post_contact'), $request); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 201); @@ -82,7 +86,7 @@ public function testCreateContact() */ public function testGetContact($request) { - $this->client->request('GET', 'http://localhost/api/rest/latest/contacts'); + $this->client->request('GET', $this->client->generate('oro_api_get_contacts')); $result = $this->client->getResponse(); $entities = json_decode($result->getContent(), true); $this->assertNotEmpty($entities); @@ -96,7 +100,7 @@ public function testGetContact($request) } $this->assertNotNull($requiredContact); - $this->client->request('GET', 'http://localhost/api/rest/latest/contacts/' . $requiredContact['id']); + $this->client->request('GET', $this->client->generate('oro_api_get_contact', array('id' => $requiredContact['id']))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 200); @@ -117,17 +121,17 @@ public function testGetContact($request) */ public function testUpdateContact($contact, $request) { - $this->testAddress['type'] = 'billing'; + $this->testAddress['types'] = array('billing'); $request['contact']['attributes']['first_name'] .= "_Updated"; - $request['contact']['addresses'][0]['type'] = $this->testAddress['type']; + $request['contact']['addresses'][0]['types'] = $this->testAddress['types']; $request['contact']['addresses'][0]['primary'] = true; - $this->client->request('PUT', 'http://localhost/api/rest/latest/contacts/' . $contact['id'], $request); + $this->client->request('PUT', $this->client->generate('oro_api_put_contact', array('id' => $contact['id'])), $request); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 204); - $this->client->request('GET', 'http://localhost/api/rest/latest/contacts/' . $contact['id']); + $this->client->request('GET', $this->client->generate('oro_api_get_contact', array('id' => $contact['id']))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 200); @@ -148,11 +152,11 @@ public function testUpdateContact($contact, $request) */ public function testDeleteContact($contact) { - $this->client->request('DELETE', 'http://localhost/api/rest/latest/contacts' . '/' . $contact['id']); + $this->client->request('DELETE', $this->client->generate('oro_api_delete_contact', array('id' => $contact['id']))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 204); - $this->client->request('GET', 'http://localhost/api/rest/latest/contacts' . '/' . $contact['id']); + $this->client->request('GET', $this->client->generate('oro_api_get_contact', array('id' => $contact['id']))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 404); } diff --git a/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/RestContactGroupsApiTest.php b/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/RestContactGroupsApiTest.php index 375a2f52ef7..d4574e8ca09 100755 --- a/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/RestContactGroupsApiTest.php +++ b/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/RestContactGroupsApiTest.php @@ -12,11 +12,16 @@ */ class RestContactGroupsApiTest extends WebTestCase { - public $client = null; + /** @var Client */ + protected $client; public function setUp() { - $this->client = static::createClient(array(), ToolsAPI::generateWsseHeader()); + if (!isset($this->client)) { + $this->client = static::createClient(array(), ToolsAPI::generateWsseHeader()); + } else { + $this->client->restart(); + } } /** @@ -26,10 +31,10 @@ public function testCreateContactGroup() { $request = array( "contact_group" => array( - "name" => 'Contact_Group_Name_' . mt_rand() + "label" => 'Contact_Group_Name_' . mt_rand() ) ); - $this->client->request('POST', 'http://localhost/api/rest/latest/contactgroup', $request); + $this->client->request('POST', $this->client->generate('oro_api_post_contactgroup'), $request); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 201); @@ -43,19 +48,19 @@ public function testCreateContactGroup() */ public function testGetContactGroup($request) { - $this->client->request('GET', 'http://localhost/api/rest/latest/contactgroups'); + $this->client->request('GET', $this->client->generate('oro_api_get_contactgroups')); $result = $this->client->getResponse(); $result = json_decode($result->getContent(), true); $flag = 1; foreach ($result as $group) { - if ($group['name'] == $request['contact_group']['name']) { + if ($group['label'] == $request['contact_group']['label']) { $flag = 0; break; } } $this->assertEquals(0, $flag); - $this->client->request('GET', 'http://localhost/api/rest/latest/contactgroups' . '/' . $group['id']); + $this->client->request('GET', $this->client->generate('oro_api_get_contactgroup', array('id' => $group['id']))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 200); @@ -70,15 +75,15 @@ public function testGetContactGroup($request) */ public function testUpdateContactGroup($group, $request) { - $group['name'] .= "_Updated"; - $this->client->request('PUT', 'http://localhost/api/rest/latest/contactgroups' . '/' . $group['id'], $request); + $group['label'] .= "_Updated"; + $this->client->request('PUT', $this->client->generate('oro_api_put_contactgroup', array('id' => $group['id'])), $request); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 204); - $this->client->request('GET', 'http://localhost/api/rest/latest/contactgroups' . '/' . $group['id']); + $this->client->request('GET', $this->client->generate('oro_api_get_contactgroup', array('id' => $group['id']))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 200); $result = json_decode($result->getContent(), true); - $this->assertEquals($request['contact_group']['name'], $result['name'], 'ContactGroup does not updated'); + $this->assertEquals($request['contact_group']['label'], $result['label'], 'ContactGroup does not updated'); } /** @@ -87,10 +92,10 @@ public function testUpdateContactGroup($group, $request) */ public function testDeleteContact($group) { - $this->client->request('DELETE', 'http://localhost/api/rest/latest/contactgroups' . '/' . $group['id']); + $this->client->request('DELETE', $this->client->generate('oro_api_delete_contactgroup', array('id' => $group['id']))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 204); - $this->client->request('GET', 'http://localhost/api/rest/latest/contactgroups' . '/' . $group['id']); + $this->client->request('GET', $this->client->generate('oro_api_get_contactgroup', array('id' => $group['id']))); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 404); } diff --git a/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/SoapContactApiTest.php b/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/SoapContactApiTest.php index b858149cb59..e95b3789065 100755 --- a/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/SoapContactApiTest.php +++ b/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/SoapContactApiTest.php @@ -12,21 +12,26 @@ */ class SoapContactApiTest extends WebTestCase { - /** @var \SoapClient */ - protected $clientSoap = null; + /** @var Client */ + protected $client; public function setUp() { $this->markTestSkipped('BAP-717'); - $this->clientSoap = static::createClient(array(), ToolsAPI::generateWsseHeader()); + if (!isset($this->client)) { + $this->client = static::createClient(array(), ToolsAPI::generateWsseHeader()); - $this->clientSoap->soap( - "http://localhost/api/soap", - array( - 'location' => 'http://localhost/api/soap', - 'soap_version' => SOAP_1_2 - ) - ); + $this->client->soap( + "http://localhost/api/soap", + array( + 'location' => 'http://localhost/api/soap', + 'soap_version' => SOAP_1_2 + ) + ); + + } else { + $this->client->restart(); + } } /** @@ -36,9 +41,9 @@ public function setUp() */ public function testCreateContact($request, $response) { - $result = $this->clientSoap->soapClient->createContact($request); + $result = $this->client->soapClient->createContact($request); $result = ToolsAPI::classToArray($result); - ToolsAPI::assertEqualsResponse($response, $result, $this->clientSoap->soapClient->__getLastResponse()); + ToolsAPI::assertEqualsResponse($response, $result, $this->client->soapClient->__getLastResponse()); } /** @@ -49,7 +54,7 @@ public function testCreateContact($request, $response) */ public function testGetContacts($request) { - $contacts = $this->clientSoap->soapClient->getContacts(1, 1000); + $contacts = $this->client->soapClient->getContacts(1, 1000); $contacts = ToolsAPI::classToArray($contacts); $result = false; foreach ($contacts as $contact) { @@ -73,7 +78,7 @@ public function testGetContacts($request) */ public function testUpdateContact($request) { - $contacts = $this->clientSoap->soapClient->getContacts(1, 1000); + $contacts = $this->client->soapClient->getContacts(1, 1000); $contacts = ToolsAPI::classToArray($contacts); $result = false; foreach ($contacts as $contact) { @@ -86,9 +91,9 @@ public function testUpdateContact($request) } } $request['attributes']['description'] .= '_Updated'; - $result = $this->clientSoap->soapClient->updateContact($contactId, $request); + $result = $this->client->soapClient->updateContact($contactId, $request); $this->assertTrue($result); - $contact = $this->clientSoap->soapClient->getContactGroup($contactId); + $contact = $this->client->soapClient->getContactGroup($contactId); $contact = ToolsAPI::classToArray($contact); $result = false; if ($contact['attributes']['description'] == $request['attributes']['description']) { @@ -106,10 +111,10 @@ public function testUpdateContact($request) */ public function testDeleteContact($contactId) { - $result = $this->clientSoap->soapClient->deleteContact($contactId); + $result = $this->client->soapClient->deleteContact($contactId); $this->assertTrue($result); try { - $this->clientSoap->soapClient->getContact($contactId); + $this->client->soapClient->getContact($contactId); } catch (\SoapFault $e) { if ($e->faultcode != 'NOT_FOUND') { throw $e; diff --git a/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/SoapContactGroupApiTest.php b/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/SoapContactGroupApiTest.php index 9b250d1e81e..e13a0dd13ca 100755 --- a/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/SoapContactGroupApiTest.php +++ b/src/OroCRM/Bundle/ContactBundle/Tests/Functional/API/SoapContactGroupApiTest.php @@ -12,20 +12,25 @@ */ class SoapContactGroupApiTest extends WebTestCase { - /** @var \SoapClient */ - protected $clientSoap = null; + /** @var Client */ + protected $client; public function setUp() { - $this->clientSoap = static::createClient(array(), ToolsAPI::generateWsseHeader()); + if (!isset($this->client)) { + $this->client = static::createClient(array(), ToolsAPI::generateWsseHeader()); - $this->clientSoap->soap( - "http://localhost/api/soap", - array( - 'location' => 'http://localhost/api/soap', - 'soap_version' => SOAP_1_2 - ) - ); + $this->client->soap( + "http://localhost/api/soap", + array( + 'location' => 'http://localhost/api/soap', + 'soap_version' => SOAP_1_2 + ) + ); + + } else { + $this->client->restart(); + } } /** @@ -34,9 +39,9 @@ public function setUp() public function testCreateContactGroup() { $request = array( - "name" => 'Group name_' . mt_rand() + "label" => 'Group name_' . mt_rand() ); - $result = $this->clientSoap->soapClient->createContactGroup($request); + $result = $this->client->soapClient->createContactGroup($request); $this->assertTrue($result); return $request; @@ -49,12 +54,12 @@ public function testCreateContactGroup() */ public function testGetContactGroups($request) { - $groups = $this->clientSoap->soapClient->getContactGroups(1, 1000); + $groups = $this->client->soapClient->getContactGroups(1, 1000); $groups = ToolsAPI::classToArray($groups); $result = false; foreach ($groups as $group) { foreach ($group as $groupDetails) { - $result = $groupDetails['name'] == $request['name']; + $result = $groupDetails['label'] == $request['label']; if ($result) { break; } @@ -73,13 +78,13 @@ public function testGetContactGroups($request) */ public function testUpdateContact($request, $group) { - $request['name'] .= '_Updated'; - $result = $this->clientSoap->soapClient->updateContactGroup($group['id'], $request); + $request['label'] .= '_Updated'; + $result = $this->client->soapClient->updateContactGroup($group['id'], $request); $this->assertTrue($result); - $group = $this->clientSoap->soapClient->getContactGroup($group['id']); + $group = $this->client->soapClient->getContactGroup($group['id']); $group = ToolsAPI::classToArray($group); $result = false; - if ($group['name'] == $request['name']) { + if ($group['label'] == $request['label']) { $result = true; } $this->assertTrue($result); @@ -92,10 +97,10 @@ public function testUpdateContact($request, $group) */ public function testDeleteContactGroup($group) { - $result = $this->clientSoap->soapClient->deleteContactGroup($group['id']); + $result = $this->client->soapClient->deleteContactGroup($group['id']); $this->assertTrue($result); try { - $this->clientSoap->soapClient->getContactGroup($group['id']); + $this->client->soapClient->getContactGroup($group['id']); } catch (\SoapFault $e) { if ($e->faultcode != 'NOT_FOUND') { throw $e; diff --git a/src/OroCRM/Bundle/ContactBundle/Tests/Unit/Entity/ContactTest.php b/src/OroCRM/Bundle/ContactBundle/Tests/Unit/Entity/ContactTest.php index 993c242833d..d63e5106765 100644 --- a/src/OroCRM/Bundle/ContactBundle/Tests/Unit/Entity/ContactTest.php +++ b/src/OroCRM/Bundle/ContactBundle/Tests/Unit/Entity/ContactTest.php @@ -3,8 +3,10 @@ namespace OroCRM\Bundle\ContactBundle\Tests\Unit\Entity; use OroCRM\Bundle\ContactBundle\Entity\Contact; +use OroCRM\Bundle\ContactBundle\Entity\Group; use OroCRM\Bundle\AccountBundle\Entity\Account; use OroCRM\Bundle\ContactBundle\Entity\ContactAddress; +use Oro\Bundle\AddressBundle\Entity\AddressType; class ContactTest extends \PHPUnit_Framework_TestCase { @@ -22,6 +24,30 @@ public function testDoPreUpdate() $this->assertInstanceOf('\DateTime', $entity->getUpdatedAt()); } + public function testGetGroupLabels() + { + $entity = new Contact(); + $this->assertEquals(array(), $entity->getGroupLabels()); + + $entity->addGroup(new Group('Group One')); + $this->assertEquals(array('Group One'), $entity->getGroupLabels()); + + $entity->addGroup(new Group('Group Two')); + $this->assertEquals(array('Group One', 'Group Two'), $entity->getGroupLabels()); + } + + public function testGetGroupLabelsAsString() + { + $entity = new Contact(); + $this->assertEquals('', $entity->getGroupLabelsAsString()); + + $entity->addGroup(new Group('Group One')); + $this->assertEquals('Group One', $entity->getGroupLabelsAsString()); + + $entity->addGroup(new Group('Group Two')); + $this->assertEquals('Group One, Group Two', $entity->getGroupLabelsAsString()); + } + public function testAddAccount() { $account = new Account(); @@ -53,7 +79,7 @@ public function testRemoveAccount() $this->assertEmpty($contact->getAccounts()->toArray()); } - public function testMultiAddress() + public function testAddresses() { $addressOne = new ContactAddress(); $addressOne->setCountry('US'); @@ -64,32 +90,70 @@ public function testMultiAddress() $addresses = array($addressOne, $addressTwo); $contact = new Contact(); - $this->assertSame($contact, $contact->setMultiAddress($addresses)); - $actual = $contact->getMultiAddress(); + $this->assertSame($contact, $contact->resetAddresses($addresses)); + $actual = $contact->getAddresses(); $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $actual); $this->assertEquals($addresses, $actual->toArray()); - $this->assertSame($contact, $contact->addMultiAddress($addressTwo)); - $actual = $contact->getMultiAddress(); + $this->assertSame($contact, $contact->addAddress($addressTwo)); + $actual = $contact->getAddresses(); $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $actual); $this->assertEquals($addresses, $actual->toArray()); - $this->assertSame($contact, $contact->addMultiAddress($addressThree)); - $actual = $contact->getMultiAddress(); + $this->assertSame($contact, $contact->addAddress($addressThree)); + $actual = $contact->getAddresses(); $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $actual); $this->assertEquals(array($addressOne, $addressTwo, $addressThree), $actual->toArray()); - $this->assertSame($contact, $contact->removeMultiAddress($addressOne)); - $actual = $contact->getMultiAddress(); + $this->assertSame($contact, $contact->removeAddress($addressOne)); + $actual = $contact->getAddresses(); $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $actual); $this->assertEquals(array(1 => $addressTwo, 2 => $addressThree), $actual->toArray()); - $this->assertSame($contact, $contact->removeMultiAddress($addressOne)); - $actual = $contact->getMultiAddress(); + $this->assertSame($contact, $contact->removeAddress($addressOne)); + $actual = $contact->getAddresses(); $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $actual); $this->assertEquals(array(1 => $addressTwo, 2 => $addressThree), $actual->toArray()); } + public function testGetPrimaryAddress() + { + $contact = new Contact(); + $this->assertNull($contact->getPrimaryAddress()); + + $address = new ContactAddress(); + $contact->addAddress($address); + $this->assertNull($contact->getPrimaryAddress()); + + $address->setPrimary(true); + $this->assertSame($address, $contact->getPrimaryAddress()); + } + + public function testGetAddressByTypeName() + { + $contact = new Contact(); + $this->assertNull($contact->getAddressByTypeName('billing')); + + $address = new ContactAddress(); + $address->addType(new AddressType('billing')); + $contact->addAddress($address); + + $this->assertSame($address, $contact->getAddressByTypeName('billing')); + } + + public function testGetAddressByType() + { + $address = new ContactAddress(); + $addressType = new AddressType('billing'); + $address->addType($addressType); + + $contact = new Contact(); + $this->assertNull($contact->getAddressByType($addressType)); + + $contact->addAddress($address); + $this->assertSame($address, $contact->getAddressByType($addressType)); + } + public function testGetAttributeDataException() { $contact = new Contact(); diff --git a/src/OroCRM/Bundle/ContactBundle/Tests/Unit/Entity/GroupTest.php b/src/OroCRM/Bundle/ContactBundle/Tests/Unit/Entity/GroupTest.php new file mode 100644 index 00000000000..5053b9f91a7 --- /dev/null +++ b/src/OroCRM/Bundle/ContactBundle/Tests/Unit/Entity/GroupTest.php @@ -0,0 +1,33 @@ +group = new Group(); + } + + public function testConstructor() + { + $this->assertNull($this->group->getLabel()); + + $group = new Group('Label'); + $this->assertEquals('Label', $group->getLabel()); + } + + public function testLabel() + { + $this->assertNull($this->group->getLabel()); + $this->group->setLabel('Label'); + $this->assertEquals('Label', $this->group->getLabel()); + } +} diff --git a/src/OroCRM/Bundle/ContactBundle/Tests/Unit/Form/Handler/ContactHandlerTest.php b/src/OroCRM/Bundle/ContactBundle/Tests/Unit/Form/Handler/ContactHandlerTest.php index f9941f081e8..fbd602dbf01 100644 --- a/src/OroCRM/Bundle/ContactBundle/Tests/Unit/Form/Handler/ContactHandlerTest.php +++ b/src/OroCRM/Bundle/ContactBundle/Tests/Unit/Form/Handler/ContactHandlerTest.php @@ -49,6 +49,11 @@ protected function setUp() $this->entity = new Contact(); $this->handler = new ContactHandler($this->form, $this->request, $this->manager); + $this->handler->setTagManager( + $this->getMockBuilder('Oro\Bundle\TagBundle\Entity\TagManager') + ->disableOriginalConstructor() + ->getMock() + ); } @@ -59,7 +64,7 @@ public function testProcessUnsupportedRequest() ->with($this->entity); $this->form->expects($this->never()) - ->method('bind'); + ->method('submit'); $this->assertFalse($this->handler->process($this->entity)); } @@ -77,7 +82,7 @@ public function testProcessSupportedRequest($method) $this->request->setMethod($method); $this->form->expects($this->once()) - ->method('bind') + ->method('submit') ->with($this->request); $this->assertFalse($this->handler->process($this->entity)); @@ -108,7 +113,7 @@ public function testProcessValidData() ->with($this->entity); $this->form->expects($this->once()) - ->method('bind') + ->method('submit') ->with($this->request); $this->form->expects($this->once()) diff --git a/src/OroCRM/Bundle/ContactBundle/Tests/Unit/Form/Type/ContactTypeTest.php b/src/OroCRM/Bundle/ContactBundle/Tests/Unit/Form/Type/ContactTypeTest.php index 823e13e0ed9..2c2ca60cdc4 100644 --- a/src/OroCRM/Bundle/ContactBundle/Tests/Unit/Form/Type/ContactTypeTest.php +++ b/src/OroCRM/Bundle/ContactBundle/Tests/Unit/Form/Type/ContactTypeTest.php @@ -45,17 +45,21 @@ public function testAddEntityFields() $builder->expects($this->at(1)) ->method('add') - ->with('multiAddress', 'oro_address_collection') + ->with('tags', 'oro_tag_select') ->will($this->returnSelf()); $builder->expects($this->at(2)) ->method('add') - ->with('groups', 'entity') + ->with('addresses', 'oro_address_collection') ->will($this->returnSelf()); $builder->expects($this->at(3)) ->method('add') - ->with('appendAccounts', 'oro_entity_identifier') + ->with('groups', 'entity') ->will($this->returnSelf()); $builder->expects($this->at(4)) + ->method('add') + ->with('appendAccounts', 'oro_entity_identifier') + ->will($this->returnSelf()); + $builder->expects($this->at(5)) ->method('add') ->with('removeAccounts', 'oro_entity_identifier') ->will($this->returnSelf()); diff --git a/src/OroCRM/Bundle/DashboardBundle/Resources/views/Default/index.html.twig b/src/OroCRM/Bundle/DashboardBundle/Resources/views/Default/index.html.twig index b415cd2336d..71ff7c5850d 100644 --- a/src/OroCRM/Bundle/DashboardBundle/Resources/views/Default/index.html.twig +++ b/src/OroCRM/Bundle/DashboardBundle/Resources/views/Default/index.html.twig @@ -53,6 +53,11 @@ {{ __.renderWidget(widget) }} {% if loop.index is even %}{% endif %} {% endfor %} + + +
+ {# TODO Replace hardcoded version with data from backend #} + Version: 1.0.0-alpha4
{% endblock %} diff --git a/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Performance/DataFixtures/Accounts/LoadCrmAccountsData.php b/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Performance/DataFixtures/Accounts/LoadCrmAccountsData.php index 7b263aecd65..698d03070c6 100644 --- a/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Performance/DataFixtures/Accounts/LoadCrmAccountsData.php +++ b/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Performance/DataFixtures/Accounts/LoadCrmAccountsData.php @@ -31,7 +31,7 @@ class LoadCrmAccountsData extends AbstractFixture implements ContainerAwareInter const FLUSH_MAX = 20; /** @var array Lead Sources */ - protected $leadSource = array('other', 'call', 'TV', 'website'); + protected $sources = array('other', 'call', 'TV', 'website'); /** * @var Account Manager */ @@ -135,8 +135,8 @@ public function loadAccounts() $user = $this->users[rand(0, count($this->users)-1)]; $this->setFlexibleAttributeValue($this->contactRepository, $contact, 'assigned_to', $user); $this->setFlexibleAttributeValue($this->contactRepository, $contact, 'reports_to', $contact); - $leadSource = $this->leadSource[rand(0, count($this->leadSource)-1)]; - $this->setFlexibleAttributeValueOption($this->contactRepository, $contact, 'lead_source', $leadSource); + $source = $this->sources[rand(0, count($this->sources)-1)]; + $this->setFlexibleAttributeValueOption($this->contactRepository, $contact, 'source', $source); $this->persist($this->accountManager, $account); @@ -279,7 +279,7 @@ function ($a) use ($idRegion) { $address->setState($region->first()); } - $contact->addMultiAddress($address); + $contact->addAddress($address); return $contact; } diff --git a/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Performance/DataFixtures/Users/LoadCrmUsersData.php b/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Performance/DataFixtures/Users/LoadCrmUsersData.php index 9170de3d983..229b84a9fbc 100644 --- a/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Performance/DataFixtures/Users/LoadCrmUsersData.php +++ b/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Performance/DataFixtures/Users/LoadCrmUsersData.php @@ -20,7 +20,9 @@ use Oro\Bundle\UserBundle\Entity\User; /** - * @SuppressWarnings(PHPMD) + * @SuppressWarnings(PHPMD.TooManyMethods) + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) + * TODO: This class should be refactored (BAP-975) */ class LoadCrmUsersData extends AbstractFixture implements ContainerAwareInterface { @@ -171,6 +173,8 @@ public function loadUsers() * @param array $hobbies * @param \DateTime $lastVisit * @return User + * @SuppressWarnings(PHPMD.ExcessiveParameterList) + * TODO: This method should be refactored (BAP-975) */ private function createUser( $username, diff --git a/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Selenium/Accounts/CreateAccountTest.php b/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Selenium/Accounts/CreateAccountTest.php new file mode 100644 index 00000000000..95a004472b2 --- /dev/null +++ b/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Selenium/Accounts/CreateAccountTest.php @@ -0,0 +1,116 @@ +setHost(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_HOST); + $this->setPort(intval(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PORT)); + $this->setBrowser(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM2_BROWSER); + $this->setBrowserUrl(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_TESTS_URL); + } + + protected function tearDown() + { + $this->cookie()->clear(); + } + + /** + * @return string + */ + public function testCreateAccount() + { + $accountname = 'Account_'.mt_rand(); + + $login = new Login($this); + $login->setUsername(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_LOGIN) + ->setPassword(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PASS) + ->submit() + ->openAccounts() + ->add() + ->setAccountName($accountname) + ->save() + ->assertTitle('Accounts - Customers') + ->assertMessage('Account successfully saved'); + + return $accountname; + } + + /** + * @depends testCreateAccount + * @param $accountname + */ + public function testAccountAutocmplete($accountname) + { + $login = new Login($this); + $login->setUsername(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_LOGIN) + ->setPassword(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PASS) + ->submit() + ->openAccounts() + ->add() + ->setAccountName($accountname . '_autocomplete_test') + ->setStreet('Street') + ->setCity('City') + ->setCountry('Kazak') + ->setState('Aqm') + ->setZipCode('Zip Code 000') + ->save() + ->assertTitle('Accounts - Customers') + ->assertMessage('Account successfully saved'); + } + + /** + * @depends testCreateAccount + * @param $accountname + * @return string + */ + public function testUpdateAccount($accountname) + { + $newAccountname = 'Update_' . $accountname; + + $login = new Login($this); + $login->setUsername(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_LOGIN) + ->setPassword(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PASS) + ->submit() + ->openAccounts() + ->filterBy('Name', $accountname) + ->open(array($accountname)) + ->edit() + ->assertTitle($accountname . ' - Accounts - Customers') + ->setAccountName($newAccountname) + ->save() + ->assertTitle('Accounts - Customers') + ->assertMessage('Account successfully saved') + ->close(); + + return $newAccountname; + } + + /** + * @depends testUpdateContact + * @param $accountname + */ + public function testDeleteAccount($accountname) + { + $this->markTestSkipped('BAP-726'); + $login = new Login($this); + $login->setUsername(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_LOGIN) + ->setPassword(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PASS) + ->submit() + ->openAccounts() + ->filterBy('Name', $accountname) + ->open(array($accountname)) + ->delete() + ->assertTitle('Accounts - Customers') + ->assertMessage('Item was deleted'); + + $login->openUsers()->filterBy('Name', $accountname)->assertNoDataMessage('No Accounts were found to match your search'); + } +} diff --git a/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Selenium/AclTest/AclTest.php b/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Selenium/AclTest/AclTest.php index cfbeff0b034..94c2aa4f0e0 100644 --- a/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Selenium/AclTest/AclTest.php +++ b/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Selenium/AclTest/AclTest.php @@ -38,10 +38,10 @@ public function testCreateRole() ->setName($this->newRole['ROLE_NAME'] . $randomPrefix) ->setLabel($this->newRole['LABEL'] . $randomPrefix) ->selectAcl('Template controller') - ->selectACl('Contact groups manipulation') - ->selectACl('Contact manipulation') - ->selectACl('Account manipulation') - ->selectACl('Oro Security') + ->selectAcl('Contact groups manipulation') + ->selectAcl('Contact manipulation') + ->selectAcl('Account manipulation') + ->selectAcl('Oro Security') ->save() ->assertMessage('Role successfully saved'); @@ -63,7 +63,7 @@ public function testCreateUser($roleName) ->submit() ->openUsers() ->add() - ->assertTitle('Create User') + ->assertTitle('Create User - Users - System') ->setUsername($username) ->enable() ->setFirstpassword('123123q') @@ -75,7 +75,7 @@ public function testCreateUser($roleName) ->save() ->assertMessage('User successfully saved') ->close() - ->assertTitle('Users'); + ->assertTitle('Users - System'); return $username; } @@ -90,11 +90,23 @@ public function testUserAccess($username) $login->setUsername($username) ->setPassword('123123q') ->submit(); - $login->byXPath("//div[@class='navbar application-menu']//a[contains(.,'System')]")->click(); - $login->assertElementNotPresent("//div[@id='system_tab']//a[contains(.,'Users')]", 'Element present so ACL for Users do not work'); - $login->assertElementNotPresent("//div[@id='system_tab']//a[contains(.,'Roles')]", 'Element present so ACL for User Roles do not work'); - $login->assertElementNotPresent("//div[@id='system_tab']//a[contains(.,'Groups')]", 'Element present so ACL for User Groups do not work'); - $login->assertElementNotPresent("//div[@id='system_tab']//a[contains(.,'Data Audit')]", 'Element present so ACL for Data Audit do not work'); + $login->moveto($login->byXPath("//div[@id='main-menu']/ul/li/a[contains(.,'System')]")); + $login->assertElementNotPresent( + "//div[@id='main-menu']/ul/li[a[contains(.,'System')]]//a[contains(.,'Users')]", + 'Element present so ACL for Users do not work' + ); + $login->assertElementNotPresent( + "//div[@id='main-menu']/ul/li[a[contains(.,'System')]]//a[contains(.,'Roles')]", + 'Element present so ACL for User Roles do not work' + ); + $login->assertElementNotPresent( + "//div[@id='main-menu']/ul/li[a[contains(.,'System')]]//a[contains(.,'Groups')]", + 'Element present so ACL for User Groups do not work' + ); + $login->assertElementNotPresent( + "//div[@id='main-menu']/ul/li[a[contains(.,'System')]]//a[contains(.,'Data Audit')]", + 'Element present so ACL for Data Audit do not work' + ); $login->assertElementNotPresent("//div[@id='search-div']", 'Element present so ACL for Search do not work'); $login->byXPath("//ul[@class='nav pull-right']//a[@class='dropdown-toggle']")->click(); $login->assertElementNotPresent("//ul[@class='dropdown-menu']//a[contains(., 'My User')]", 'Element present so ACL for Search do not work'); @@ -135,17 +147,17 @@ public function testEditRole($roleName) ->menu('Roles') ->openRoles(false) ->open(array($roleName)) - ->selectACl('Contact groups manipulation') - ->selectACl('Contact manipulation') - ->selectACl('Account manipulation') - ->selectACl('View Account') - ->selectACl('View List of Accounts') - ->selectACl('View Contact') - ->selectACl('View List of Contacts') - ->selectACl('View contact group') - ->selectACl('View Contact Group List') + ->selectAcl('Contact groups manipulation') + ->selectAcl('Contact manipulation') + ->selectAcl('Account manipulation') + ->selectAcl('View Account') + ->selectAcl('View List of Accounts') + ->selectAcl('View Contact') + ->selectAcl('View List of Contacts') + ->selectAcl('View contact group') + ->selectAcl('View Contact Group List') ->selectAcl('View user user') - ->selectACl('Edit user') + ->selectAcl('Edit user') ->save() ->assertMessage('Role successfully saved'); } @@ -157,19 +169,18 @@ public function testEditRole($roleName) */ public function testViewAccountsContacts($username) { - $this->markTestSkipped('Due bug CRM-147'); $login = new Login($this); $login->setUsername($username) ->setPassword('123123q') ->submit() ->openAccounts() - ->assertTitle('Accounts') + ->assertTitle('Accounts - Customers') ->assertElementNotPresent("//div[@class='container-fluid']//a[@title='Create account']") ->openContacts() - ->assertTitle('Contacts') + ->assertTitle('Contacts - Customers') ->assertElementNotPresent("//div[@class='container-fluid']//a[@title='Create contact']") ->openContactGroups() - ->assertTitle('Contact Groups') + ->assertTitle('Contact Groups - Customers') ->assertElementNotPresent("//div[@class='container-fluid']//a[@title='Create contact group']") ->openAclCheck() ->assertAcl('account/create') diff --git a/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Selenium/Contacts/CreateContactTest.php b/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Selenium/Contacts/CreateContactTest.php new file mode 100644 index 00000000000..f655447f907 --- /dev/null +++ b/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Selenium/Contacts/CreateContactTest.php @@ -0,0 +1,159 @@ + array('billing'), + 'primary' => true, + 'firstName' => 'Address First Name', + 'lastName' => 'Address Last Name', + 'street' => 'Address Street', + 'city' => 'Address City', + 'postalCode' => '10001', + 'country' => 'United States', + 'state' => 'New York' + ); + + protected $addressSecondary = array( + 'types' => array('shipping'), + 'primary' => false, + 'firstName' => 'Address1 First Name', + 'lastName' => 'Address1 Last Name', + 'street' => 'Address1 Street', + 'city' => 'Address1 City', + 'postalCode' => '10001', + 'country' => 'United States', + 'state' => 'New York' + ); + + protected function setUp() + { + $this->setHost(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_HOST); + $this->setPort(intval(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PORT)); + $this->setBrowser(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM2_BROWSER); + $this->setBrowserUrl(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_TESTS_URL); + } + + protected function tearDown() + { + $this->cookie()->clear(); + } + + /** + * @return string + */ + public function testCreateContact() + { + $contactname = 'Contact_'.mt_rand(); + $addressPrimary = array(); + $addressSecondary = array(); + + $login = new Login($this); + $login->setUsername(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_LOGIN) + ->setPassword(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PASS) + ->submit() + ->openContacts() + ->add() + ->setFirstName($contactname . '_first') + ->setLastName($contactname . '_last') + ->setEmail($contactname . '@mail.com') + ->setAddress($this->addressPrimary) + ->setAddress($this->addressSecondary, 1) + ->save() + ->assertTitle('Contacts - Customers') + ->assertMessage('Contact successfully saved') + ->close() + ->filterBy('Email', $contactname . '@mail.com') + ->open(array($contactname)) + ->assertTitle($contactname . '_last, ' . $contactname . '_first - Contacts - Customers') + ->edit() + ->getAddress($addressPrimary) + ->getAddress($addressSecondary, 1); + + $this->assertEquals($this->addressPrimary, $addressPrimary); + $this->assertEquals($this->addressSecondary, $addressSecondary); + + return $contactname; + } + + /** + * @depends testCreateContact + * @param $contactname + */ + public function testContactAutocmplete($contactname) + { + $login = new Login($this); + $login->setUsername(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_LOGIN) + ->setPassword(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PASS) + ->submit() + ->openContacts() + ->add() + ->setFirstName($contactname . '_first_autocomplete') + ->setLastName($contactname . '_last_autocomplete') + ->setAssignedTo('admin') + ->setReportsTo($contactname) + ->setAddressStreet('Street') + ->setAddressCity('City') + ->setAddressPostalCode('Zip Code 000') + ->setAddressCountry('Kazak') + ->setAddressState('Aqm') + ->save() + ->assertTitle('Contacts - Customers') + ->assertMessage('Contact successfully saved') + ->close(); + } + + /** + * @depends testCreateContact + * @param $contactname + * @return string + */ + public function testUpdateContact($contactname) + { + $newContactname = 'Update_' . $contactname; + + $login = new Login($this); + $login->setUsername(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_LOGIN) + ->setPassword(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PASS) + ->submit() + ->openContacts() + ->filterBy('Email', $contactname . '@mail.com') + ->open(array($contactname)) + ->assertTitle($contactname . '_last, ' . $contactname . '_first - Contacts - Customers') + ->edit() + ->setFirstName($newContactname . '_first') + ->save() + ->assertTitle('Contacts - Customers') + ->assertMessage('Contact successfully saved') + ->close(); + + return $newContactname; + } + + /** + * @depends testUpdateContact + * @param $contactname + */ + public function testDeleteContact($contactname) + { + $this->markTestSkipped('BAP-726'); + $login = new Login($this); + $login->setUsername(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_LOGIN) + ->setPassword(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PASS) + ->submit() + ->openContacts() + ->filterBy('Email', $contactname . '@mail.com') + ->open(array($contactname)) + ->delete() + ->assertTitle('Contacts - Customers') + ->assertMessage('Item was deleted'); + + $login->openUsers()->filterBy('Email', $contactname . '@mail.com')->assertNoDataMessage('No Contacts were found to match your search'); + } +} diff --git a/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Selenium/Tags/TagsAssignTest.php b/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Selenium/Tags/TagsAssignTest.php new file mode 100644 index 00000000000..6d1abf8a6ff --- /dev/null +++ b/src/OroCRM/Bundle/TestFrameworkBundle/Tests/Selenium/Tags/TagsAssignTest.php @@ -0,0 +1,155 @@ +setHost(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_HOST); + $this->setPort(intval(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PORT)); + $this->setBrowser(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM2_BROWSER); + $this->setBrowserUrl(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_TESTS_URL); + } + + protected function tearDown() + { + $this->cookie()->clear(); + } + + /** + * @return string + */ + public function testCreateTag() + { + $tagname = 'Tag_'.mt_rand(); + + $login = new Login($this); + $login->setUsername(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_LOGIN) + ->setPassword(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PASS) + ->submit() + ->openTags() + ->add() + ->assertTitle('Create Tag - Tags - System') + ->setTagname($tagname) + ->save() + ->assertMessage('Tag successfully saved') + ->assertTitle('Tags - System') + ->close(); + + return $tagname; + } + + /** + * @depends testCreateTag + * @param $tagname + */ + public function testAccountTag($tagname) + { + $accountname = 'Account_'.mt_rand(); + + $login = new Login($this); + $login->setUsername(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_LOGIN) + ->setPassword(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PASS) + ->submit() + ->openAccounts() + ->add() + ->setAccountName($accountname) + ->verifyTag($tagname) + ->setTag('New_' . $tagname) + ->save() + ->assertMessage('Account successfully saved') + ->close() + ->filterBy('Name', $accountname) + ->open(array($accountname)) + ->verifyTag($tagname); + } + + /** + * @depends testCreateTag + * @param $tagname + */ + public function testContactTag($tagname) + { + $contactname = 'Contact_'.mt_rand(); + + $login = new Login($this); + $login->setUsername(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_LOGIN) + ->setPassword(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PASS) + ->submit() + ->openContacts() + ->add() + ->setFirstName($contactname . '_first') + ->setLastName($contactname . '_last') + ->setEmail($contactname . '@mail.com') + ->verifyTag($tagname) + ->setTag('New_' . $tagname) + ->save() + ->assertMessage('Contact successfully saved') + ->close() + ->filterBy('Email', $contactname . '@mail.com') + ->open(array($contactname)) + ->verifyTag($tagname); + } + + /** + * @depends testCreateTag + * @param $tagname + */ + public function testUserTag($tagname) + { + $username = 'User_'.mt_rand(); + + $login = new Login($this); + $login->setUsername(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_LOGIN) + ->setPassword(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PASS) + ->submit() + ->openUsers() + ->add() + ->setUsername($username) + ->enable() + ->setFirstpassword('123123q') + ->setSecondpassword('123123q') + ->setFirstname('First_'.$username) + ->setLastname('Last_'.$username) + ->setEmail($username.'@mail.com') + ->setRoles(array('Manager')) + ->verifyTag($tagname) + ->setTag('New_' . $tagname) + ->save() + ->assertMessage('User successfully saved') + ->close() + ->filterBy('Username', $username) + ->open(array($username)) + ->verifyTag($tagname); + } + + + /** + * @depends testCreateTag + * @depends testAccountTag + * @depends testContactTag + * @depends testUserTag + * @param $tagname + */ + public function testTagSearch($tagname) + { + $login = new Login($this); + $login->setUsername(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_LOGIN) + ->setPassword(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PASS) + ->submit(); + $tagsearch = new Search($this); + $result = $tagsearch->search('New_' . $tagname) + ->submit() + ->select('New_' . $tagname) + ->assertEntity('User', 1) + ->assertEntity('Contact', 1) + ->assertEntity('Account', 1); + $this->assertNotEmpty($result); + } +}