[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/tests/inc/ -> indexer_rename.test.php (source)

   1  <?php
   2  /**
   3   * Test cases for the Doku_Indexer::renamePage and Doku_Indexer::renameMetaValue methods
   4   */
   5  class indexer_rename_test extends DokuWikiTest {
   6      /** @var Doku_Indexer $indexer */
   7      private $indexer;
   8  
   9      private $old_id = 'old_testid';
  10  
  11      function setUp() {
  12          parent::setUp();
  13          $this->indexer = idx_get_indexer();
  14          $this->indexer->clear();
  15  
  16          saveWikiText($this->old_id, 'Old test content', 'Created old test page for indexer rename test');
  17          idx_addPage($this->old_id);
  18      }
  19  
  20      function test_rename_to_new_page() {
  21          $newid = 'new_id_1';
  22  
  23          $oldpid = $this->indexer->getPID($this->old_id);
  24  
  25          $this->assertTrue($this->indexer->renamePage($this->old_id, $newid), 'Renaming the page to a new id failed');
  26          io_rename(wikiFN($this->old_id), wikiFN($newid));
  27  
  28          $this->assertNotEquals($this->indexer->getPID($this->old_id), $oldpid, 'PID for the old page unchanged after rename.');
  29          $this->assertEquals($this->indexer->getPID($newid), $oldpid, 'New page has not the old pid.');
  30          $query = array('old');
  31          $this->assertEquals(array('old' => array($newid => 1)), $this->indexer->lookup($query), '"Old" doesn\'t find the new page');
  32      }
  33  
  34      function test_rename_to_existing_page() {
  35          $newid = 'existing_page';
  36          saveWikiText($newid, 'Existing content', 'Created page for move_to_existing_page');
  37          idx_addPage($newid);
  38  
  39          $oldpid = $this->indexer->getPID($this->old_id);
  40          $existingpid = $this->indexer->getPID($newid);
  41  
  42          $this->assertTrue($this->indexer->renamePage($this->old_id, $newid), 'Renaming the page to an existing id failed');
  43  
  44          $this->assertNotEquals($this->indexer->getPID($this->old_id), $oldpid, 'PID for old page unchanged after rename.');
  45          $this->assertNotEquals($this->indexer->getPID($this->old_id), $existingpid, 'PID for old page is now PID of the existing page.');
  46          $this->assertEquals($this->indexer->getPID($newid), $oldpid, 'New page has not the old pid.');
  47          $query = array('existing');
  48          $this->assertEquals(array('existing' => array()), $this->indexer->lookup($query), 'Existing page hasn\'t been deleted from the index.');
  49          $query = array('old');
  50          $this->assertEquals(array('old' => array($newid => 1)), $this->indexer->lookup($query), '"Old" doesn\'t find the new page');
  51      }
  52  
  53      function test_meta_rename_to_new_value() {
  54          $this->indexer->addMetaKeys($this->old_id, array('mkey' => 'old_value'));
  55  
  56          $this->assertTrue($this->indexer->renameMetaValue('mkey', 'old_value', 'new_value'), 'Meta value rename to new value failed.');
  57          $query = 'old_value';
  58          $this->assertEquals(array(), $this->indexer->lookupKey('mkey', $query), 'Page can still be found under old value.');
  59          $query = 'new_value';
  60          $this->assertEquals(array($this->old_id), $this->indexer->lookupKey('mkey', $query), 'Page can\'t be found under new value.');
  61      }
  62  
  63      function test_meta_rename_to_existing_value() {
  64          $this->indexer->addMetaKeys($this->old_id, array('mkey' => array('old_value', 'new_value')));
  65  
  66          saveWikiText('newvalue', 'Test page', '');
  67          idx_addPage('newvalue');
  68          $this->indexer->addMetaKeys('newvalue', array('mkey' => array('new_value')));
  69  
  70          saveWikiText('oldvalue', 'Test page', '');
  71          idx_addPage('oldvalue');
  72          $this->indexer->addMetaKeys('oldvalue', array('mkey' => array('old_value')));
  73  
  74          $this->assertTrue($this->indexer->renameMetaValue('mkey', 'old_value', 'new_value'), 'Meta value rename to existing value failed');
  75          $query = 'old_value';
  76          $this->assertEquals(array(), $this->indexer->lookupKey('mkey', $query), 'Page can still be found under old value.');
  77          $query = 'new_value';
  78          $result = $this->indexer->lookupKey('mkey', $query);
  79          $this->assertContains($this->old_id, $result, 'Page with both values can\'t be found anymore');
  80          $this->assertContains('newvalue', $result, 'Page with new value can\'t be found anymore');
  81          $this->assertContains('oldvalue', $result, 'Page with only the old value can\'t be found anymore');
  82      }
  83  }