Awight has uploaded a new change for review.
https://gerrit.wikimedia.org/r/155315
Change subject: Merge remote-tracking branch 'origin/master' into HEAD
......................................................................
Merge remote-tracking branch 'origin/master' into HEAD
Change-Id: I6bd38517aa920b17d9b6f7b64a8151b46e50b154
---
D tests/AllocationsTest.php
D tests/ApiAllocationsTest.php
D tests/BannerTest.php
D tests/CentralNoticeTest.php
D tests/CentralNoticeTestFixtures.php
D tests/ComparisonUtil.php
D tests/HistoryTest.php
7 files changed, 0 insertions(+), 769 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralNotice
refs/changes/15/155315/1
diff --git a/tests/AllocationsTest.php b/tests/AllocationsTest.php
deleted file mode 100644
index 4fbaddd..0000000
--- a/tests/AllocationsTest.php
+++ /dev/null
@@ -1,187 +0,0 @@
-<?php
-
-require_once 'CentralNoticeTestFixtures.php';
-require_once 'ComparisonUtil.php';
-
-/**
- * @group CentralNotice
- * @group medium
- * @group Database
- */
-class AllocationsTest extends MediaWikiTestCase {
- /** @var CentralNoticeTestFixtures */
- protected $cnFixtures;
-
- protected function setUp() {
- parent::setUp();
-
- $this->cnFixtures = new CentralNoticeTestFixtures();
- }
-
- protected function tearDown() {
- $this->cnFixtures->removeFixtures();
- parent::tearDown();
- }
-
- public function testThrottlingCampaign() {
- $this->cnFixtures->addFixtures( 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()
- ),
- ),
- ),
- ) );
- $expected = array(
- array (
- 'name' =>
$this->cnFixtures->spec['campaigns'][1]['banners'][0]['name'],
- 'fundraising' => 1,
- 'campaign' =>
$this->cnFixtures->spec['campaigns'][1]['name'],
- 'bucket' => 0,
- 'allocation' => .2,
- ),
- array (
- 'name' =>
$this->cnFixtures->spec['campaigns'][1]['banners'][1]['name'],
- 'fundraising' => 1,
- 'campaign' =>
$this->cnFixtures->spec['campaigns'][1]['name'],
- 'bucket' => 0,
- 'allocation' => .2,
- ),
- array (
- 'name' =>
$this->cnFixtures->spec['campaigns'][0]['banners'][0]['name'],
- 'fundraising' => 1,
- 'campaign' =>
$this->cnFixtures->spec['campaigns'][0]['name'],
- 'bucket' => 0,
- 'allocation' => .3,
- ),
- array (
- 'name' =>
$this->cnFixtures->spec['campaigns'][0]['banners'][1]['name'],
- 'fundraising' => 1,
- 'campaign' =>
$this->cnFixtures->spec['campaigns'][0]['name'],
- 'bucket' => 0,
- 'allocation' => .3,
- ),
- );
-
- $allocContext = new AllocationContext( 'US', 'en', 'wikipedia',
'true', 'desktop', null );
- $chooser = new BannerChooser( $allocContext );
- $banners = $chooser->getBanners();
-
- $this->assertTrue( ComparisonUtil::assertSuperset( $banners,
$expected ) );
- }
-
- public function testOverAllocation() {
- $this->cnFixtures->addFixtures( array(
- 'campaigns' => array(
- array(
- 'banners' => array(
- array(
- 'weight' => 5,
- ),
- array(
- 'weight' => 100,
- ),
- array(
- 'weight' => 100,
- ),
- ),
- ),
- ),
- ) );
- $expected = array(
- array (
- 'weight' => 5,
- 'slots' => 1,
- ),
- array (
- 'weight' => 100,
- 'slots' => 15,
- ),
- array (
- 'weight' => 100,
- 'slots' => 14,
- ),
- );
-
- $allocContext = new AllocationContext( 'US', 'en', 'wikipedia',
'true', 'desktop', null );
- $chooser = new BannerChooser( $allocContext );
- $banners = $chooser->getBanners();
-
- $this->assertTrue( ComparisonUtil::assertSuperset( $banners,
$expected ) );
- }
-
- public function testBlanks() {
- $this->cnFixtures->addFixtures( array(
- 'campaigns' => array(
- array(
- 'throttle' => 10,
- 'banners' => array(
- array(),
- ),
- ),
- ),
- ) );
- $expected = array(
- array(
- 'slots' => 3,
- ),
- );
-
- $allocContext = new AllocationContext( 'US', 'en', 'wikipedia',
'true', 'desktop', null );
- $chooser = new BannerChooser( $allocContext );
- $banners = $chooser->getBanners();
-
- $this->assertTrue( ComparisonUtil::assertSuperset( $banners,
$expected ) );
-
- $this->assertNotNull( $chooser->chooseBanner( 3 ) );
-
- $this->assertNull( $chooser->chooseBanner( 4 ) );
- }
-
- public function testPriority() {
- $this->cnFixtures->addFixtures( array(
- 'campaigns' => array(
- array(
- 'preferred' =>
CentralNotice::LOW_PRIORITY,
- 'banners' => array(
- array(),
- ),
- ),
- array(
- 'preferred' =>
CentralNotice::NORMAL_PRIORITY,
- 'banners' => array(
- array(),
- ),
- ),
- ),
- ) );
- $expected = array(
- array(
- 'campaign' =>
$this->cnFixtures->spec['campaigns'][0]['name'],
- 'slots' => 0,
- ),
- array(
- 'campaign' =>
$this->cnFixtures->spec['campaigns'][1]['name'],
- 'slots' => 30,
- ),
- );
-
- $allocContext = new AllocationContext( 'US', 'en', 'wikipedia',
'true', 'desktop', null );
- $chooser = new BannerChooser( $allocContext );
- $banners = $chooser->getBanners();
-
- $this->assertTrue( ComparisonUtil::assertSuperset( $banners,
$expected ) );
- }
-}
diff --git a/tests/ApiAllocationsTest.php b/tests/ApiAllocationsTest.php
deleted file mode 100644
index a1c84c3..0000000
--- a/tests/ApiAllocationsTest.php
+++ /dev/null
@@ -1,79 +0,0 @@
-<?php
-
-require_once 'CentralNoticeTestFixtures.php';
-require_once 'ComparisonUtil.php';
-
-/**
- * @group CentralNotice
- * @group medium
- * @group Database
- *
- * This is a little sloppy, it is testing both the api and the allocations
algorithms
- */
-class ApiAllocationsTest extends ApiTestCase {
- /** @var CentralNoticeTestFixtures */
- protected $cnFixtures;
-
- protected function setUp() {
- parent::setUp();
-
- $this->cnFixtures = new CentralNoticeTestFixtures();
- }
-
- protected function tearDown() {
- $this->cnFixtures->removeFixtures();
- parent::tearDown();
- }
-
- public function testEqualAllocations() {
- // Campaign has two banners, with default parameters
- $this->cnFixtures->addFixtures( array(
- 'campaigns' => array(
- array(
- 'banners' => array(
- array(),
- array()
- ),
- ),
- ),
- ) );
- $expected = array(
- 'centralnoticeallocations' => array(
- 'banners' => array(
- array (
- 'name' =>
$this->cnFixtures->spec['campaigns'][0]['banners'][0]['name'],
- 'fundraising' => 1,
- 'campaign' =>
$this->cnFixtures->spec['campaigns'][0]['name'],
- 'bucket' => 0,
- 'allocation' => .5,
- ),
- array (
- 'name' =>
$this->cnFixtures->spec['campaigns'][0]['banners'][1]['name'],
- 'fundraising' => 1,
- 'campaign' =>
$this->cnFixtures->spec['campaigns'][0]['name'],
- 'bucket' => 0,
- 'allocation' => .5,
- ),
- ),
- ),
- );
-
- $ret = $this->doApiRequest( array(
- 'action' => 'centralnoticeallocations',
- ) );
- $this->assertTrue( ComparisonUtil::assertSuperset( $ret[0],
$expected ) );
- }
-
- //TODO:
- //function testInvalid() {
-
- //function testFilters() {
-
- //function testUnderallocation() {
- // * driven below 1 / total_weight -> 1
- // * 1/4 edge?
- // * an underallocation -> in a predictable order
- //function testKnownUnequal() {
- //function testPriorities() {
- //function test() {
-}
diff --git a/tests/BannerTest.php b/tests/BannerTest.php
deleted file mode 100644
index 7108863..0000000
--- a/tests/BannerTest.php
+++ /dev/null
@@ -1,156 +0,0 @@
-<?php
-
-/**
- * @group Fundraising
- * @group Database
- * @group CentralNotice
- */
-class BannerTest extends PHPUnit_Framework_TestCase {
- const TEST_BANNER_NAME = 'PhpUnitTestBanner';
-
- public static function setUpBeforeClass() {
- $banner = Banner::fromName( BannerTest::TEST_BANNER_NAME );
- if ( $banner->exists() ) {
- $banner->remove();
- }
- }
-
- public function tearDown() {
- $banner = Banner::fromName( BannerTest::TEST_BANNER_NAME );
- if ( $banner->exists() ) {
- $banner->remove();
- }
- }
-
- public function testNewFromName() {
- // Create what should be a new empty banner
- $banner = Banner::newFromName( BannerTest::TEST_BANNER_NAME );
- $this->assertFalse( $banner->exists(), 'Test precondition
failed! Banner already exists!' );
-
- // Run down the basic metadata and ensure it is in fact empty
- $this->assertEquals( null, $banner->getId(), 'New banner ID is
not null; probably already exists!' );
- $this->assertEquals( BannerTest::TEST_BANNER_NAME,
$banner->getName(), 'Banner name did not get set' );
- $this->assertFalse( $banner->allocateToAnon(), 'Initial
anonymous allocation is set to true' );
- $this->assertFalse( $banner->allocateToLoggedIn(), 'Initial
logged in allocation is set to true' );
- $this->assertEquals( '{{{campaign}}}', $banner->getCategory(),
'Initial category is not equal to {{{campaign}}}' );
- $this->assertFalse( $banner->isAutoLinked(), 'Initial banner is
autolinked' );
- $this->assertEquals( array(), $banner->getAutoLinks(), 'Initial
banner has autolinks' );
- $this->assertFalse( $banner->isArchived(), 'Initial banner is
archived?' );
-
- // More complex metadata should also be empty
- $this->assertEquals( array(), $banner->getDevices(), 'Initial
banner has associated device targets' );
- $this->assertEquals( array(), $banner->getMixins(), 'Initial
banner has associated mixins' );
- $this->assertEquals( array(), $banner->getPriorityLanguages(),
'Initial banner has priority languages' );
-
- // And the body content should also be empty
- $this->assertEquals( '', $banner->getBodyContent(), 'Initial
banner has non empty body content' );
-
- // And finally; save this empty banner
- $banner->save();
- $this->assertTrue( $banner->exists(), 'Banner was not
successfully saved' );
-
- // Did we get the right ID back?
- $banner2 = Banner::fromId( $banner->getId() );
- $this->assertTrue( $banner2->exists(), 'Banner does not exist
by saved id!' );
- }
-
- /**
- * @depends testNewFromName
- */
- public function testEmptyFromName() {
- $banner = Banner::newFromName( BannerTest::TEST_BANNER_NAME );
- $banner->save();
- $this->assertTrue( $banner->exists(), 'Test banner that should
exist does not!' );
-
- // Run down the basic metadata and ensure it is in fact empty
- $this->assertNotEquals( -1, $banner->getId(), 'Test banner has
no ID' );
- $this->assertEquals( BannerTest::TEST_BANNER_NAME,
$banner->getName(), 'Banner name did not get saved' );
- $this->assertFalse( $banner->allocateToAnon(), 'Initial
anonymous allocation is set to true' );
- $this->assertFalse( $banner->allocateToLoggedIn(), 'Initial
logged in allocation is set to true' );
- $this->assertEquals( '{{{campaign}}}', $banner->getCategory(),
'Initial category is not equal to {{{campaign}}}' );
- $this->assertFalse( $banner->isAutoLinked(), 'Initial banner is
autolinked' );
- $this->assertEquals( array(), $banner->getAutoLinks(), 'Initial
banner has autolinks' );
- $this->assertFalse( $banner->isArchived(), 'Initial banner is
archived?' );
-
- // More complex metadata should also be empty
- $this->assertEquals( array(), $banner->getDevices(), 'Initial
banner has associated device targets' );
- $this->assertEquals( array(), $banner->getMixins(), 'Initial
banner has associated mixins' );
- $this->assertEquals( array(), $banner->getPriorityLanguages(),
'Initial banner has priority languages' );
-
- // And the body content should also be empty
- $this->assertEquals( '', $banner->getBodyContent(), 'Initial
banner has non empty body content' );
- }
-
- /**
- * @depends testEmptyFromName
- */
- public function testBasicSave() {
- $banner = Banner::newFromName( BannerTest::TEST_BANNER_NAME );
- $banner->save();
- $this->assertTrue( $banner->exists() );
-
- // Attempt to populate basic metadata
- $banner->setAllocation( true, true )->
- setCategory( 'testCategory' )->
- setAutoLink( true, array( 'testlink' ) );
-
- // And the more advanced metadata
- $banner->setDevices( 'desktop' );
- $banner->setMixins( array('BannerDiet') );
- $banner->setPriorityLanguages( array( 'en', 'ru' ) );
-
- $banner->save();
-
- // Can we retrieve it from the same object?
- $this->assertTrue( $banner->allocateToAnon(), "Failed retrieve
anon allocation from initial" );
- $this->assertTrue( $banner->allocateToLoggedIn(), "Failed
retrieve logged in allocation from initial" );
- $this->assertEquals( 'testCategory', $banner->getCategory(),
"Failed retrieve category from initial" );
- $this->assertTrue( $banner->isAutoLinked(), "Failed autolink
retrieve from initial" );
- $this->assertEquals( array( 'testlink' ),
$banner->getAutoLinks(), 'Failed autolinks retrieve from initial' );
-
- $this->assertEquals( array( 'desktop' ), array_values(
$banner->getDevices() ), 'Failed devices retrieve from initial' );
- $this->assertEquals( array( 'BannerDiet' ), array_keys(
$banner->getMixins() ), 'Failed mixins retrieve from initial' );
- $this->assertEquals( array( 'en', 'ru' ),
$banner->getPriorityLanguages(), "Failed prilang retrieve from initial" );
-
- // Can we retrieve it from a different object
- $banner2 = Banner::fromName( BannerTest::TEST_BANNER_NAME );
- $this->assertTrue( $banner2->allocateToAnon(), "Failed anon
allocation from copy" );
- $this->assertTrue( $banner2->allocateToLoggedIn(), "Failed
loggedin allocation from copy" );
- $this->assertEquals( 'testCategory', $banner2->getCategory(),
"Failed category from copy" );
- $this->assertTrue( $banner2->isAutoLinked(), "Failed autolink
from copy" );
- $this->assertEquals( array( 'testlink' ),
$banner2->getAutoLinks(), "Failed autolinks from copy" );
-
- $this->assertEquals( array( 'desktop' ), array_values(
$banner2->getDevices() ), "Failed devices from copy" );
- $this->assertEquals( array( 'BannerDiet' ), array_keys(
$banner2->getMixins() ), "Failed mixins from copy" );
-
- global $wgNoticeUseTranslateExtension;
- if ( $wgNoticeUseTranslateExtension ) {
- $this->assertEquals( array( 'en', 'ru' ),
$banner2->getPriorityLanguages(), "Failed languages from copy" );
- }
- }
-
- /**
- * @depends testBasicSave
- * @dataProvider providerSetAllocation
- */
- public function testSetAllocation( $anon, $loggedIn ) {
- $banner = Banner::newFromName( BannerTest::TEST_BANNER_NAME );
- $banner->setAllocation( $anon, $loggedIn );
- $banner->save();
- $this->assertEquals( $anon, $banner->allocateToAnon(), "Testing
initial anon" );
- $this->assertEquals( $loggedIn, $banner->allocateToLoggedIn(),
"Testing initial logged in" );
-
- $banner2 = Banner::fromName( BannerTest::TEST_BANNER_NAME );
- $this->assertEquals( $anon, $banner2->allocateToAnon(),
"Testing post save anon" );
- $this->assertEquals( $loggedIn, $banner2->allocateToLoggedIn(),
"Testing post save logged in" );
- }
-
- public function providerSetAllocation() {
- return array(
- array( false, false ),
- array( true, false ),
- array( false, true ),
- array( true, true )
- );
- }
-}
diff --git a/tests/CentralNoticeTest.php b/tests/CentralNoticeTest.php
deleted file mode 100644
index 7af0a94..0000000
--- a/tests/CentralNoticeTest.php
+++ /dev/null
@@ -1,145 +0,0 @@
-<?php
-
-/**
- * @group Fundraising
- * @group Database
- * @group CentralNotice
- */
-class CentralNoticeTest extends PHPUnit_Framework_TestCase {
- /**
- * @var CentralNotice
- */
- protected static $centralNotice;
- /**
- * @var SpecialNoticeTemplate
- */
- protected static $noticeTemplate;
-
- protected $userUser;
-
- protected $campaignArray;
-
- public $campaignId;
-
- protected function setUp() {
- parent::setUp();
- self::$centralNotice = new CentralNotice;
- $noticeName = 'PHPUnitTestCampaign';
- $enabled = 0;
- $startTs = '20110718' . '235500';
- $projects = array( 'wikipedia', 'wikibooks' );
- $project_languages = array( 'en', 'de' );
- $geotargeted = 1;
- $geo_countries = array( 'US', 'AF' );
- $preferred = 1;
-
- $this->campaignArray = array(
- 'enabled' => '0',
- 'end' => '20110719005500',
- 'geo' => '1',
- 'locked' => '0',
- 'preferred' => '1',
- 'start' => '20110718235500',
- 'buckets' => '1',
- 'projects' => 'wikibooks, wikipedia',
- 'languages' => 'de, en',
- 'countries' => 'AF, US',
- 'archived' => 0,
- 'throttle' => 100,
- );
-
- //get User
- $this->userUser = User::newFromName( 'TestUser' );
- if ( !$this->userUser->getID() ) {
- $this->userUser = User::createNew( 'TestUser', array(
- "email" => "[email protected]",
- "real_name" => "Test User" ) );
- $this->userUser->load();
- }
- Campaign::addCampaign( $noticeName, $enabled, $startTs,
$projects,
- $project_languages, $geotargeted, $geo_countries,
- 100, $preferred, $this->userUser );
-
- $this->campaignId = Campaign::getNoticeId(
'PHPUnitTestCampaign' );
-
- self::$noticeTemplate = new SpecialNoticeTemplate;
- $bannerName = 'PHPUnitTestBanner';
- $body = 'testing';
- $displayAnon = 1;
- $displayAccount = 1;
- $fundraising = 1;
- $autolink = 0;
- $landingPages = 'JA1, JA2';
- $campaign_z_index = 1;
-
- $this->campaignBannersJson =
'[{"name":"PHPUnitTestBanner","weight":25,"display_anon":1,"display_account":1,"fundraising":1,"autolink":0,"landing_pages":"JA1,JA2","device":"desktop","campaign":"PHPUnitTestCampaign","campaign_z_index":"1","campaign_num_buckets":1,"campaign_throttle":100,"bucket":0}]';
-
- Banner::addTemplate( $bannerName, $body, $this->userUser,
$displayAnon, $displayAccount,
- $fundraising, $autolink, $landingPages );
- Campaign::addTemplateTo( 'PHPUnitTestCampaign',
'PHPUnitTestBanner', '25' );
- }
-
- protected function tearDown() {
- parent::tearDown();
- Campaign::removeCampaign( 'PHPUnitTestCampaign',
$this->userUser );
- Campaign::removeTemplateFor( 'PHPUnitTestCampaign',
'PHPUnitTestBanner' );
- Banner::removeTemplate ( 'PHPUnitTestBanner', $this->userUser );
- }
-
- public function testDropDownList() {
- $text = 'Weight';
- $values = range ( 0, 50, 10 );
- $this->assertEquals(
- "*Weight\n**0\n**10\n**20\n**30\n**40\n**50\n",
- CentralNotice::dropDownList( $text, $values ) );
- }
-
- public function testGetNoticeProjects() {
- $projects = Campaign::getNoticeProjects( 'PHPUnitTestCampaign'
);
- sort( $projects );
- $this->assertEquals(
- array ( 'wikibooks', 'wikipedia' ),
- $projects
- );
- }
-
- public function testGetNoticeLanguages() {
- $languages = Campaign::getNoticeLanguages(
'PHPUnitTestCampaign' );
- sort( $languages );
- $this->assertEquals(
- array ( 'de', 'en' ),
- $languages
- );
- }
-
- public function testGetNoticeCountries() {
- $countries = Campaign::getNoticeCountries(
'PHPUnitTestCampaign' );
- sort( $countries );
- $this->assertEquals(
- array ( 'AF', 'US' ),
- $countries
- );
- }
-
- public function testGetCampaignBanners() {
- $campaignId = Campaign::getNoticeId( 'PHPUnitTestCampaign' );
- $this->assertEquals(
- $this->campaignBannersJson,
- json_encode( Banner::getCampaignBanners( $campaignId ) )
- );
- }
-
- public function testGetCampaignSettings() {
- $settings = Campaign::getCampaignSettings(
'PHPUnitTestCampaign' );
- $banners = json_decode( $settings[ 'banners' ], true );
-
- $this->assertEquals( 1, count( $banners ) );
- $this->assertEquals( array( 'PHPUnitTestBanner' ), array_keys(
$banners ) );
- unset( $settings[ 'banners' ] );
-
- $this->assertEquals(
- $this->campaignArray,
- $settings
- );
- }
-}
diff --git a/tests/CentralNoticeTestFixtures.php
b/tests/CentralNoticeTestFixtures.php
deleted file mode 100644
index 77ace7a..0000000
--- a/tests/CentralNoticeTestFixtures.php
+++ /dev/null
@@ -1,101 +0,0 @@
-<?php
-
-class CentralNoticeTestFixtures {
- public $spec = array();
- protected $user;
-
- // Use exactly the api defaults where available
- static public $defaultCampaign;
- static public $defaultBanner;
-
- function __construct() {
- $this->user = User::newFromName( 'UTSysop' );
-
- static::$defaultCampaign = array(
- 'enabled' => 1,
- // inclusive comparison is used, so this does not cause
a race condition.
- 'startTs' => wfTimestamp( TS_MW ),
- 'projects' => array(
ApiCentralNoticeAllocations::DEFAULT_PROJECT ),
- 'project_languages' => array(
ApiCentralNoticeAllocations::DEFAULT_LANGUAGE ),
- 'preferred' => CentralNotice::NORMAL_PRIORITY,
- 'geotargeted' => 0,
- 'geo_countries' => array(
ApiCentralNoticeAllocations::DEFAULT_COUNTRY ),
- 'throttle' => 100,
- 'banners' => array(),
- );
- static::$defaultBanner = array(
- 'body' => 'testing',
- 'displayAnon' =>
ApiCentralNoticeAllocations::DEFAULT_ANONYMOUS === 'true',
- 'displayAccount' =>
ApiCentralNoticeAllocations::DEFAULT_ANONYMOUS === 'false',
- 'fundraising' => 1,
- 'autolink' => 0,
- 'landingPages' => 'JA1, JA2',
- 'campaign_z_index' => 0,
- 'weight' => 25,
- );
- }
-
- function addFixtures( $spec ) {
- CNDeviceTarget::addDeviceTarget( 'desktop',
'{{int:centralnotice-devicetype-desktop}}' );
-
- foreach ( $spec['campaigns'] as $campaignSpec ) {
- $campaign = $campaignSpec + static::$defaultCampaign +
array(
- 'name' => 'TestCampaign_' . rand(),
- );
-
- $campaign['id'] = Campaign::addCampaign(
- $campaign['name'],
- $campaign['enabled'],
- $campaign['startTs'],
- $campaign['projects'],
- $campaign['project_languages'],
- $campaign['geotargeted'],
- $campaign['geo_countries'],
- $campaign['throttle'],
- $campaign['preferred'],
- $this->user
- );
-
- $banners = array();
- foreach ( $campaign['banners'] as $bannerSpec ) {
- $banner = $bannerSpec + static::$defaultBanner
+ array(
- 'name' => 'TestBanner_' . rand(),
- );
-
- Banner::addTemplate(
- $banner['name'],
- $banner['body'],
- $this->user,
- $banner['displayAnon'],
- $banner['displayAccount'],
- $banner['fundraising'],
- $banner['autolink'],
- $banner['landingPages']
- );
- Campaign::addTemplateTo(
- $campaign['name'],
- $banner['name'],
- $banner['weight']
- );
-
- $banners[] = $banner;
- }
- $campaign['banners'] = $banners;
-
- $this->spec['campaigns'][] = $campaign;
- }
- }
-
- function removeFixtures() {
- if ( $this->spec ) {
- foreach ( $this->spec['campaigns'] as $campaign ) {
- foreach ( $campaign['banners'] as $banner ) {
- Campaign::removeTemplateFor(
$campaign['name'], $banner['name'] );
- Banner::removeTemplate(
$banner['name'], $this->user );
- }
-
- Campaign::removeCampaign( $campaign['name'],
$this->user );
- }
- }
- }
-}
diff --git a/tests/ComparisonUtil.php b/tests/ComparisonUtil.php
deleted file mode 100644
index 0fde013..0000000
--- a/tests/ComparisonUtil.php
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-
-class ComparisonUtil {
- /**
- * Check that all elements of $inner match in $super, recursively.
- */
- static public function assertSuperset( $super, $inner, $path = array()
) {
- $expected_value = static::array_dereference( $inner, $path );
- if ( is_array( $expected_value ) ) {
- foreach ( array_keys( $expected_value ) as $key ) {
- $inner_path = $path;
- $inner_path[] = $key;
- self::assertSuperset( $super, $inner,
$inner_path );
- }
- } else {
- $actual_value = static::array_dereference( $super,
$path );
- if ( $expected_value !== $actual_value ) {
- throw new Exception( "Non-match at " . implode(
".", $path ) . " expected {$expected_value}, found {$actual_value}" );
- }
- }
- return true;
- }
-
- static protected function array_dereference( $root, $path ) {
- $cur_path = array();
- while ( count( $path ) ) {
- $key = array_shift( $path );
- $cur_path[] = $key;
- if ( !is_array( $root ) or !array_key_exists( $key,
$root ) ) {
- throw new Exception( "Missing value for key " .
implode( ".", $cur_path ) );
- }
- $root = $root[$key];
- }
- return $root;
- }
-}
diff --git a/tests/HistoryTest.php b/tests/HistoryTest.php
deleted file mode 100644
index 504e9a6..0000000
--- a/tests/HistoryTest.php
+++ /dev/null
@@ -1,65 +0,0 @@
-<?php
-
-require_once 'CentralNoticeTestFixtures.php';
-
-/**
- * @group CentralNotice
- * @group medium
- * @group Database
- */
-class HistoryTest extends CentralNoticeTest {
- /** @var CentralNoticeTestFixtures */
- protected $cnFixtures;
-
- protected function setUp() {
- parent::setUp();
-
- $this->cnFixtures = new CentralNoticeTestFixtures();
- }
-
- protected function tearDown() {
- $this->cnFixtures->removeFixtures();
- parent::tearDown();
- }
-
- public function testStaleHistoricalCampaigns() {
- // Bug was that expired campaigns would still be included in the
- // history, as long as they were enabled.
- $this->cnFixtures->addFixtures( array(
- 'campaigns' => array(
- array(
- 'banners' => array(
- array()
- ),
- ),
- ),
- ) );
-
- $made_by_ts = wfTimestamp( TS_MW );
- $this->assertEquals( 1, count(
Campaign::getHistoricalCampaigns( $made_by_ts ) ) );
-
- $initialSettings = Campaign::getCampaignSettings(
$this->cnFixtures->spec['campaigns'][0]['name'] );
-
- sleep( 2 );
-
- // FIXME: Campaign::updateSettings
- $newSettings = array(
- 'end' => $made_by_ts,
- ) + $initialSettings;
- Campaign::updateNoticeDate(
- $this->cnFixtures->spec['campaigns'][0]['name'],
- $newSettings['start'],
- $newSettings['end']
- );
- Campaign::logCampaignChange(
- 'modified',
- $this->cnFixtures->spec['campaigns'][0]['id'],
- $this->userUser,
- $initialSettings,
- $newSettings
- );
-
- $modified_ts = wfTimestamp( TS_MW );
- $this->assertEquals( 0, count(
Campaign::getHistoricalCampaigns( $modified_ts ) ) );
- }
-}
--
To view, visit https://gerrit.wikimedia.org/r/155315
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6bd38517aa920b17d9b6f7b64a8151b46e50b154
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: wmf_deploy
Gerrit-Owner: Awight <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits