jenkins-bot has submitted this change and it was merged.

Change subject: Remove defaults for setup in test fixtures
......................................................................


Remove defaults for setup in test fixtures

This is the second step in removing defaults for test fixture data,
to make way for expanded fixture coverage (and the complexification
of fixtures that entails).

Defaults are not removed for legacy tests that do not use the shared
fixture data. Also, test fixture data setup is provided a few default
properties that are not relevant to the tests covered by the fixture
data. (TODOs add to placeholder fixture documentation for this.)

Finally, CentralNoticeTestFixutres is reorganized and PHPdoc'd a bit,
support for setting devices and buckets in setup is added, and
some property names are tweaked.

Legacy tests are left more or less alone.

Change-Id: I063a4b421b6e9c169121c8a0a855d9706fa4e0ec
---
M tests/ApiAllocationsTest.php
M tests/ApiCentralNoticeBannerChoiceDataTest.php
M tests/BannerAllocationCalculatorTest.php
M tests/BannerChoiceDataProviderTest.php
M tests/BannerChooserTest.php
M tests/BannerTest.php
M tests/CNBannerChoicesResourceLoaderModuleTest.php
M tests/CentralNoticeTest.php
M tests/CentralNoticeTestFixtures.php
M tests/HistoryTest.php
M tests/data/AllocationsFixtures.json
M tests/data/allocation_fixtures_doc.md
M 
tests/qunit/ext.centralNotice.bannerController.lib/bannerController.lib.tests.js
13 files changed, 495 insertions(+), 158 deletions(-)

Approvals:
  Awight: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests/ApiAllocationsTest.php b/tests/ApiAllocationsTest.php
