[ Index ] |
PHP Cross Reference of DokuWiki |
[Summary view] [Print] [Text view]
1 <?php 2 3 namespace tests\inc\Subscriptions; 4 5 use dokuwiki\Subscriptions\BulkSubscriptionSender; 6 use dokuwiki\Subscriptions\SubscriberManager; 7 use dokuwiki\test\mock\MailerMock; 8 use DokuWikiTest; 9 10 class BulkSubscriptionsSenderTest extends DokuWikiTest 11 { 12 13 private $originalSubscriptionConfig; 14 15 public function setUp() 16 { 17 parent::setUp(); 18 global $conf; 19 $this->originalSubscriptionConfig = $conf['subscribers']; 20 $conf['subscribers'] = true; 21 } 22 23 protected function tearDown() 24 { 25 global $conf; 26 $conf['subscribers'] = $this->originalSubscriptionConfig; 27 parent::tearDown(); 28 } 29 30 public function testBulkdigest() 31 { 32 $mailerMock = new MailerMock(); 33 $sub = new BulkSubscriptionSender($mailerMock); 34 $manager = new SubscriberManager(); 35 36 // let's start with nothing 37 $this->assertEquals(0, $sub->sendBulk('sub1:test')); 38 39 // create a subscription 40 $manager->add('sub1:', 'testuser', 'digest', '978328800'); // last mod 2001-01-01 41 42 // now create change 43 $_SERVER['REMOTE_USER'] = 'someguy'; 44 saveWikiText('sub1:test', 'foo bar', 'a subscription change', false); 45 46 // should trigger a mail 47 $this->assertEquals(1, $sub->sendBulk('sub1:test')); 48 $this->assertEquals(['arthur@example.com'], array_column($mailerMock->mails, 'Bcc')); 49 50 $mailerMock->mails = []; 51 52 // now create more changes 53 $_SERVER['REMOTE_USER'] = 'someguy'; 54 saveWikiText('sub1:sub2:test', 'foo bar', 'a subscription change', false); 55 saveWikiText('sub1:another_test', 'foo bar', 'a subscription change', false); 56 57 // should not trigger a mail, because the subscription time has not been reached, yet 58 $this->assertEquals(0, $sub->sendBulk('sub1:test')); 59 $this->assertEquals([], array_column($mailerMock->mails, 'Bcc')); 60 61 // reset the subscription time 62 $manager->add('sub1:', 'testuser', 'digest', '978328800'); // last mod 2001-01-01 63 64 // we now should get mails for three changes 65 $this->assertEquals(3, $sub->sendBulk('sub1:test')); 66 $this->assertEquals( 67 ['arthur@example.com', 'arthur@example.com', 'arthur@example.com'], 68 array_column($mailerMock->mails, 'Bcc') 69 ); 70 } 71 72 public function testBulklist() 73 { 74 $mailerMock = new MailerMock(); 75 $sub = new BulkSubscriptionSender($mailerMock); 76 $manager = new SubscriberManager(); 77 78 // let's start with nothing 79 $this->assertEquals(0, $sub->sendBulk('sub1:test')); 80 81 // create a subscription 82 $manager->add('sub1:', 'testuser', 'list', '978328800'); // last mod 2001-01-01 83 84 // now create change 85 $_SERVER['REMOTE_USER'] = 'someguy'; 86 saveWikiText('sub1:test', 'foo bar', 'a subscription change', false); 87 88 // should trigger a mail 89 $this->assertEquals(1, $sub->sendBulk('sub1:test')); 90 $this->assertEquals(['arthur@example.com'], array_column($mailerMock->mails, 'Bcc')); 91 92 $mailerMock->mails = []; 93 94 // now create more changes 95 $_SERVER['REMOTE_USER'] = 'someguy'; 96 saveWikiText('sub1:sub2:test', 'foo bar', 'a subscription change', false); 97 saveWikiText('sub1:another_test', 'foo bar', 'a subscription change', false); 98 99 // should not trigger a mail, because the subscription time has not been reached, yet 100 $this->assertEquals(0, $sub->sendBulk('sub1:test')); 101 $this->assertEquals([], array_column($mailerMock->mails, 'Bcc')); 102 103 // reset the subscription time 104 $manager->add('sub1:', 'testuser', 'list', '978328800'); // last mod 2001-01-01 105 106 // we now should get a single mail for all three changes 107 $this->assertEquals(1, $sub->sendBulk('sub1:test')); 108 $this->assertEquals(['arthur@example.com'], array_column($mailerMock->mails, 'Bcc')); 109 } 110 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body