jenkins-bot has submitted this change and it was merged.
Change subject: test fixtures do not pollute cn_known_devices table
......................................................................
test fixtures do not pollute cn_known_devices table
Change-Id: I04935fcb8bc0e4a3e0c76b53820230b77a2e1441
---
M tests/BannerTest.php
M tests/CentralNoticeTest.php
M tests/CentralNoticeTestFixtures.php
3 files changed, 57 insertions(+), 1 deletion(-)
Approvals:
Ejegg: Looks good to me, approved
Awight: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/tests/BannerTest.php b/tests/BannerTest.php
index 7108863..5e454b1 100644
--- a/tests/BannerTest.php
+++ b/tests/BannerTest.php
@@ -8,6 +8,8 @@
class BannerTest extends PHPUnit_Framework_TestCase {
const TEST_BANNER_NAME = 'PhpUnitTestBanner';
+ protected $fixture;
+
public static function setUpBeforeClass() {
$banner = Banner::fromName( BannerTest::TEST_BANNER_NAME );
if ( $banner->exists() ) {
@@ -15,11 +17,18 @@
}
}
+ protected function setUp() {
+ parent::setUp();
+ $this->fixture = new CentralNoticeTestFixtures();
+ $this->fixture->addFixtures( array( 'campaigns' => array() ) );
+ }
+
public function tearDown() {
$banner = Banner::fromName( BannerTest::TEST_BANNER_NAME );
if ( $banner->exists() ) {
$banner->remove();
}
+ $this->fixture->removeFixtures();
}
public function testNewFromName() {
diff --git a/tests/CentralNoticeTest.php b/tests/CentralNoticeTest.php
index 7af0a94..a4d19c2 100644
--- a/tests/CentralNoticeTest.php
+++ b/tests/CentralNoticeTest.php
@@ -21,6 +21,8 @@
public $campaignId;
+ protected $fixture;
+
protected function setUp() {
parent::setUp();
self::$centralNotice = new CentralNotice;
@@ -32,6 +34,9 @@
$geotargeted = 1;
$geo_countries = array( 'US', 'AF' );
$preferred = 1;
+
+ $this->fixture = new CentralNoticeTestFixtures();
+ $this->fixture->addFixtures( array( 'campaigns' => array() ) );
$this->campaignArray = array(
'enabled' => '0',
@@ -84,6 +89,7 @@
Campaign::removeCampaign( 'PHPUnitTestCampaign',
$this->userUser );
Campaign::removeTemplateFor( 'PHPUnitTestCampaign',
'PHPUnitTestBanner' );
Banner::removeTemplate ( 'PHPUnitTestBanner', $this->userUser );
+ $this->fixture->removeFixtures();
}
public function testDropDownList() {
diff --git a/tests/CentralNoticeTestFixtures.php
b/tests/CentralNoticeTestFixtures.php
index da43cba..89716b2 100644
--- a/tests/CentralNoticeTestFixtures.php
+++ b/tests/CentralNoticeTestFixtures.php
@@ -3,6 +3,7 @@
class CentralNoticeTestFixtures {
public $spec = array();
protected $user;
+ protected $fixtureDeviceId;
// Use exactly the api defaults where available
static public $defaultCampaign;
@@ -36,7 +37,7 @@
}
function addFixtures( $spec ) {
- CNDeviceTarget::addDeviceTarget( 'desktop',
'{{int:centralnotice-devicetype-desktop}}' );
+ $this->ensureDesktopDevice();
foreach ( $spec['campaigns'] as $campaignSpec ) {
$campaign = $campaignSpec + static::$defaultCampaign +
array(
@@ -97,6 +98,46 @@
Campaign::removeCampaign( $campaign['name'],
$this->user );
}
}
+
+ if ( $this->fixtureDeviceId ) {
+ $dbw = CNDatabase::getDb( DB_MASTER );
+ $dbw->delete(
+ 'cn_known_devices',
+ array( 'dev_id' => $this->fixtureDeviceId ),
+ __METHOD__
+ );
+ }
+ }
+
+ protected function getDesktopDevice() {
+ $dbr = CNDatabase::getDb();
+
+ $res = $dbr->select(
+ array(
+ 'cn_known_devices'
+ ),
+ array(
+ 'dev_id',
+ 'dev_name'
+ ),
+ array(
+ 'dev_name' => 'desktop',
+ )
+ );
+ $ids = array();
+ foreach ( $res as $row ) {
+ $ids[] = $row->dev_id;
+ }
+ return $ids;
+ }
+
+ protected function ensureDesktopDevice() {
+ $ids = $this->getDesktopDevice();
+ if ( !$ids ) {
+ CNDeviceTarget::addDeviceTarget( 'desktop',
'{{int:centralnotice-devicetype-desktop}}' );
+ $ids = $this->getDesktopDevice();
+ $this->fixtureDeviceId = $ids[0];
+ }
}
static function allocationsData() {
--
To view, visit https://gerrit.wikimedia.org/r/173211
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I04935fcb8bc0e4a3e0c76b53820230b77a2e1441
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Ejegg <[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