Index: trunk/extensions/CentralNotice/tests/CentralNoticeTest.php |
— | — | @@ -5,7 +5,8 @@ |
6 | 6 | */ |
7 | 7 | class CentralNoticeTest extends PHPUnit_Framework_TestCase { |
8 | 8 | |
9 | | - protected static $centralNotice; |
| 9 | + protected static $centralNotice, $centralNoticeDB, $noticeTemplate; |
| 10 | + var $campaignId; |
10 | 11 | |
11 | 12 | protected function setUp() { |
12 | 13 | parent::setUp(); |
— | — | @@ -13,11 +14,11 @@ |
14 | 15 | $noticeName = 'PHPUnitTestCampaign'; |
15 | 16 | $enabled = 0; |
16 | 17 | $start = array( |
17 | | - "month" => 07, |
18 | | - "day" => 18, |
19 | | - "year" => 2011, |
20 | | - "hour" => 23, |
21 | | - "min" => 55, |
| 18 | + "month" => '07', |
| 19 | + "day" => '18', |
| 20 | + "year" => '2011', |
| 21 | + "hour" => '23', |
| 22 | + "min" => '55', |
22 | 23 | ); |
23 | 24 | $projects = array( 'wikipedia', 'wikibooks' ); |
24 | 25 | $project_languages = array( 'en', 'de' ); |
— | — | @@ -25,11 +26,27 @@ |
26 | 27 | $geo_countries = array( 'US', 'AF' ); |
27 | 28 | self::$centralNotice->addCampaign( $noticeName, $enabled, $start, $projects, |
28 | 29 | $project_languages, $geotargeted, $geo_countries ); |
| 30 | + $this->campaignId = CentralNotice::getNoticeId( 'PHPUnitTestCampaign' ); |
| 31 | + |
| 32 | + self::$noticeTemplate = new SpecialNoticeTemplate; |
| 33 | + $bannerName = 'PHPUnitTestBanner'; |
| 34 | + $body = 'testing'; |
| 35 | + $displayAnon = 1; |
| 36 | + $displayAccount = 1; |
| 37 | + $fundaising = 1; |
| 38 | + $landingPages = 'JA1, JA2'; |
| 39 | + self::$noticeTemplate->addTemplate( $bannerName, $body, $displayAnon, $displayAccount, |
| 40 | + $fundaising, $landingPages ); |
| 41 | + self::$centralNotice->addTemplateTo( 'PHPUnitTestCampaign', 'PHPUnitTestBanner', '25' ); |
| 42 | + |
| 43 | + self::$centralNoticeDB = new CentralNoticeDB; |
29 | 44 | } |
30 | 45 | |
31 | 46 | protected function tearDown() { |
32 | 47 | parent::tearDown(); |
33 | 48 | self::$centralNotice->removeCampaign( 'PHPUnitTestCampaign' ); |
| 49 | + self::$centralNotice->removeTemplateFor( 'PHPUnitTestCampaign', 'PHPUnitTestBanner' ); |
| 50 | + self::$noticeTemplate->removeTemplate ( 'PHPUnitTestBanner' ); |
34 | 51 | } |
35 | 52 | |
36 | 53 | public function testDropDownList() { |
— | — | @@ -60,5 +77,28 @@ |
61 | 78 | CentralNotice::getNoticeCountries( 'PHPUnitTestCampaign' ) |
62 | 79 | ); |
63 | 80 | } |
| 81 | + |
| 82 | + public function testGetCampaignBanners() { |
| 83 | + $campaignId = CentralNotice::getNoticeId( 'PHPUnitTestCampaign' ); |
| 84 | + $this->assertEquals( |
| 85 | + '[{"name":"PHPUnitTestBanner","weight":25,"display_anon":1,"display_account":1,"fundraising":1,"landing_pages":"JA1, JA2","campaign":"PHPUnitTestCampaign"}]', |
| 86 | + json_encode( CentralNoticeDB::getCampaignBanners( $campaignId ) ) |
| 87 | + ); |
| 88 | + } |
| 89 | + |
| 90 | + public function testGetCampaignSettings() { |
| 91 | + $campaignArray = array( |
| 92 | + 'enabled' => 0, |
| 93 | + 'end' => 20110818235500, |
| 94 | + 'geo' => 1, |
| 95 | + 'locked' => 0, |
| 96 | + 'preferred' => 0, |
| 97 | + 'start' => 20110718235500 |
| 98 | + ); |
| 99 | + $this->assertEquals( |
| 100 | + $campaignArray, |
| 101 | + CentralNoticeDB::getCampaignSettings( 'PHPUnitTestCampaign', false ) |
| 102 | + ); |
| 103 | + } |
64 | 104 | |
65 | 105 | } |