index 5de3041..9af7041 100644
--- a/tests/ApiAllocationsTest.php
+++ b/tests/ApiAllocationsTest.php
@@ -24,16 +24,20 @@
 
        public function testEqualAllocations() {
                // Campaign has two banners, with default parameters
-               $this->cnFixtures->setupTestCase( array(
-                       'campaigns' => array(
-                               array(
-                                       'banners' => array(
-                                               array(),
-                                               array()
+               $this->cnFixtures->setupTestCaseWithDefaults(
+                       array(
+                               'setup' => array(
+                                       'campaigns' => array(
+                                               array(
+                                                       'banners' => array(
+                                                               array(),
+                                                               array()
+                                                       ),
+                                               ),
                                        ),
                                ),
-                       ),
-               ) );
+                       ) );
+
                $expected = array(
                        'centralnoticeallocations' => array(
                                'banners' => array(
diff --git a/tests/ApiCentralNoticeBannerChoiceDataTest.php 
b/tests/ApiCentralNoticeBannerChoiceDataTest.php
index 3aad3be..a8cb0f1 100644
--- a/tests/ApiCentralNoticeBannerChoiceDataTest.php
+++ b/tests/ApiCentralNoticeBannerChoiceDataTest.php
@@ -25,13 +25,12 @@
         */
        public function testBannerChoiceResponse( $name, $testCase ) {
 
-               $this->cnFixtures->prepareTestcase( $testCase );
-               $this->cnFixtures->setupTestCase( $testCase['setup'] );
+               $this->cnFixtures->setupTestCaseFromFixtureData( $testCase );
 
                $ret = $this->doApiRequest( array(
                        'action' => 'centralnoticebannerchoicedata',
                        'project' => 
CentralNoticeTestFixtures::$defaultCampaign['projects'][0],
-                       'language' => 
CentralNoticeTestFixtures::$defaultCampaign['project_languages'][0]
+                       'language' => 
CentralNoticeTestFixtures::$defaultCampaign['languages'][0]
                ) );
                $this->assertTrue( ComparisonUtil::assertSuperset( 
$ret[0]['choices'], $testCase['choices'] ) );
        }
diff --git a/tests/BannerAllocationCalculatorTest.php 
b/tests/BannerAllocationCalculatorTest.php
index 101d93c..d681d2f 100644
--- a/tests/BannerAllocationCalculatorTest.php
+++ b/tests/BannerAllocationCalculatorTest.php
@@ -25,8 +25,7 @@
         */
        public function testAllocations( $name, $testCase ) {
 
-               $this->cnFixtures->prepareTestcase( $testCase );
-               $this->cnFixtures->setupTestCase( $testCase['setup'] );
+               $this->cnFixtures->setupTestCaseFromFixtureData( $testCase );
 
                $allocationsProvider = new BannerChoiceDataProvider(
                        CentralNoticeTestFixtures::getDefaultProject(),
diff --git a/tests/BannerChoiceDataProviderTest.php 
b/tests/BannerChoiceDataProviderTest.php
index 035a657..7c28e8c 100644
--- a/tests/BannerChoiceDataProviderTest.php
+++ b/tests/BannerChoiceDataProviderTest.php
@@ -25,12 +25,11 @@
         */
        public function testProviderResponse( $name, $testCase ) {
 
-               $this->cnFixtures->prepareTestcase( $testCase );
-               $this->cnFixtures->setupTestCase( $testCase['setup'] );
+               $this->cnFixtures->setupTestCaseFromFixtureData( $testCase );
 
                $allocationsProvider = new BannerChoiceDataProvider(
                        
CentralNoticeTestFixtures::$defaultCampaign['projects'][0],
-                       
CentralNoticeTestFixtures::$defaultCampaign['project_languages'][0]
+                       
CentralNoticeTestFixtures::$defaultCampaign['languages'][0]
                );
                $choices = $allocationsProvider->getChoices();
                $this->assertTrue( ComparisonUtil::assertSuperset( $choices, 
$testCase['choices'] ) );
diff --git a/tests/BannerChooserTest.php b/tests/BannerChooserTest.php
index de9c6ad..fdec9f5 100644
--- a/tests/BannerChooserTest.php
+++ b/tests/BannerChooserTest.php
@@ -21,26 +21,30 @@
        }
 
        public function testThrottlingCampaign() {
-               $this->cnFixtures->setupTestCase( array(
-                       'campaigns' => array(
-                               array(
-                                       'preferred' => 
CentralNotice::NORMAL_PRIORITY,
-                                       'throttle' => 60,
-                                       'banners' => array(
-                                               array(),
-                                               array()
+               $this->cnFixtures->setupTestCaseWithDefaults(
+                       array(
+                               'setup' => array(
+                                       'campaigns' => array(
+                                               array(
+                                                       'preferred' => 
CentralNotice::NORMAL_PRIORITY,
+                                                       'throttle' => 60,
+                                                       'banners' => array(
+                                                               array(),
+                                                               array()
+                                                       ),
+                                               ),
+                                               array(
+                                                       'preferred' => 
CentralNotice::LOW_PRIORITY,
+                                                       'throttle' => 100,
+                                                       'banners' => array(
+                                                               array(),
+                                                               array()
+                                                       ),
+                                               ),
                                        ),
-                               ),
-                               array(
-                                       'preferred' => 
CentralNotice::LOW_PRIORITY,
-                                       'throttle' => 100,
-                                       'banners' => array(
-                                               array(),
-                                               array()
-                                       ),
-                               ),
-                       ),
-               ) );
+                               )
+                       ) );
+
                $expected = array(
                        array (
                                'name' => 
$this->cnFixtures->spec['campaigns'][1]['banners'][0]['name'],
@@ -80,23 +84,26 @@
        }
 
        public function testOverAllocation() {
-               $this->cnFixtures->setupTestCase( array(
-                       'campaigns' => array(
-                               array(
-                                       'banners' => array(
+               $this->cnFixtures->setupTestCaseWithDefaults(
+                       array(
+                               'setup' => array(
+                                       'campaigns' => array(
                                                array(
-                                                       'weight' => 5,
-                                               ),
-                                               array(
-                                                       'weight' => 100,
-                                               ),
-                                               array(
-                                                       'weight' => 100,
+                                                       'banners' => array(
+                                                               array(
+                                                                       
'weight' => 5,
+                                                               ),
+                                                               array(
+                                                                       
'weight' => 100,
+                                                               ),
+                                                               array(
+                                                                       
'weight' => 100,
+                                                               ),
+                                                       ),
                                                ),
                                        ),
-                               ),
-                       ),
-               ) );
+                               )
+                       ) );
                $expected = array(
                        array (
                                'weight' => 5,
@@ -120,16 +127,19 @@
        }
 
        public function testBlanks() {
-               $this->cnFixtures->setupTestCase( array(
-                       'campaigns' => array(
-                               array(
-                                       'throttle' => 10,
-                                       'banners' => array(
-                                               array(),
+               $this->cnFixtures->setupTestCaseWithDefaults(
+                       array(
+                               'setup' => array(
+                                       'campaigns' => array(
+                                               array(
+                                                       'throttle' => 10,
+                                                       'banners' => array(
+                                                               array(),
+                                                       ),
+                                               ),
                                        ),
-                               ),
-                       ),
-               ) );
+                               )
+                       ) );
                $expected = array(
                        array(
                                'slots' => 3,
@@ -148,22 +158,26 @@
        }
 
        public function testPriority() {
-               $this->cnFixtures->setupTestCase( array(
-                       'campaigns' => array(
-                               array(
-                                       'preferred' => 
CentralNotice::LOW_PRIORITY,
-                                       'banners' => array(
-                                               array(),
+               $this->cnFixtures->setupTestCaseWithDefaults(
+                       array(
+                               'setup' => array(
+                                       'campaigns' => array(
+                                               array(
+                                                       'preferred' => 
CentralNotice::LOW_PRIORITY,
+                                                       'banners' => array(
+                                                               array(),
+                                                       ),
+                                               ),
+                                               array(
+                                                       'preferred' => 
CentralNotice::NORMAL_PRIORITY,
+                                                       'banners' => array(
+                                                               array(),
+                                                       ),
+                                               ),
                                        ),
-                               ),
-                               array(
-                                       'preferred' => 
CentralNotice::NORMAL_PRIORITY,
-                                       'banners' => array(
-                                               array(),
-                                       ),
-                               ),
-                       ),
-               ) );
+                               )
+                       ) );
+
                $expected = array(
                        array(
                                'campaign' => 
$this->cnFixtures->spec['campaigns'][0]['name'],
diff --git a/tests/BannerTest.php b/tests/BannerTest.php
index 2a7a13e..b9f4e77 100644
--- a/tests/BannerTest.php
+++ b/tests/BannerTest.php
@@ -20,7 +20,9 @@
        protected function setUp() {
                parent::setUp();
                $this->fixture = new CentralNoticeTestFixtures();
-               $this->fixture->setupTestCase( array( 'campaigns' => array() ) 
);
+
+               $this->fixture->setupTestCaseWithDefaults(
+                       array( 'setup' => array( 'campaigns' => array() ) ) );
        }
 
        public function tearDown() {
diff --git a/tests/CNBannerChoicesResourceLoaderModuleTest.php 
b/tests/CNBannerChoicesResourceLoaderModuleTest.php
index c5be722..d4182c4 100644
--- a/tests/CNBannerChoicesResourceLoaderModuleTest.php
+++ b/tests/CNBannerChoicesResourceLoaderModuleTest.php
@@ -22,7 +22,7 @@
                        'modules' => 'ext.centralNotice.bannerChoiceData',
                        'skin' => 'fallback',
                        'user' => false,
-                       'uselang' => 
CentralNoticeTestFixtures::$defaultCampaign['project_languages'][0],
+                       'uselang' => 'en' // Note: this is a temporary measure 
                ) );
                $this->rlContext = new ResourceLoaderContext( new 
ResourceLoader(), $fauxRequest );
        }
@@ -41,7 +41,7 @@
        protected function addSomeBanners() {
                $fixtures = CentralNoticeTestFixtures::allocationsData();
                $completeness = $fixtures['testCases']['completeness'];
-               $this->cnFixtures->setupTestCase( $completeness['setup'] );
+               $this->cnFixtures->setupTestCaseFromFixtureData( $completeness 
);
        }
 
        public function testDisabledByConfig() {
@@ -59,8 +59,7 @@
        public function testChoicesFromDb( $name, $testCase ) {
                $this->setMwGlobals( 'wgCentralDBname', wfWikiID() );
 
-               $this->cnFixtures->prepareTestcase( $testCase );
-               $this->cnFixtures->setupTestCase( $testCase['setup'] );
+               $this->cnFixtures->setupTestCaseFromFixtureData( $testCase );
 
                $choices = $this->getProvider()->getChoicesForTesting( 
$this->rlContext );
                $this->assertTrue( ComparisonUtil::assertSuperset( $choices, 
$testCase['choices'] ) );
diff --git a/tests/CentralNoticeTest.php b/tests/CentralNoticeTest.php
index 0e4126d..d69c05d 100644
--- a/tests/CentralNoticeTest.php
+++ b/tests/CentralNoticeTest.php
@@ -30,13 +30,14 @@
                $enabled           = 0;
                $startTs           = '20110718' . '235500';
                $projects          = array( 'wikipedia', 'wikibooks' );
-               $project_languages = array( 'en', 'de' );
+               $languages = array( 'en', 'de' );
                $geotargeted       = 1;
-               $geo_countries     = array( 'US', 'AF' );
+               $countries     = array( 'US', 'AF' );
                $preferred         = 1;
 
                $this->fixture = new CentralNoticeTestFixtures();
-               $this->fixture->setupTestCase( array( 'campaigns' => array() ) 
);
+               $this->fixture->setupTestCaseWithDefaults(
+                       array( 'setup' => array( 'campaigns' => array() ) ) );
 
                $this->campaignArray = array(
                        'enabled' => '0',
@@ -62,7 +63,7 @@
                        $this->userUser->load();
                }
                Campaign::addCampaign( $noticeName, $enabled, $startTs, 
$projects,
-                       $project_languages, $geotargeted, $geo_countries,
+                       $languages, $geotargeted, $countries,
                        100, $preferred, $this->userUser );
 
                $this->campaignId = Campaign::getNoticeId( 
'PHPUnitTestCampaign' );
diff --git a/tests/CentralNoticeTestFixtures.php 
b/tests/CentralNoticeTestFixtures.php
index 9e153d7..62fef39 100644
--- a/tests/CentralNoticeTestFixtures.php
+++ b/tests/CentralNoticeTestFixtures.php
@@ -19,21 +19,21 @@
                        // inclusive comparison is used, so this does not cause 
a race condition.
                        'startTs' => wfTimestamp( TS_MW ),
                        'projects' => array( 
CentralNoticeTestFixtures::getDefaultProject() ),
-                       'project_languages' => array( 
CentralNoticeTestFixtures::getDefaultLanguage() ),
+                       'languages' => array( 
CentralNoticeTestFixtures::getDefaultLanguage() ),
                        'preferred' => CentralNotice::NORMAL_PRIORITY,
                        'geotargeted' => 0,
-                       'geo_countries' => array( 
CentralNoticeTestFixtures::getDefaultCountry() ),
+                       'countries' => array( 
CentralNoticeTestFixtures::getDefaultCountry() ),
                        'throttle' => 100,
                        'banners' => array(),
                );
                static::$defaultBanner = array(
+                       'bucket' => 0,
                        'body' => 'testing',
                        'displayAnon' => true,
                        'displayAccount' => true,
                        'fundraising' => 1,
                        'autolink' => 0,
                        'landingPages' => 'JA1, JA2',
-                       'campaign_z_index' => 0,
                        'weight' => 25,
                );
        }
@@ -55,18 +55,70 @@
        }
 
        /**
+        * Set up a test case as required for shared JSON data. Process the 
special
+        * startDaysFromNow and endDaysFromNow properties, ensure an empty
+        * countries property for non-geotargetted campaigns, and add dummy
+        * banner bodies.
         *
-        * @see bannerController.lib.tests.js
-        *
-        * @param TS_UNIX $testCase
+        * @param array $testCase A data structure with the test case 
specification
         */
-       function prepareTestcase( &$testCase ) {
+       function setupTestCaseFromFixtureData( &$testCase ) {
+               $this->setTestCaseStartEnd( $testCase );
+               $this->preprocessSetupCountriesProp( $testCase['setup'] );
+               $this->addDummyBannerBody( $testCase['setup'] );
+               $this->setupTestCase( $testCase['setup'] );
+       }
+
+       /**
+        * Set up a test case with defaults, for legacy tests that don't use the
+        * shared JSON fixture data.
+        *
+        * @param array $testCase A data structure with the test case 
specification
+        */
+       function setupTestCaseWithDefaults( $testCase ) {
+               $this->addTestCaseDefaults( $testCase['setup'] );
+               $this->setupTestCase( $testCase['setup'] );
+       }
+
+       /**
+        * Add defaults to the test case setup specification, for legacy tests 
that
+        * don't use the shared JSON fixture data. 
+        *
+        * @param array $testCaseSetup A data structure with the setup section 
of a
+        *  test case specification
+        */
+       protected function addTestCaseDefaults( &$testCaseSetup ) {
+
+               foreach ( $testCaseSetup['campaigns'] as &$campaign ) {
+                       $campaign = $campaign + static::$defaultCampaign + 
array(
+                                       'name' => 'TestCampaign_' . rand(),
+                       );
+
+                       foreach ( $campaign['banners'] as &$banner ) {
+                               $banner = $banner + static::$defaultBanner + 
array(
+                                               'name' => 'TestBanner_' . 
rand(),
+                               );
+                       }
+               }
+       }
+
+       /**
+        * Set campaign start and end times for test case fixtures using the
+        * startDaysFromNow and endDaysFromNow properties.
+        *
+        * Note: this logic is repeated in client-side tests.
+        * @see setTestCaseStartEnd() in bannerController.lib.tests.js
+        *
+        * @param array $testCase A data structure with the test case 
specification
+        */
+       protected function setTestCaseStartEnd( &$testCase ) {
+
                $now = wfTimestamp();
 
                foreach ( $testCase['setup']['campaigns'] as &$campaign ) {
 
                        $start = CentralNoticeTestFixtures::makeTimestamp(
-                               $now, $campaign['startDaysFromNow'] );
+                                       $now, $campaign['startDaysFromNow'] );
 
                        $campaign['startTs'] = wfTimestamp( TS_MW, $start );
 
@@ -92,67 +144,123 @@
                }
        }
 
-       private static function makeTimestamp( $now, $offsetInDays ) {
+       /**
+        * For test case setup, provide an empty array of countries for
+        * non-geotargeted campaigns, and check for mistakenly set countries for
+        * such campaigns.
+        *
+        * @param array $testCaseSetup A data structure with the setup section 
of a
+        *  test case specification
+        */
+       protected function preprocessSetupCountriesProp( &$testCaseSetup ) {
+
+               foreach ( $testCaseSetup['campaigns'] as &$campaign ) {
+
+                       if ( !$campaign['geotargeted'] ) {
+                               if ( !isset( $campaign['countries'] ) ) {
+                                       $campaign['countries'] = array();
+                               } else {
+                                       throw new MWException( "Campaign is not 
geotargetted but "
+                                                       . "'countries' property 
is set." );
+                               }
+                       }
+               }
+       }
+
+       /**
+        * Add dummy banner properties throughout a test case setup 
specification. 
+        *
+        * @param array $testCaseSetup A data structure with the setup section 
of a
+        *  test case specification
+        */
+       protected function addDummyBannerBody( &$testCaseSetup ) {
+               foreach ( $testCaseSetup['campaigns'] as &$campaign ) {
+                       foreach ( $campaign['banners'] as &$banner ) {
+                               $banner['body'] = $banner['name'] . ' body';
+                       }
+               }
+       }
+
+       /**
+        * Make a timestamp offset from the current time by a number of days.
+        *
+        * @param MW_TS $now Timestamp of the current time
+        * @param unknown $offsetInDays
+        * @return MW_TS
+        */
+       protected static function makeTimestamp( $now, $offsetInDays ) {
                return $now + ( 86400 * $offsetInDays );
        }
 
-       function setupTestCase( $spec ) {
+       /**
+        * Create campaigns and related banners according to a test case setup
+        * specification.
+        *
+        * @param array $testCaseSetup A data structure with the setup section 
of a
+        *  test case specification
+        */
+       protected function setupTestCase( $testCaseSetup ) {
                $this->ensureDesktopDevice();
 
-               foreach ( $spec['campaigns'] as $campaignSpec ) {
-                       $campaign = $campaignSpec + static::$defaultCampaign + 
array(
-                               'name' => 'TestCampaign_' . rand(),
-                       );
+               foreach ( $testCaseSetup['campaigns'] as $campaign ) {
 
                        $campaign['id'] = Campaign::addCampaign(
                                $campaign['name'],
                                $campaign['enabled'],
                                $campaign['startTs'],
                                $campaign['projects'],
-                               $campaign['project_languages'],
+                               $campaign['languages'],
                                $campaign['geotargeted'],
-                               $campaign['geo_countries'],
+                               $campaign['countries'],
                                $campaign['throttle'],
                                $campaign['preferred'],
                                $this->user
                        );
 
                        // Update notice end date only if that property was 
sent in.
-                       // It may not be there since it's not in the defaults; 
not adding
-                       // since defaults will soon be removed (for json-based 
test
-                       // fixtures).
+                       // It may not be there since it's not in the defaults
+                       // (used by legacy tests).
                        if ( isset( $campaign['endTs'] ) ) {
                                Campaign::updateNoticeDate( $campaign['name'],
                                        $campaign['startTs'], 
$campaign['endTs'] );
                        }
 
-                       $banners = array();
+                       // autolink and landingPage properties are not relevant 
to tests set
+                       // up via fixture data and may not be provided. For 
those
+                       // parameters, in that case, provide the default value 
in the
+                       // Banner::addTemplate method signature.
                        foreach ( $campaign['banners'] as $bannerSpec ) {
-                               $banner = $bannerSpec + static::$defaultBanner 
+ array(
-                                       'name' => 'TestBanner_' . rand(),
-                               );
-
                                Banner::addTemplate(
-                                       $banner['name'],
-                                       $banner['body'],
+                                       $bannerSpec['name'],
+                                       $bannerSpec['body'],
                                        $this->user,
-                                       $banner['displayAnon'],
-                                       $banner['displayAccount'],
-                                       $banner['fundraising'],
-                                       $banner['autolink'],
-                                       $banner['landingPages']
+                                       $bannerSpec['displayAnon'],
+                                       $bannerSpec['displayAccount'],
+                                       $bannerSpec['fundraising'],
+                                       isset( $bannerSpec['autolink'] ) ? 
$bannerSpec['autolink'] : 0,
+                                       isset( $bannerSpec['landingPages'] ) ? 
$bannerSpec['landingPages'] : ''
                                );
 
-                               // FIXME Can't test buckets other than 0, the 
(!) default
                                Campaign::addTemplateTo(
                                        $campaign['name'],
-                                       $banner['name'],
-                                       $banner['weight']
+                                       $bannerSpec['name'],
+                                       $bannerSpec['weight']
                                );
 
-                               $banners[] = $banner;
+                               $bannerObj = Banner::fromName( 
$bannerSpec['name'] );
+                               
+                               if ( isset( $bannerSpec['bucket'] ) ) {
+                                       Campaign::updateBucket(
+                                               $campaign['name'],
+                                               $bannerObj->getId(),
+                                               $bannerSpec['bucket'] );
+                               }
+
+                               if ( isset( $bannerSpec['devices'] ) ) {
+                                       $bannerObj->setDevices( 
$bannerSpec['devices'] );
+                                       $bannerObj->save();
+                               }
                        }
-                       $campaign['banners'] = $banners;
 
                        $this->spec['campaigns'][] = $campaign;
                }
diff --git a/tests/HistoryTest.php b/tests/HistoryTest.php
index cbaeb88..5f080f0 100644
--- a/tests/HistoryTest.php
+++ b/tests/HistoryTest.php
@@ -23,15 +23,18 @@
        public function testStaleHistoricalCampaigns() {
                // Bug was that expired campaigns would still be included in the
                // history, as long as they were enabled.
-               $this->cnFixtures->setupTestCase( array(
-                       'campaigns' => array(
-                               array(
-                                       'banners' => array(
-                                               array()
+               $this->cnFixtures->setupTestCaseWithDefaults(
+                       array(
+                               'setup' => array(
+                                       'campaigns' => array(
+                                               array(
+                                                       'banners' => array(
+                                                               array()
+                                                       ),
+                                               ),
                                        ),
-                               ),
-                       ),
-               ) );
+                               )
+                       ) );
 
                $made_by_ts = wfTimestamp( TS_MW );
                $this->assertEquals( 1, count( 
Campaign::getHistoricalCampaigns( $made_by_ts ) ) );
diff --git a/tests/data/AllocationsFixtures.json 
b/tests/data/AllocationsFixtures.json
index be5d166..eadc9b4 100644
--- a/tests/data/AllocationsFixtures.json
+++ b/tests/data/AllocationsFixtures.json
@@ -5,21 +5,30 @@
                 "campaigns": [
                     {
                         "name": "c1",
+                        "enabled": 1,
                         "startDaysFromNow": 0,
                         "endDaysFromNow": 1,
-                        "category": "fundraising",
                         "preferred": 1,
                         "throttle": 50,
                         "geotargeted": true,
-                        "geo_countries": [
+                        "countries": [
                             "FR",
                             "GR",
                             "XX"
                         ],
+                        "projects": ["wikipedia"],
+                        "languages": ["en"],
                         "banners": [
                             {
                                 "name": "b1",
-                                "weight": 5
+                                "weight": 5,
+                                "bucket": 0,
+                                "displayAnon": true,
+                                "displayAccount": true,
+                                "fundraising": 1,
+                                "devices": [
+                                    "desktop"
+                                 ]
                             }
                         ]
                     }
@@ -64,24 +73,72 @@
                 "campaigns": [
                     {
                         "name": "c1",
+                        "enabled": 1,
                         "startDaysFromNow": 0,
                         "endDaysFromNow": 1,
                         "preferred": 3,
                         "throttle": 60,
+                        "geotargeted": false,
+                        "projects": ["wikipedia"],
+                        "languages": ["en"],
                         "banners": [
-                            { "name": "c1b1" },
-                            { "name": "c1b2" }
+                            {
+                                "name": "c1b1",
+                                "weight": 25,
+                                "bucket": 0,
+                                "displayAnon": true,
+                                "displayAccount": true,
+                                "fundraising": 1,
+                                "devices": [
+                                    "desktop"
+                                 ]
+                            },
+                            {
+                                "name": "c1b2",
+                                "weight": 25,
+                                "bucket": 0,
+                                "displayAnon": true,
+                                "displayAccount": true,
+                                "fundraising": 1,
+                                "devices": [
+                                    "desktop"
+                                 ]
+                            }
                         ]
                     },
                     {
                         "name": "c2",
+                        "enabled": 1,
                         "startDaysFromNow": 0,
                         "endDaysFromNow": 1,
                         "preferred": 1,
                         "throttle": 100,
+                        "geotargeted": false,
+                        "projects": ["wikipedia"],
+                        "languages": ["en"],
                         "banners": [
-                            { "name": "c2b1" },
-                            { "name": "c2b2" }
+                            {
+                                "name": "c2b1",
+                                "weight": 25,
+                                "bucket": 0,
+                                "displayAnon": true,
+                                "displayAccount": true,
+                                "fundraising": 1,
+                                "devices": [
+                                    "desktop"
+                                 ]
+                            },
+                            {
+                                "name": "c2b2",
+                                "weight": 25,
+                                "bucket": 0,
+                                "displayAnon": true,
+                                "displayAccount": true,
+                                "fundraising": 1,
+                                "devices": [
+                                    "desktop"
+                                 ]
+                            }
                         ]
                     }
                 ]
@@ -167,20 +224,47 @@
                 "campaigns": [
                     {
                         "name": "c1",
+                        "enabled": 1,
                         "startDaysFromNow": 0,
                         "endDaysFromNow": 1,
+                        "preferred": 1,
+                        "throttle": 100,
+                        "geotargeted": false,
+                        "projects": ["wikipedia"],
+                        "languages": ["en"],
                         "banners": [
                             {
                                 "name": "b1",
-                                "weight": 5
+                                "weight": 5,
+                                "bucket": 0,
+                                "displayAnon": true,
+                                "displayAccount": true,
+                                "fundraising": 1,
+                                "devices": [
+                                    "desktop"
+                                 ]
                             },
                             {
                                 "name": "b2",
-                                "weight": 100
+                                "weight": 100,
+                                "bucket": 0,
+                                "displayAnon": true,
+                                "displayAccount": true,
+                                "fundraising": 1,
+                                "devices": [
+                                    "desktop"
+                                 ]
                             },
                             {
                                 "name": "b3",
-                                "weight": 100
+                                "weight": 100,
+                                "bucket": 0,
+                                "displayAnon": true,
+                                "displayAccount": true,
+                                "fundraising": 1,
+                                "devices": [
+                                    "desktop"
+                                 ]
                             }
                         ]
                     }
@@ -244,11 +328,23 @@
                 "campaigns": [
                     {
                         "name": "c1",
+                        "enabled": 1,
                         "startDaysFromNow": 0,
                         "endDaysFromNow": 1,
+                        "preferred": 1,
                         "throttle": 10,
+                        "geotargeted": false,
+                        "projects": ["wikipedia"],
+                        "languages": ["en"],
                         "banners": [
-                            { "name": "b1" }
+                            {
+                                "name": "b1",
+                                "weight": 25,
+                                "bucket": 0,
+                                "displayAnon": true,
+                                "displayAccount": true,
+                                "fundraising": 1
+                            }
                         ]
                     }
                 ]
@@ -287,20 +383,50 @@
                 "campaigns": [
                     {
                         "name": "c1",
+                        "enabled": 1,
                         "startDaysFromNow": 0,
                         "endDaysFromNow": 1,
                         "preferred": 1,
+                        "throttle": 100,
+                        "geotargeted": false,
+                        "projects": ["wikipedia"],
+                        "languages": ["en"],
                         "banners": [
-                            { "name": "c1b1" }
+                            {
+                                "name": "c1b1",
+                                "weight": 25,
+                                "bucket": 0,
+                                "displayAnon": true,
+                                "displayAccount": true,
+                                "fundraising": 1,
+                                "devices": [
+                                    "desktop"
+                                 ]
+                            }
                         ]
                     },
                     {
                         "name": "c2",
+                        "enabled": 1,
                         "startDaysFromNow": 0,
                         "endDaysFromNow": 1,
                         "preferred": 2,
+                        "throttle": 100,
+                        "geotargeted": false,
+                        "projects": ["wikipedia"],
+                        "languages": ["en"],
                         "banners": [
-                            { "name": "c2b1" }
+                            {
+                                "name": "c2b1",
+                                "weight": 25,
+                                "bucket": 0,
+                                "displayAnon": true,
+                                "displayAccount": true,
+                                "fundraising": 1,
+                                "devices": [
+                                    "desktop"
+                                 ]
+                            }
                         ]
                     }
                 ]
@@ -362,17 +488,29 @@
                 "campaigns": [
                     {
                         "name": "c1",
+                        "enabled": 1,
                         "startDaysFromNow": 0,
                         "endDaysFromNow": 1,
+                        "preferred": 1,
+                        "throttle": 100,
+                        "projects": ["wikipedia"],
+                        "languages": ["en"],
                         "geotargeted": true,
-                        "geo_countries": [
+                        "countries": [
                             "FR",
                             "XX"
                         ],
                         "banners": [
                             {
                                 "name": "b1",
-                                "weight": 5
+                                "weight": 25,
+                                "bucket": 0,
+                                "displayAnon": true,
+                                "displayAccount": true,
+                                "fundraising": 1,
+                                "devices": [
+                                    "desktop"
+                                 ]
                             }
                         ]
                     }
@@ -390,7 +528,7 @@
                     "banners": [
                         {
                             "name": "b1",
-                            "weight": 5,
+                            "weight": 25,
                             "bucket": 0,
                             "category": "fundraising",
                             "display_anon": true,
@@ -416,17 +554,29 @@
                 "campaigns": [
                     {
                         "name": "c1",
+                        "enabled": 1,
                         "startDaysFromNow": 0,
                         "endDaysFromNow": 1,
+                        "preferred": 1,
+                        "throttle": 100,
                         "geotargeted": true,
-                        "geo_countries": [
+                        "countries": [
                             "FR",
                             "GR"
                         ],
+                        "projects": ["wikipedia"],
+                        "languages": ["en"],
                         "banners": [
                             {
                                 "name": "b1",
-                                "weight": 5
+                                "weight": 25,
+                                "bucket": 0,
+                                "displayAnon": true,
+                                "displayAccount": true,
+                                "fundraising": 1,
+                                "devices": [
+                                    "desktop"
+                                 ]
                             }
                         ]
                     }
@@ -445,7 +595,7 @@
                         {
                             "name": "b1",
                             "bucket": 0,
-                            "weight": 5,
+                            "weight": 25,
                             "category": "fundraising",
                             "display_anon": true,
                             "display_account": true,
@@ -469,13 +619,25 @@
                 "campaigns": [
                     {
                         "name": "c1",
+                        "enabled": 1,
                         "startDaysFromNow": 0,
                         "endDaysFromNow": 1,
+                        "preferred": 1,
+                        "throttle": 100,
+                        "geotargeted": false,
                         "projects": [ "wikisource" ],
+                        "languages": ["en"],
                         "banners": [
                             {
                                 "name": "b1",
-                                "weight": 5
+                                "weight": 25,
+                                "bucket": 0,
+                                "displayAnon": true,
+                                "displayAccount": true,
+                                "fundraising": 1,
+                                "devices": [
+                                    "desktop"
+                                 ]
                             }
                         ]
                     }
@@ -492,13 +654,25 @@
                 "campaigns": [
                     {
                         "name": "c1",
+                        "enabled": 1,
                         "startDaysFromNow": 0,
                         "endDaysFromNow": 1,
-                        "project_languages": [ "zh" ],
+                        "preferred": 1,
+                        "throttle": 100,
+                        "geotargeted": false,
+                        "projects": ["wikipedia"],
+                        "languages": [ "zh" ],
                         "banners": [
                             {
                                 "name": "b1",
-                                "weight": 5
+                                "weight": 25,
+                                "bucket": 0,
+                                "displayAnon": true,
+                                "displayAccount": true,
+                                "fundraising": 1,
+                                "devices": [
+                                    "desktop"
+                                 ]
                             }
                         ]
                     }
@@ -515,12 +689,25 @@
                 "campaigns": [
                     {
                         "name": "c1",
+                        "enabled": 1,
                         "startDaysFromNow": 1,
                         "endDaysFromNow": 2,
+                        "preferred": 1,
+                        "throttle": 100,
+                        "geotargeted": false,
+                        "projects": ["wikipedia"],
+                        "languages": ["en"],
                         "banners": [
                             {
                                 "name": "b1",
-                                "weight": 5
+                                "weight": 25,
+                                "bucket": 0,
+                                "displayAnon": true,
+                                "displayAccount": true,
+                                "fundraising": 1,
+                                "devices": [
+                                    "desktop"
+                                 ]
                             }
                         ]
                     }
@@ -537,14 +724,25 @@
                 "campaigns": [
                     {
                         "name": "c1",
+                        "enabled": 1,
                         "startDaysFromNow": 0,
                         "endDaysFromNow": 1,
+                        "preferred": 1,
+                        "throttle": 100,
+                        "geotargeted": false,
+                        "projects": ["wikipedia"],
+                        "languages": ["en"],
                         "banners": [
                             {
+                                "name": "b1",
+                                "weight": 25,
+                                "bucket": 0,
                                 "displayAnon": false,
                                 "displayAccount": true,
-                                "name": "b1",
-                                "weight": 5
+                                "fundraising": 1,
+                                "devices": [
+                                    "desktop"
+                                 ]
                             }
                         ]
                     }
@@ -563,7 +761,7 @@
                         {
                             "name": "b1",
                             "bucket": 0,
-                            "weight": 5,
+                            "weight": 25,
                             "category": "fundraising",
                             "display_anon": false,
                             "display_account": true,
diff --git a/tests/data/allocation_fixtures_doc.md 
b/tests/data/allocation_fixtures_doc.md
index 0889602..9645b44 100644
--- a/tests/data/allocation_fixtures_doc.md
+++ b/tests/data/allocation_fixtures_doc.md
@@ -9,6 +9,12 @@
 Test Cases
 ----------
 
+TODO update the following note
 In the allocation fixture data, times are represented as offsets in days from 
the
 current time. When the fixtures are loaded, these are converted to UNIX
-timestamps (the format used by the code being tested).
\ No newline at end of file
+timestamps (the format used by the code being tested).
+
+TODO mention: for non-geotargetted, countries prop is filled in as blank
+
+TODO mention: some default properties that are set (autolink, landingPage,
+dummy banner body)
\ No newline at end of file
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 cf808c4..fba35a4 100644
--- 
a/tests/qunit/ext.centralNotice.bannerController.lib/bannerController.lib.tests.js
+++ 
b/tests/qunit/ext.centralNotice.bannerController.lib/bannerController.lib.tests.js
@@ -25,7 +25,7 @@
 
                        // BOOM on priority case FIXME ???
 
-                       prepareTestCase( testCase );
+                       setTestCaseStartEnd( testCase );
                        choices = testCase.choices;
 
                        // Set per-campaign buckets to 0 for all campaigns
@@ -73,16 +73,21 @@
         * in days from the current time. Note: this logic is repeated in PHP 
for
         * PHPUnit tests that use the same fixtures.
         *
-        * @see CentralNoticeTestFixtures::prepareTestcase()
+        * @see CentralNoticeTestFixtures::setTestCaseStartEnd()
         */
-       function prepareTestCase( testCase ) {
+       function setTestCaseStartEnd( testCaseSpec ) {
                var i, choice,
                        now = new Date();
 
-               for ( i = 0; i < testCase.choices.length; i++ ) {
-                       choice = testCase.choices[i];
+               for ( i = 0; i < testCaseSpec.choices.length; i++ ) {
+                       choice = testCaseSpec.choices[i];
                        choice.start = makeTimestamp( now, 
choice.startDaysFromNow );
                        choice.end = makeTimestamp( now, choice.endDaysFromNow);
+
+                       // Remove these special properties from choices, to 
make the
+                       // choices data mirror the real data structure.
+                       delete choice.startDaysFromNow;
+                       delete choice.endDaysFromNow;
                }
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/185542
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I063a4b421b6e9c169121c8a0a855d9706fa4e0ec
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: AndyRussG <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: Katie Horn <[email protected]>
Gerrit-Reviewer: Mwalker <[email protected]>
Gerrit-Reviewer: Ssmith <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to