[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/tests/inc/Subscriptions/ -> SubscriberManagerTest.php (source)

   1  <?php
   2  
   3  namespace tests\inc\Subscriptions;
   4  
   5  use dokuwiki\Subscriptions\SubscriberManager;
   6  use DokuWikiTest;
   7  
   8  class SubscriberManagerTest extends DokuWikiTest
   9  {
  10      private $originalSubscriptionConfig;
  11  
  12      public function setUp()
  13      {
  14          parent::setUp();
  15          global $conf;
  16          $this->originalSubscriptionConfig = $conf['subscribers'];
  17          $conf['subscribers'] = true;
  18      }
  19  
  20      protected function tearDown()
  21      {
  22          global $conf;
  23          $conf['subscribers'] = $this->originalSubscriptionConfig;
  24          parent::tearDown();
  25      }
  26  
  27      public function testAddremove()
  28      {
  29          $sub = new SubscriberManager();
  30  
  31          // no subscriptions
  32          $this->assertArrayNotHasKey(
  33              'wiki:dokuwiki',
  34              $sub->subscribers('wiki:dokuwiki', null, ['every', 'list', 'digest'])
  35          );
  36  
  37          // add page subscription
  38          $sub->add('wiki:dokuwiki', 'testuser', 'every');
  39  
  40          // one subscription
  41          $this->assertArrayHasKey(
  42              'wiki:dokuwiki',
  43              $sub->subscribers('wiki:dokuwiki', null, ['every', 'list', 'digest'])
  44          );
  45  
  46          // remove page subscription
  47          $sub->remove('wiki:dokuwiki', 'testuser');
  48  
  49          // no subscription
  50          $this->assertArrayNotHasKey(
  51              'wiki:dokuwiki',
  52              $sub->subscribers('wiki:dokuwiki', null, ['every', 'list', 'digest'])
  53          );
  54  
  55          // add namespace subscription
  56          $sub->add('wiki:', 'testuser', 'every');
  57  
  58          // one subscription
  59          $this->assertArrayHasKey(
  60              'wiki:',
  61              $sub->subscribers('wiki:dokuwiki', null, ['every', 'list', 'digest'])
  62          );
  63  
  64          // remove (non existing) page subscription
  65          $sub->remove('wiki:dokuwiki', 'testuser');
  66  
  67          // still one subscription
  68          $this->assertArrayHasKey(
  69              'wiki:',
  70              $sub->subscribers('wiki:dokuwiki', null, ['every', 'list', 'digest'])
  71          );
  72  
  73          // change namespace subscription
  74          $sub->add('wiki:', 'testuser', 'digest', '1234567');
  75  
  76          // still one subscription
  77          $this->assertArrayHasKey(
  78              'wiki:',
  79              $sub->subscribers('wiki:dokuwiki', null, ['every', 'list', 'digest'])
  80          );
  81  
  82          // check contents
  83          $this->assertEquals(
  84              ['wiki:' => ['testuser' => ['digest', '1234567']]],
  85              $sub->subscribers('wiki:dokuwiki', null, ['every', 'list', 'digest'])
  86          );
  87  
  88          // change subscription data
  89          $sub->add('wiki:', 'testuser', 'digest', '7654321');
  90  
  91          // still one subscription
  92          $this->assertArrayHasKey(
  93              'wiki:',
  94              $sub->subscribers('wiki:dokuwiki', null, ['every', 'list', 'digest'])
  95          );
  96  
  97          // check contents
  98          $this->assertEquals(
  99              ['wiki:' => ['testuser' => ['digest', '7654321']]],
 100              $sub->subscribers('wiki:dokuwiki', null, ['every', 'list', 'digest'])
 101          );
 102      }
 103  
 104      /**
 105       * Tests, if overwriting subscriptions works even when subscriptions for the same
 106       * user exist for two nested namespaces, this is a test for the bug described in FS#2580
 107       */
 108      public function testOverwrite()
 109      {
 110          $sub = new SubscriberManager();
 111  
 112          $sub->add(':', 'admin', 'digest', '123456789');
 113          $sub->add(':wiki:', 'admin', 'digest', '123456789');
 114          $sub->add(':', 'admin', 'digest', '1234');
 115          $sub->add(':wiki:', 'admin', 'digest', '1234');
 116  
 117          $subscriptions = $sub->subscribers(':wiki:', 'admin');
 118  
 119          $this->assertCount(
 120              1,
 121              $subscriptions[':'],
 122              'More than one subscription saved for the root namespace even though the old one should have been overwritten.'
 123          );
 124          $this->assertCount(
 125              1,
 126              $subscriptions[':wiki:'],
 127              'More than one subscription saved for the wiki namespace even though the old one should have been overwritten.'
 128          );
 129          $this->assertCount(2, $subscriptions, 'Didn\'t find the expected two subscriptions');
 130      }
 131  }