Skip to content

Commit 3cf5c24

Browse files
authored
Merge pull request #2096 from magento-performance/MAGETWO-87815
[Performance] MAGETWO-87815: Update PAT scenarios for caching popular search terms functionality
2 parents 7814f7d + a7c2290 commit 3cf5c24

File tree

4 files changed

+180
-22
lines changed

4 files changed

+180
-22
lines changed

app/code/Magento/CatalogSearch/view/frontend/web/js/search-terms-log.js

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,17 @@
44
*/
55

66
define([
7-
'jquery'
8-
], function ($) {
7+
'jquery',
8+
'mageUtils'
9+
], function ($, utils) {
910
'use strict';
1011

11-
/**
12-
* Return url parameters.
13-
* @returns {Object}
14-
*/
15-
function urlParameters() {
16-
var params = {},
17-
queries = window.location.search.substring(1).split('&'),
18-
temp,
19-
i,
20-
l;
21-
22-
for (i = 0, l = queries.length; i < l; i++) {
23-
temp = queries[i].split('=');
24-
params[temp[0]] = temp[1];
25-
}
26-
27-
return params;
28-
}
29-
3012
return function (data) {
3113
$.ajax({
3214
method: 'GET',
3315
url: data.url,
3416
data: {
35-
'q': urlParameters().q
17+
'q': utils.getUrlParameters(window.location.href).q
3618
}
3719
});
3820
};

dev/tests/js/jasmine/tests/lib/mage/misc.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,40 @@ define([
1111

1212
describe('mageUtils', function () {
1313

14+
it('Check getUrlParameters function', function () {
15+
var fixture,
16+
url,
17+
getParameters;
18+
19+
fixture = {
20+
'not valid url': {},
21+
'http://example.com/catalogsearch/result/': {},
22+
'http://example.com/catalogsearch/result/?': {},
23+
'http://example.com/catalogsearch/result/?q': {
24+
q: ''
25+
},
26+
'http://example.com/catalogsearch/result/?q=': {
27+
q: ''
28+
},
29+
'http://example.com/catalogsearch/result/?q=+Simple+99%2C+8%2F%3F&cat=3': {
30+
q: ' Simple 99, 8/?',
31+
cat: '3'
32+
},
33+
'http://example.com/catalogsearch/result/?q=Simple&cat=3&p=1': {
34+
q: 'Simple',
35+
cat: '3',
36+
p: '1'
37+
}
38+
};
39+
40+
for (url in fixture) {
41+
if (fixture.hasOwnProperty(url)) {
42+
getParameters = fixture[url];
43+
expect(utils.getUrlParameters(url)).toEqual(getParameters);
44+
}
45+
}
46+
});
47+
1448
it('Check convertToMomentFormat function', function () {
1549
var format, momentFormat;
1650

lib/web/mage/utils/misc.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,38 @@ define([
255255
newFormat = newFormat.replace(/dd|d/g, 'DD'); // replace the date
256256

257257
return newFormat;
258+
},
259+
260+
/**
261+
* Get Url Parameters.
262+
*
263+
* @param {String} url - Url string
264+
* @returns {Object}
265+
*/
266+
getUrlParameters: function (url) {
267+
var params = {},
268+
queries = url.split('?'),
269+
temp,
270+
i,
271+
l;
272+
273+
if (!queries[1]) {
274+
return params;
275+
}
276+
277+
queries = queries[1].split('&');
278+
279+
for (i = 0, l = queries.length; i < l; i++) {
280+
temp = queries[i].split('=');
281+
282+
if (temp[1]) {
283+
params[temp[0]] = decodeURIComponent(temp[1].replace(/\+/g, '%20'));
284+
} else {
285+
params[temp[0]] = '';
286+
}
287+
}
288+
289+
return params;
258290
}
259291
};
260292
});

setup/performance-toolkit/benchmark.jmx

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,8 +2931,63 @@ if (testLabel
29312931
<stringProp name="RegexExtractor.match_number">-1</stringProp>
29322932
</RegexExtractor>
29332933
<hashTree/>
2934+
<RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="Regular Expression Extractor: isPageCacheable" enabled="true">
2935+
<stringProp name="RegexExtractor.useHeaders">false</stringProp>
2936+
<stringProp name="RegexExtractor.refname">isPageCacheable</stringProp>
2937+
<stringProp name="RegexExtractor.regex">catalogsearch/searchTermsLog/save</stringProp>
2938+
<stringProp name="RegexExtractor.template">$0$</stringProp>
2939+
<stringProp name="RegexExtractor.default">0</stringProp>
2940+
<stringProp name="RegexExtractor.match_number">1</stringProp>
2941+
</RegexExtractor>
2942+
<hashTree/>
29342943
</hashTree>
29352944

2945+
<IfController guiclass="IfControllerPanel" testclass="IfController" testname="If Controller" enabled="true">
2946+
<stringProp name="IfController.condition">"${isPageCacheable}" != "0"</stringProp>
2947+
<boolProp name="IfController.evaluateAll">false</boolProp>
2948+
<stringProp name="TestPlan.comments">mpaf/tool/fragments/ce/search/if_page_cacheable_controller.jmx</stringProp></IfController>
2949+
<hashTree>
2950+
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="Search Terms Log" enabled="true">
2951+
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" enabled="true">
2952+
<collectionProp name="Arguments.arguments">
2953+
<elementProp name="q" elementType="HTTPArgument">
2954+
<boolProp name="HTTPArgument.always_encode">true</boolProp>
2955+
<stringProp name="Argument.name">q</stringProp>
2956+
<stringProp name="Argument.value">${searchTerm}</stringProp>
2957+
<stringProp name="Argument.metadata">=</stringProp>
2958+
<boolProp name="HTTPArgument.use_equals">true</boolProp>
2959+
</elementProp>
2960+
</collectionProp>
2961+
</elementProp>
2962+
<stringProp name="HTTPSampler.domain"/>
2963+
<stringProp name="HTTPSampler.port"/>
2964+
<stringProp name="HTTPSampler.connect_timeout"/>
2965+
<stringProp name="HTTPSampler.response_timeout"/>
2966+
<stringProp name="HTTPSampler.protocol">${request_protocol}</stringProp>
2967+
<stringProp name="HTTPSampler.contentEncoding"/>
2968+
<stringProp name="HTTPSampler.path">${base_path}catalogsearch/searchTermsLog/save/</stringProp>
2969+
<stringProp name="HTTPSampler.method">GET</stringProp>
2970+
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
2971+
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
2972+
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
2973+
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
2974+
<boolProp name="HTTPSampler.monitor">false</boolProp>
2975+
<stringProp name="HTTPSampler.embedded_url_re"/>
2976+
<stringProp name="TestPlan.comments">mpaf/tool/fragments/ce/search/search_terms_log_save.jmx</stringProp>
2977+
</HTTPSamplerProxy>
2978+
<hashTree>
2979+
<ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="Response Assertion: Assert search result" enabled="true">
2980+
<collectionProp name="Asserion.test_strings">
2981+
<stringProp name="-547797305">"success":true</stringProp>
2982+
</collectionProp>
2983+
<stringProp name="Assertion.test_field">Assertion.response_data</stringProp>
2984+
<boolProp name="Assertion.assume_success">false</boolProp>
2985+
<intProp name="Assertion.test_type">2</intProp>
2986+
</ResponseAssertion>
2987+
<hashTree/>
2988+
</hashTree>
2989+
</hashTree>
2990+
29362991
<BeanShellSampler guiclass="BeanShellSamplerGui" testclass="BeanShellSampler" testname="SetUp - Set Arguments" enabled="true">
29372992
<stringProp name="BeanShellSampler.query">
29382993
foundProducts = Integer.parseInt(vars.get("product_url_keys_matchNr"));
@@ -3174,8 +3229,63 @@ if (testLabel
31743229
<stringProp name="RegexExtractor.match_number">-1</stringProp>
31753230
</RegexExtractor>
31763231
<hashTree/>
3232+
<RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="Regular Expression Extractor: isPageCacheable" enabled="true">
3233+
<stringProp name="RegexExtractor.useHeaders">false</stringProp>
3234+
<stringProp name="RegexExtractor.refname">isPageCacheable</stringProp>
3235+
<stringProp name="RegexExtractor.regex">catalogsearch/searchTermsLog/save</stringProp>
3236+
<stringProp name="RegexExtractor.template">$0$</stringProp>
3237+
<stringProp name="RegexExtractor.default">0</stringProp>
3238+
<stringProp name="RegexExtractor.match_number">1</stringProp>
3239+
</RegexExtractor>
3240+
<hashTree/>
31773241
</hashTree>
31783242

3243+
<IfController guiclass="IfControllerPanel" testclass="IfController" testname="If Controller" enabled="true">
3244+
<stringProp name="IfController.condition">"${isPageCacheable}" != "0"</stringProp>
3245+
<boolProp name="IfController.evaluateAll">false</boolProp>
3246+
<stringProp name="TestPlan.comments">mpaf/tool/fragments/ce/search/if_page_cacheable_controller.jmx</stringProp></IfController>
3247+
<hashTree>
3248+
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="Search Terms Log" enabled="true">
3249+
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" enabled="true">
3250+
<collectionProp name="Arguments.arguments">
3251+
<elementProp name="q" elementType="HTTPArgument">
3252+
<boolProp name="HTTPArgument.always_encode">true</boolProp>
3253+
<stringProp name="Argument.name">q</stringProp>
3254+
<stringProp name="Argument.value">${searchTerm}</stringProp>
3255+
<stringProp name="Argument.metadata">=</stringProp>
3256+
<boolProp name="HTTPArgument.use_equals">true</boolProp>
3257+
</elementProp>
3258+
</collectionProp>
3259+
</elementProp>
3260+
<stringProp name="HTTPSampler.domain"/>
3261+
<stringProp name="HTTPSampler.port"/>
3262+
<stringProp name="HTTPSampler.connect_timeout"/>
3263+
<stringProp name="HTTPSampler.response_timeout"/>
3264+
<stringProp name="HTTPSampler.protocol">${request_protocol}</stringProp>
3265+
<stringProp name="HTTPSampler.contentEncoding"/>
3266+
<stringProp name="HTTPSampler.path">${base_path}catalogsearch/searchTermsLog/save/</stringProp>
3267+
<stringProp name="HTTPSampler.method">GET</stringProp>
3268+
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
3269+
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
3270+
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
3271+
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
3272+
<boolProp name="HTTPSampler.monitor">false</boolProp>
3273+
<stringProp name="HTTPSampler.embedded_url_re"/>
3274+
<stringProp name="TestPlan.comments">mpaf/tool/fragments/ce/search/search_terms_log_save.jmx</stringProp>
3275+
</HTTPSamplerProxy>
3276+
<hashTree>
3277+
<ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="Response Assertion: Assert search result" enabled="true">
3278+
<collectionProp name="Asserion.test_strings">
3279+
<stringProp name="-547797305">"success":true</stringProp>
3280+
</collectionProp>
3281+
<stringProp name="Assertion.test_field">Assertion.response_data</stringProp>
3282+
<boolProp name="Assertion.assume_success">false</boolProp>
3283+
<intProp name="Assertion.test_type">2</intProp>
3284+
</ResponseAssertion>
3285+
<hashTree/>
3286+
</hashTree>
3287+
</hashTree>
3288+
31793289
<IfController guiclass="IfControllerPanel" testclass="IfController" testname="If Attribute 1 present in layered navigation" enabled="true">
31803290
<stringProp name="IfController.condition">${attribute_1_options_count} &gt; 0</stringProp>
31813291
<boolProp name="IfController.evaluateAll">false</boolProp>

0 commit comments

Comments
 (0)