Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'remotes/dev/master'
- Loading branch information
Showing
6 changed files
with
322 additions
and
3 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/Oro/Bundle/ReportCRMBundle/Tests/Behat/Context/FeatureContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Oro\Bundle\ReportCRMBundle\Tests\Behat\Context; | ||
|
||
use Behat\Symfony2Extension\Context\KernelAwareContext; | ||
use Behat\Symfony2Extension\Context\KernelDictionary; | ||
use Doctrine\ORM\Mapping\ClassMetadataInfo; | ||
use Oro\Bundle\SalesBundle\Entity\Lead; | ||
use Oro\Bundle\TestFrameworkBundle\Behat\Context\OroFeatureContext; | ||
use Oro\Bundle\TestFrameworkBundle\Behat\Fixtures\FixtureLoaderAwareInterface; | ||
use Oro\Bundle\TestFrameworkBundle\Behat\Fixtures\FixtureLoaderDictionary; | ||
|
||
class FeatureContext extends OroFeatureContext implements KernelAwareContext, FixtureLoaderAwareInterface | ||
{ | ||
use KernelDictionary; | ||
use FixtureLoaderDictionary; | ||
|
||
/** | ||
* Load "LeadsByDateReportFixture.yml" alice fixture from ReportCRMBundle suite | ||
* | ||
* PrePersist lifecycleCallback will override createdAt and updatedAt fields passed from fixture. | ||
* So, we should disable this callback to save original values. | ||
* | ||
* @Given /^leads by date report fixture loaded$/ | ||
*/ | ||
public function bestSellingFixtureLoaded() | ||
{ | ||
$metadata = $this->getMetadata(); | ||
|
||
$events = $metadata->lifecycleCallbacks; | ||
$metadata->setLifecycleCallbacks([]); | ||
|
||
$this->fixtureLoader->loadFixtureFile('OroReportCRMBundle:LeadsByDateReportFixture.yml'); | ||
|
||
$metadata->setLifecycleCallbacks($events); | ||
} | ||
|
||
/** | ||
* @return ClassMetadataInfo | ||
*/ | ||
private function getMetadata() | ||
{ | ||
$manager = $this->getContainer()->get('doctrine')->getManagerForClass(Lead::class); | ||
|
||
return $manager->getClassMetadata(Lead::class); | ||
} | ||
} |
159 changes: 159 additions & 0 deletions
159
src/Oro/Bundle/ReportCRMBundle/Tests/Behat/Features/Fixtures/LeadsByDateReportFixture.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
Oro\Bundle\ContactBundle\Entity\ContactEmail: | ||
contactEmail{1..16}: | ||
email: '<email()>' | ||
|
||
Oro\Bundle\ContactBundle\Entity\Contact: | ||
contact{1..16}: | ||
firstName: 'firstName<current()>' | ||
lastName: 'lastName<current()>' | ||
addEmail: ['@contactEmail<current()>'] | ||
owner: '@admin' | ||
organization: '@organization' | ||
|
||
Oro\Bundle\AccountBundle\Entity\Account: | ||
account{1..16}: | ||
name: 'Customer <current()>' | ||
organization: '@organization' | ||
|
||
Oro\Bundle\SalesBundle\Entity\B2bCustomer: | ||
b2bcustomer{1..16}: | ||
name: 'B2bCustomer <current()>' | ||
account: '@account<current()>' | ||
contact: '@contact<current()>' | ||
owner: '@admin' | ||
organization: '@organization' | ||
|
||
Oro\Bundle\SalesBundle\Entity\Customer: | ||
customer{1..16}: | ||
account: '@account<current()>' | ||
customerTarget: '@b2bcustomer<current()>' | ||
|
||
Oro\Bundle\SalesBundle\Entity\Lead: | ||
lead1: | ||
customerAssociation: '@customer1' | ||
name: 'Lead 1' | ||
status: new | ||
owner: '@admin' | ||
organization: '@organization' | ||
createdAt: '<(new DateTime("2016-01-01 11:00:00 UTC"))>' | ||
updatedAt: '<(new DateTime("2016-01-01 11:00:00 UTC"))>' | ||
lead2: | ||
customerAssociation: '@customer2' | ||
name: 'Lead 2' | ||
status: new | ||
owner: '@admin' | ||
organization: '@organization' | ||
createdAt: '<(new DateTime("2016-01-01 11:00:00 UTC"))>' | ||
updatedAt: '<(new DateTime("2016-01-01 11:00:00 UTC"))>' | ||
lead3: | ||
customerAssociation: '@customer3' | ||
name: 'Lead 3' | ||
status: new | ||
owner: '@admin' | ||
organization: '@organization' | ||
createdAt: '<(new DateTime("2016-01-01 13:00:00 UTC"))>' | ||
updatedAt: '<(new DateTime("2016-01-01 13:00:00 UTC"))>' | ||
lead4: | ||
customerAssociation: '@customer4' | ||
name: 'Lead 4' | ||
status: new | ||
owner: '@admin' | ||
organization: '@organization' | ||
createdAt: '<(new DateTime("2016-01-01 13:00:00 UTC"))>' | ||
updatedAt: '<(new DateTime("2016-01-01 13:00:00 UTC"))>' | ||
lead5: | ||
customerAssociation: '@customer5' | ||
name: 'Lead 5' | ||
status: new | ||
owner: '@admin' | ||
organization: '@organization' | ||
createdAt: '<(new DateTime("2016-01-02 11:00:00 UTC"))>' | ||
updatedAt: '<(new DateTime("2016-01-02 11:00:00 UTC"))>' | ||
lead6: | ||
customerAssociation: '@customer6' | ||
name: 'Lead 6' | ||
status: new | ||
owner: '@admin' | ||
organization: '@organization' | ||
createdAt: '<(new DateTime("2016-01-03 11:00:00 UTC"))>' | ||
updatedAt: '<(new DateTime("2016-01-03 11:00:00 UTC"))>' | ||
lead7: | ||
customerAssociation: '@customer7' | ||
name: 'Lead 7' | ||
status: new | ||
owner: '@admin' | ||
organization: '@organization' | ||
createdAt: '<(new DateTime("2016-01-03 11:00:00 UTC"))>' | ||
updatedAt: '<(new DateTime("2016-01-03 11:00:00 UTC"))>' | ||
lead8: | ||
customerAssociation: '@customer8' | ||
name: 'Lead 8' | ||
status: new | ||
owner: '@admin' | ||
organization: '@organization' | ||
createdAt: '<(new DateTime("2016-01-03 11:00:00 UTC"))>' | ||
updatedAt: '<(new DateTime("2016-01-03 11:00:00 UTC"))>' | ||
lead9: | ||
customerAssociation: '@customer9' | ||
name: 'Lead 9' | ||
status: new | ||
owner: '@admin' | ||
organization: '@organization' | ||
createdAt: '<(new DateTime("2016-02-01 11:00:00 UTC"))>' | ||
updatedAt: '<(new DateTime("2016-02-01 11:00:00 UTC"))>' | ||
lead10: | ||
customerAssociation: '@customer10' | ||
name: 'Lead 10' | ||
status: new | ||
owner: '@admin' | ||
organization: '@organization' | ||
createdAt: '<(new DateTime("2016-02-01 11:00:00 UTC"))>' | ||
updatedAt: '<(new DateTime("2016-02-01 11:00:00 UTC"))>' | ||
lead11: | ||
customerAssociation: '@customer11' | ||
name: 'Lead 11' | ||
status: new | ||
owner: '@admin' | ||
organization: '@organization' | ||
createdAt: '<(new DateTime("2016-05-01 11:00:00 UTC"))>' | ||
updatedAt: '<(new DateTime("2016-05-01 11:00:00 UTC"))>' | ||
lead12: | ||
customerAssociation: '@customer12' | ||
name: 'Lead 12' | ||
status: new | ||
owner: '@admin' | ||
organization: '@organization' | ||
createdAt: '<(new DateTime("2016-05-01 11:00:00 UTC"))>' | ||
updatedAt: '<(new DateTime("2016-05-01 11:00:00 UTC"))>' | ||
lead13: | ||
customerAssociation: '@customer13' | ||
name: 'Lead 13' | ||
status: new | ||
owner: '@admin' | ||
organization: '@organization' | ||
createdAt: '<(new DateTime("2016-06-01 11:00:00 UTC"))>' | ||
updatedAt: '<(new DateTime("2016-06-01 11:00:00 UTC"))>' | ||
lead14: | ||
customerAssociation: '@customer14' | ||
name: 'Lead 14' | ||
status: new | ||
owner: '@admin' | ||
organization: '@organization' | ||
createdAt: '<(new DateTime("2016-06-01 11:00:00 UTC"))>' | ||
updatedAt: '<(new DateTime("2016-06-01 11:00:00 UTC"))>' | ||
lead15: | ||
customerAssociation: '@customer15' | ||
name: 'Lead 15' | ||
status: new | ||
owner: '@admin' | ||
organization: '@organization' | ||
createdAt: '<(new DateTime("2017-01-01 11:00:00 UTC"))>' | ||
updatedAt: '<(new DateTime("2017-01-01 11:00:00 UTC"))>' | ||
lead16: | ||
customerAssociation: '@customer16' | ||
name: 'Lead 16' | ||
status: new | ||
owner: '@admin' | ||
organization: '@organization' | ||
createdAt: '<(new DateTime("2017-01-01 11:00:00 UTC"))>' | ||
updatedAt: '<(new DateTime("2017-01-01 11:00:00 UTC"))>' |
18 changes: 18 additions & 0 deletions
18
src/Oro/Bundle/ReportCRMBundle/Tests/Behat/Features/leads_by_date_report.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@ticket-BAP-12348 | ||
|
||
Feature: Leads by date report | ||
In order to understand leads count in specific periods of time | ||
As an Administrator | ||
I want to have ability to build Leads By Date Report | ||
|
||
Scenario: Check report | ||
Given leads by date report fixture loaded | ||
And I login as administrator | ||
And I go to Reports & Segments/ Reports/ Leads/ Leads By Date | ||
When I filter Created Date as between "Jan 1, 2016 11:30 AM" and "Jan 3, 2016 11:30 AM" | ||
Then number of records should be 3 | ||
And I should see following grid: | ||
| Created Date | Leads Count | | ||
| Jan 1, 2016 | 4 | | ||
| Jan 2, 2016 | 1 | | ||
| Jan 3, 2016 | 3 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
oro_behat_extension: | ||
suites: | ||
OroReportCRMBundle: | ||
contexts: | ||
- Oro\Bundle\TestFrameworkBundle\Tests\Behat\Context\OroMainContext | ||
- OroFormBundle::FormContext | ||
- OroDataGridBundle::GridContext | ||
- OroReportCRMBundle::FeatureContext | ||
paths: | ||
- '@OroReportCRMBundle/Tests/Behat/Features' |
83 changes: 83 additions & 0 deletions
83
src/Oro/Bundle/ReportCRMBundle/Tests/Functional/DatagridReport/LeadsByDateReportTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace Oro\Bundle\ReportCRMBundle\Tests\Functional\DatagridReport; | ||
|
||
use Oro\Bundle\ReportCRMBundle\Tests\Functional\DataFixtures\LoadLeadsData; | ||
use Oro\Bundle\ReportCRMBundle\Tests\Functional\DataFixtures\LoadLeadSourceData; | ||
use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase; | ||
|
||
class LeadsByDateReportTest extends WebTestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
$this->initClient([], $this->generateBasicAuthHeader()); | ||
$this->loadFixtures( | ||
[ | ||
LoadLeadSourceData::class, | ||
LoadLeadsData::class, | ||
] | ||
); | ||
} | ||
|
||
public function testDatagridReport() | ||
{ | ||
$currentDate = new \DateTime('now'); | ||
$currentDate = $currentDate->format('Y-m-d'); | ||
|
||
$response = $this->client->requestGrid( | ||
'oro_reportcrm-leads-by_date', | ||
[ | ||
'oro_reportcrm-leads-by_date[_filter][createdDate][type]' => 1, | ||
'oro_reportcrm-leads-by_date[_filter][createdDate][value][start]' => $currentDate, | ||
'oro_reportcrm-leads-by_date[_filter][createdDate][value][end]' => $currentDate, | ||
'oro_reportcrm-leads-by_date[_filter][leadsCount][type]' => 7, | ||
'oro_reportcrm-leads-by_date[_filter][leadsCount][value]' => 2, | ||
'oro_reportcrm-leads-by_date[_filter][leadsCount][value_end]' => 2, | ||
], | ||
true | ||
); | ||
$result = self::getJsonResponseContent($response, 200); | ||
|
||
$valuableResultData = $this->getValuableDataFromResult($result, ['createdDate', 'leadsCount']); | ||
|
||
$this->assertEquals( | ||
[ | ||
'rows' => [ | ||
[ | ||
'createdDate' => $currentDate, | ||
'leadsCount' => 2, | ||
] | ||
], | ||
'totals' => [ | ||
'createdDate' => 'Grand Total', | ||
'leadsCount' => 2, | ||
] | ||
], | ||
$valuableResultData | ||
); | ||
} | ||
|
||
/** | ||
* @param array $response | ||
* @param array $keys | ||
* | ||
* @return array | ||
*/ | ||
protected function getValuableDataFromResult(array $response, array $keys) | ||
{ | ||
return [ | ||
'rows' => array_map( | ||
function ($item) use ($keys) { | ||
return array_intersect_key($item, array_flip($keys)); | ||
}, | ||
$response['data'] | ||
), | ||
'totals' => array_map( | ||
function ($item) { | ||
return $item['total'] ?? $item['label']; | ||
}, | ||
array_intersect_key($response['options']['totals']['grand_total']['columns'], array_flip($keys)) | ||
) | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters