Awight has uploaded a new change for review.
https://gerrit.wikimedia.org/r/173193
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/CentralNoticeTestFixtures.php
1 file changed, 41 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralNotice
refs/changes/93/173193/1
diff --git a/tests/CentralNoticeTestFixtures.php
b/tests/CentralNoticeTestFixtures.php
index da43cba..1522ba5 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,45 @@
Campaign::removeCampaign( $campaign['name'],
$this->user );
}
}
+
+ if ( $this->fixtureDeviceId ) {
+ $db->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/173193
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I04935fcb8bc0e4a3e0c76b53820230b77a2e1441
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