AndyRussG has uploaded a new change for review. https://gerrit.wikimedia.org/r/180650
Change subject: WIP Minor improvements in text fixtures
......................................................................
WIP Minor improvements in text fixtures
- Removed level of array nesting from fixtures and re-added in a
method specifically for PHPUnit data provision.
- Created outer object structure for additional fixture properties
other than test cases (use case upcoming).
- Added a comment
Change-Id: I803ff7868056ae286b4004ea95c13a0f786d462e
---
M tests/CentralNoticeTestFixtures.php
M tests/data/AllocationsFixtures.json
M
tests/qunit/ext.centralNotice.bannerController.lib/bannerController.lib.tests.js
3 files changed, 294 insertions(+), 291 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralNotice
refs/changes/50/180650/1
diff --git a/tests/CentralNoticeTestFixtures.php
b/tests/CentralNoticeTestFixtures.php
index 89eb21b..b7a9f73 100644
--- a/tests/CentralNoticeTestFixtures.php
+++ b/tests/CentralNoticeTestFixtures.php
@@ -129,6 +129,7 @@
}
}
+ //FIXME review, possibly trim and/or document device-related stuff here
protected function getDesktopDevice() {
$dbr = CNDatabase::getDb();
diff --git a/tests/data/AllocationsFixtures.json
b/tests/data/AllocationsFixtures.json
index 07b5673..1f7f144 100644
--- a/tests/data/AllocationsFixtures.json
+++ b/tests/data/AllocationsFixtures.json
@@ -1,14 +1,35 @@
-[
- [ {
- "title": "completeness",
- "fixture": {
- "campaigns": [
+{
+ testCases: [
+ {
+ "title": "completeness",
+ "fixture": {
+ "campaigns": [
+ {
+ "category": "fundraising",
+ "preferred": 1,
+ "throttle": 50,
+ "geotargeted": true,
+ "geo_countries": [
+ "FR",
+ "GR",
+ "XX"
+ ],
+ "banners": [
+ {
+ "name": "b1",
+ "weight": 5
+ }
+ ]
+ }
+ ]
+ },
+ "choices": [
{
- "category": "fundraising",
"preferred": 1,
"throttle": 50,
+ "bucket_count": 1,
"geotargeted": true,
- "geo_countries": [
+ "countries": [
"FR",
"GR",
"XX"
@@ -16,52 +37,62 @@
"banners": [
{
"name": "b1",
- "weight": 5
+ "weight": 5,
+ "bucket": 0,
+ "category": "fundraising",
+ "devices": [
+ "desktop"
+ ]
}
]
}
- ]
+ ],
+ "allocations": {
+ "b1": "0.500"
+ }
},
- "choices": [
- {
- "preferred": 1,
- "throttle": 50,
- "bucket_count": 1,
- "geotargeted": true,
- "countries": [
- "FR",
- "GR",
- "XX"
- ],
- "banners": [
+
+ {
+ "title": "throttling",
+ "fixture": {
+ "campaigns": [
{
- "name": "b1",
- "weight": 5,
- "bucket": 0,
- "category": "fundraising",
- "devices": [
- "desktop"
+ "name": "c1",
+ "preferred": 3,
+ "throttle": 60,
+ "banners": [
+ { "name": "c1b1" },
+ { "name": "c1b2" }
+ ]
+ },
+ {
+ "name": "c2",
+ "preferred": 1,
+ "throttle": 100,
+ "banners": [
+ { "name": "c2b1" },
+ { "name": "c2b2" }
]
}
]
- }
- ],
- "allocations": {
- "b1": "0.500"
- }
- } ],
-
- [ {
- "title": "throttling",
- "fixture": {
- "campaigns": [
+ },
+ "choices": [
{
"name": "c1",
+ "geotargeted": false,
"preferred": 3,
"throttle": 60,
"banners": [
- { "name": "c1b1" },
- { "name": "c1b2" }
+ {
+ "name": "c1b1",
+ "weight": 25,
+ "category": "fundraising"
+ },
+ {
+ "name": "c1b2",
+ "weight": 25,
+ "category": "fundraising"
+ }
]
},
{
@@ -69,62 +100,52 @@
"preferred": 1,
"throttle": 100,
"banners": [
- { "name": "c2b1" },
- { "name": "c2b2" }
+ {
+ "name": "c2b1",
+ "weight": 25,
+ "category": "fundraising"
+ },
+ {
+ "name": "c2b2",
+ "weight": 25,
+ "category": "fundraising"
+ }
]
}
- ]
+ ],
+ "allocations": {
+ "c1b1": "0.300",
+ "c1b2": "0.300",
+ "c2b1": "0.200",
+ "c2b2": "0.200"
+ }
},
- "choices": [
- {
- "name": "c1",
- "geotargeted": false,
- "preferred": 3,
- "throttle": 60,
- "banners": [
+
+ {
+ "title": "overallocation",
+ "fixture": {
+ "campaigns": [
{
- "name": "c1b1",
- "weight": 25,
- "category": "fundraising"
- },
- {
- "name": "c1b2",
- "weight": 25,
- "category": "fundraising"
+ "banners": [
+ {
+ "name": "b1",
+ "weight": 5
+ },
+ {
+ "name": "b2",
+ "weight": 100
+ },
+ {
+ "name": "b3",
+ "weight": 100
+ }
+ ]
}
]
},
- {
- "name": "c2",
- "preferred": 1,
- "throttle": 100,
- "banners": [
- {
- "name": "c2b1",
- "weight": 25,
- "category": "fundraising"
- },
- {
- "name": "c2b2",
- "weight": 25,
- "category": "fundraising"
- }
- ]
- }
- ],
- "allocations": {
- "c1b1": "0.300",
- "c1b2": "0.300",
- "c2b1": "0.200",
- "c2b2": "0.200"
- }
- } ],
-
- [ {
- "title": "overallocation",
- "fixture": {
- "campaigns": [
+ "choices": [
{
+ "throttle": 100,
"banners": [
{
"name": "b1",
@@ -140,63 +161,60 @@
}
]
}
- ]
+ ],
+ "allocations": {
+ "b1": "0.024",
+ "b2": "0.488",
+ "b3": "0.488"
+ }
},
- "choices": [
- {
- "throttle": 100,
- "banners": [
+
+ {
+ "title": "blanks",
+ "fixture": {
+ "campaigns": [
{
- "name": "b1",
- "weight": 5
- },
- {
- "name": "b2",
- "weight": 100
- },
- {
- "name": "b3",
- "weight": 100
+ "throttle": 10,
+ "banners": [
+ { "name": "b1" }
+ ]
}
]
- }
- ],
- "allocations": {
- "b1": "0.024",
- "b2": "0.488",
- "b3": "0.488"
- }
- } ],
-
- [ {
- "title": "blanks",
- "fixture": {
- "campaigns": [
+ },
+ "choices": [
{
"throttle": 10,
"banners": [
{ "name": "b1" }
]
}
- ]
- },
- "choices": [
- {
- "throttle": 10,
- "banners": [
- { "name": "b1" }
- ]
+ ],
+ "allocations": {
+ "b1": 0.100
}
- ],
- "allocations": {
- "b1": 0.100
- }
- } ],
+ },
- [ {
- "title": "priority",
- "fixture": {
- "campaigns": [
+ {
+ "title": "priority",
+ "fixture": {
+ "campaigns": [
+ {
+ "name": "c1",
+ "preferred": 1,
+ "banners": [
+ { "name": "c1b1" }
+ ]
+ },
+ {
+ "name": "c2",
+ "preferred": 2,
+ "banners": [
+ { "name": "c2b1" }
+ ]
+ }
+ ]
+ },
+ "choices": [
{
"name": "c1",
"preferred": 1,
@@ -211,37 +229,36 @@
{ "name": "c2b1" }
]
}
- ]
+ ],
+ "allocations": {
+ "c1b1": 0.000,
+ "c2b1": 1.000
+ }
},
- "choices": [
- {
- "name": "c1",
- "preferred": 1,
- "banners": [
- { "name": "c1b1" }
+
+ {
+ "title": "geoInCountry",
+ "fixture": {
+ "campaigns": [
+ {
+ "geotargeted": true,
+ "geo_countries": [
+ "FR",
+ "XX"
+ ],
+ "banners": [
+ {
+ "name": "b1",
+ "weight": 5
+ }
+ ]
+ }
]
},
- {
- "name": "c2",
- "preferred": 2,
- "banners": [
- { "name": "c2b1" }
- ]
- }
- ],
- "allocations": {
- "c1b1": 0.000,
- "c2b1": 1.000
- }
- } ],
-
- [ {
- "title": "geoInCountry",
- "fixture": {
- "campaigns": [
+ "choices": [
{
"geotargeted": true,
- "geo_countries": [
+ "countries": [
"FR",
"XX"
],
@@ -252,35 +269,35 @@
}
]
}
- ]
+ ],
+ "allocations": {
+ "b1": 1.000
+ }
},
- "choices": [
- {
- "geotargeted": true,
- "countries": [
- "FR",
- "XX"
- ],
- "banners": [
+
+ {
+ "title": "geoNotInCountry",
+ "fixture": {
+ "campaigns": [
{
- "name": "b1",
- "weight": 5
+ "geotargeted": true,
+ "geo_countries": [
+ "FR",
+ "GR"
+ ],
+ "banners": [
+ {
+ "name": "b1",
+ "weight": 5
+ }
+ ]
}
]
- }
- ],
- "allocations": {
- "b1": 1.000
- }
- } ],
-
- [ {
- "title": "geoNotInCountry",
- "fixture": {
- "campaigns": [
+ },
+ "choices": [
{
"geotargeted": true,
- "geo_countries": [
+ "countries": [
"FR",
"GR"
],
@@ -291,119 +308,104 @@
}
]
}
- ]
+ ],
+ "allocations": {
+ }
},
- "choices": [
- {
- "geotargeted": true,
- "countries": [
- "FR",
- "GR"
- ],
- "banners": [
+
+ {
+ "title": "notInProject",
+ "fixture": {
+ "campaigns": [
{
- "name": "b1",
- "weight": 5
+ "projects": [ "wikisource" ],
+ "banners": [
+ {
+ "name": "b1",
+ "weight": 5
+ }
+ ]
}
]
+ },
+ "choices": [
+ ],
+ "allocations": {
}
- ],
- "allocations": {
- }
- } ],
-
- [ {
- "title": "notInProject",
- "fixture": {
- "campaigns": [
- {
- "projects": [ "wikisource" ],
- "banners": [
- {
- "name": "b1",
- "weight": 5
- }
- ]
- }
- ]
},
- "choices": [
- ],
- "allocations": {
- }
- } ],
- [ {
- "title": "notInLanguage",
- "fixture": {
- "campaigns": [
- {
- "project_languages": [ "zh" ],
- "banners": [
- {
- "name": "b1",
- "weight": 5
- }
- ]
- }
- ]
- },
- "choices": [
- ],
- "allocations": {
- }
- } ],
-
- [ {
- "title": "notInTimeWindow",
- "fixture": {
- "campaigns": [
- {
- "startTs": "20010101123456",
- "banners": [
- {
- "name": "b1",
- "weight": 5
- }
- ]
- }
- ]
- },
- "choices": [
- ],
- "allocations": {
- }
- } ],
-
- [ {
- "title": "notAnonymous",
- "fixture": {
- "campaigns": [
- {
- "banners": [
- {
- "displayAnon": false,
- "displayAccount": true,
- "name": "b1",
- "weight": 5
- }
- ]
- }
- ]
- },
- "choices": [
- {
- "banners": [
+ {
+ "title": "notInLanguage",
+ "fixture": {
+ "campaigns": [
{
- "name": "b1",
- "weight": 5,
- "display_anon": false,
- "display_account": true
+ "project_languages": [ "zh" ],
+ "banners": [
+ {
+ "name": "b1",
+ "weight": 5
+ }
+ ]
}
]
+ },
+ "choices": [
+ ],
+ "allocations": {
}
- ],
- "allocations": {
+ },
+
+ {
+ "title": "notInTimeWindow",
+ "fixture": {
+ "campaigns": [
+ {
+ "startTs": "20010101123456",
+ "banners": [
+ {
+ "name": "b1",
+ "weight": 5
+ }
+ ]
+ }
+ ]
+ },
+ "choices": [
+ ],
+ "allocations": {
+ }
+ },
+
+ {
+ "title": "notAnonymous",
+ "fixture": {
+ "campaigns": [
+ {
+ "banners": [
+ {
+ "displayAnon": false,
+ "displayAccount": true,
+ "name": "b1",
+ "weight": 5
+ }
+ ]
+ }
+ ]
+ },
+ "choices": [
+ {
+ "banners": [
+ {
+ "name": "b1",
+ "weight": 5,
+ "display_anon": false,
+ "display_account": true
+ }
+ ]
+ }
+ ],
+ "allocations": {
+ }
}
- } ]
-]
+ ]
+}
diff --git
a/tests/qunit/ext.centralNotice.bannerController.lib/bannerController.lib.tests.js
b/tests/qunit/ext.centralNotice.bannerController.lib/bannerController.lib.tests.js
index f1d622f..02e207b 100644
---
a/tests/qunit/ext.centralNotice.bannerController.lib/bannerController.lib.tests.js
+++
b/tests/qunit/ext.centralNotice.bannerController.lib/bannerController.lib.tests.js
@@ -27,14 +27,14 @@
QUnit.test( 'allocations test cases', function( assert ) {
var testFixtures = mw.centralNoticeTestFixtures,
+ testCases = testFixtures.testCases,
lib = mw.cnBannerControllerLib;
- assert.ok( testFixtures.length );
- QUnit.expect( testFixtures.length + 1 );
+ assert.ok( testCases.length );
+ QUnit.expect( testCases.length + 1 );
- $.each( testFixtures, function( index, testFixturesInputs ) {
- var testCase = testFixturesInputs[0],
- choices,
+ $.each( testCases, function( index, testCase ) {
+ var choices,
choice,
i,
allocatedBanner;
--
To view, visit https://gerrit.wikimedia.org/r/180650
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I803ff7868056ae286b4004ea95c13a0f786d462e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: AndyRussG <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
