Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality to filter getReportMetadata and getSegmentsMetada in SystemTestCase #18141

Merged
merged 12 commits into from Oct 26, 2021

Conversation

AltamashShaikh
Copy link
Contributor

Added functionality to filter getReportMetadata and getSegmentsMetada in SystemTestCase
Issue: #DEV-2366

Description:

Please include a description of this change and which issue it fixes. If no issue exists yet please include context and what problem it solves.

Review

@AltamashShaikh AltamashShaikh added this to the 4.6.0 milestone Oct 12, 2021
@AltamashShaikh AltamashShaikh marked this pull request as ready for review October 14, 2021 03:36
@AltamashShaikh AltamashShaikh added the Needs Review PRs that need a code review label Oct 14, 2021
@sgiehl
Copy link
Member

sgiehl commented Oct 18, 2021

@AltamashShaikh I think it might be useful to add or change a test in core that uses that new possibility so we can directly see how and if it works. That might also prevent future regressions. You could for example change the custom dimension tests:

plugins/CustomDimensions/tests/System/ApiTest.php Outdated Show resolved Hide resolved
Piwik::addAction('API.API.getSegmentsMetadata.end', function (&$reports, $info) use ($allowedModuleForApiSegmentsReport) {
$this->filterReportsCallback($reports, $info, $allowedModuleForApiSegmentsReport);
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be moved to the setUpBeforeClass method. Calling it in setUp causes each test to add a new observer. So running 10 tests would end up having 10 event observers in the last test.
If the event observer is added in the setUpBeforeClass, you could also always add it like:

Piwik::addAction('API.getReportMetadata.end', function (&$reports, $info) {
    $allowedModuleForApiMetadataReport = self::getAllowedModuleToFilterApiResponse('API.getReportMetadata');
    if ($allowedModuleForApiMetadataReport) {
        self::filterReportsCallback($reports, $info, $allowedModuleForApiMetadataReport);
    }
 });

Piwik::addAction('API.API.getSegmentsMetadata.end', function (&$reports, $info) {
    $allowedModuleForApiSegmentsReport = self::getAllowedModuleToFilterApiResponse('API.getSegmentsMetadata');
    if ($allowedModuleForApiSegmentsReport) {
        self::filterReportsCallback($reports, $info, $allowedModuleForApiSegmentsReport);
    }
});

Note: EvenObserver will be cleared when a Fixture is teared down, so the shouldn't be a need to remove the observers manually.

Copy link
Member

@sgiehl sgiehl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me now. Once travis tests are running again and we can see if all tests are still passing, this should be good to merge

@sgiehl sgiehl merged commit c3b32a5 into 4.x-dev Oct 26, 2021
@sgiehl sgiehl deleted the DEV-2366-filter_API_Response branch October 26, 2021 08:27
@sgiehl sgiehl added not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. and removed Needs Review PRs that need a code review labels Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants