diff options
Diffstat (limited to '_test/tests/inc')
-rw-r--r-- | _test/tests/inc/auth_password.test.php | 6 | ||||
-rw-r--r-- | _test/tests/inc/indexer_rename.test.php | 83 | ||||
-rw-r--r-- | _test/tests/inc/search/search.test.php | 19 | ||||
-rw-r--r-- | _test/tests/inc/subscription.test.php | 246 | ||||
-rw-r--r-- | _test/tests/inc/subscription_set.test.php | 20 |
5 files changed, 354 insertions, 20 deletions
diff --git a/_test/tests/inc/auth_password.test.php b/_test/tests/inc/auth_password.test.php index 426353291..27e03be60 100644 --- a/_test/tests/inc/auth_password.test.php +++ b/_test/tests/inc/auth_password.test.php @@ -16,6 +16,7 @@ class auth_password_test extends PHPUnit_Framework_TestCase { 'kmd5' => 'a579299436d7969791189acadd86fcb716', 'djangomd5' => 'md5$abcde$d0fdddeda8cd92725d2b54148ac09158', 'djangosha1' => 'sha1$abcde$c8e65a7f0acc9158843048a53dcc5a6bc4d17678', + 'sha512' => '$6$abcdefgh12345678$J9.zOcgx0lotwZdcz0uulA3IVQMinZvFZVjA5vapRLVAAqtay23XD4xeeUxQ3B4JvDWYFBIxVWW1tOYlHX13k1' ); @@ -61,6 +62,11 @@ class auth_password_test extends PHPUnit_Framework_TestCase { $this->assertTrue(auth_verifyPassword('test12345','$H$9IQRaTwmfeRo7ud9Fh4E2PdI0S3r.L0')); } + function test_veryPassword_mediawiki(){ + $this->assertTrue(auth_verifyPassword('password', ':B:838c83e1:e4ab7024509eef084cdabd03d8b2972c')); + } + + /** * pmd5 checking should throw an exception when a hash with a too high * iteration count is passed diff --git a/_test/tests/inc/indexer_rename.test.php b/_test/tests/inc/indexer_rename.test.php new file mode 100644 index 000000000..d8c456f8e --- /dev/null +++ b/_test/tests/inc/indexer_rename.test.php @@ -0,0 +1,83 @@ +<?php +/** + * Test cases for the Doku_Indexer::renamePage and Doku_Indexer::renameMetaValue methods + */ +class indexer_rename_test extends DokuWikiTest { + /** @var Doku_Indexer $indexer */ + private $indexer; + + private $old_id = 'old_testid'; + + function setUp() { + parent::setUp(); + $this->indexer = idx_get_indexer(); + $this->indexer->clear(); + + saveWikiText($this->old_id, 'Old test content', 'Created old test page for indexer rename test'); + idx_addPage($this->old_id); + } + + function test_rename_to_new_page() { + $newid = 'new_id_1'; + + $oldpid = $this->indexer->getPID($this->old_id); + + $this->assertTrue($this->indexer->renamePage($this->old_id, $newid), 'Renaming the page to a new id failed'); + io_rename(wikiFN($this->old_id), wikiFN($newid)); + + $this->assertNotEquals($this->indexer->getPID($this->old_id), $oldpid, 'PID for the old page unchanged after rename.'); + $this->assertEquals($this->indexer->getPID($newid), $oldpid, 'New page has not the old pid.'); + $query = array('old'); + $this->assertEquals(array('old' => array($newid => 1)), $this->indexer->lookup($query), '"Old" doesn\'t find the new page'); + } + + function test_rename_to_existing_page() { + $newid = 'existing_page'; + saveWikiText($newid, 'Existing content', 'Created page for move_to_existing_page'); + idx_addPage($newid); + + $oldpid = $this->indexer->getPID($this->old_id); + $existingpid = $this->indexer->getPID($newid); + + $this->assertTrue($this->indexer->renamePage($this->old_id, $newid), 'Renaming the page to an existing id failed'); + + $this->assertNotEquals($this->indexer->getPID($this->old_id), $oldpid, 'PID for old page unchanged after rename.'); + $this->assertNotEquals($this->indexer->getPID($this->old_id), $existingpid, 'PID for old page is now PID of the existing page.'); + $this->assertEquals($this->indexer->getPID($newid), $oldpid, 'New page has not the old pid.'); + $query = array('existing'); + $this->assertEquals(array('existing' => array()), $this->indexer->lookup($query), 'Existing page hasn\'t been deleted from the index.'); + $query = array('old'); + $this->assertEquals(array('old' => array($newid => 1)), $this->indexer->lookup($query), '"Old" doesn\'t find the new page'); + } + + function test_meta_rename_to_new_value() { + $this->indexer->addMetaKeys($this->old_id, array('mkey' => 'old_value')); + + $this->assertTrue($this->indexer->renameMetaValue('mkey', 'old_value', 'new_value'), 'Meta value rename to new value failed.'); + $query = 'old_value'; + $this->assertEquals(array(), $this->indexer->lookupKey('mkey', $query), 'Page can still be found under old value.'); + $query = 'new_value'; + $this->assertEquals(array($this->old_id), $this->indexer->lookupKey('mkey', $query), 'Page can\'t be found under new value.'); + } + + function test_meta_rename_to_existing_value() { + $this->indexer->addMetaKeys($this->old_id, array('mkey' => array('old_value', 'new_value'))); + + saveWikiText('newvalue', 'Test page', ''); + idx_addPage('newvalue'); + $this->indexer->addMetaKeys('newvalue', array('mkey' => array('new_value'))); + + saveWikiText('oldvalue', 'Test page', ''); + idx_addPage('oldvalue'); + $this->indexer->addMetaKeys('oldvalue', array('mkey' => array('old_value'))); + + $this->assertTrue($this->indexer->renameMetaValue('mkey', 'old_value', 'new_value'), 'Meta value rename to existing value failed'); + $query = 'old_value'; + $this->assertEquals(array(), $this->indexer->lookupKey('mkey', $query), 'Page can still be found under old value.'); + $query = 'new_value'; + $result = $this->indexer->lookupKey('mkey', $query); + $this->assertContains($this->old_id, $result, 'Page with both values can\'t be found anymore'); + $this->assertContains('newvalue', $result, 'Page with new value can\'t be found anymore'); + $this->assertContains('oldvalue', $result, 'Page with only the old value can\'t be found anymore'); + } +} diff --git a/_test/tests/inc/search/search.test.php b/_test/tests/inc/search/search.test.php index 33cc80e74..9c854a661 100644 --- a/_test/tests/inc/search/search.test.php +++ b/_test/tests/inc/search/search.test.php @@ -1,6 +1,7 @@ <?php class search_test extends DokuWikiTest { + function strip_index_data($entry) { $n_entry = array(); foreach(array('id', 'type', 'level', 'open') as $k) { @@ -9,6 +10,24 @@ class search_test extends DokuWikiTest { return $n_entry; } + function test_search_allpages(){ + $data = array(); + + //depth is 0 hence we should recurse endlesly + search($data, dirname(__FILE__) . '/data', 'search_allpages', array('depth' => 0), 'ns1'); + $this->assertEquals(3, count($data)); + + //depth is 1 and we start too deep to expect results + $data = array(); + search($data, dirname(__FILE__) . '/data', 'search_allpages', array('depth' => 1), 'ns1/ns3'); + $this->assertEquals(0, count($data)); + + //depth is 1 so I should get only pages from ns1 + $data = array(); + search($data, dirname(__FILE__) . '/data', 'search_allpages', array('depth' => 1), 'ns1'); + $this->assertEquals(2, count($data)); + } + function test_search_index(){ $data = array(); search($data, dirname(__FILE__) . '/data', 'search_index', diff --git a/_test/tests/inc/subscription.test.php b/_test/tests/inc/subscription.test.php new file mode 100644 index 000000000..333400576 --- /dev/null +++ b/_test/tests/inc/subscription.test.php @@ -0,0 +1,246 @@ +<?php + +class subscription_test extends DokuWikiTest { + + function test_regexp() { + // data to test against + $data = array( + "casper every\n", + "Andreas digest 1344689733", + "Cold%20Fusion every", + "zioth list 1344691369\n", + "nlights digest", + "rikblok\tdigest \t 1344716803", + ); + + // user, style, data, expected number of results + $tests = array( + array('Cold Fusion', null, null, 1), + array('casper', null, null, 1), + array('nope', null, null, 0), + array('lights', null, null, 0), + array(array('Cold Fusion', 'casper', 'nope'), null, null, 2), + array(null, 'list', null, 1), + array(null, 'every', null, 2), + array(null, 'digest', null, 3), + array(null, array('list', 'every'), null, 3), + array('casper', 'digest', null, 0), + array('casper', array('digest', 'every'), null, 1), + array('zioth', 'list', '1344691369', 1), + array('zioth', null, '1344691369', 1), + array('zioth', 'digest', '1344691369', 0), + ); + + $sub = new MockupSubscription(); + + $row = 0; + foreach($tests as $test) { + $re = $sub->buildregex($test[0], $test[1], $test[2]); + $this->assertFalse(empty($re), "test line $row"); + $result = preg_grep($re, $data); + $this->assertEquals($test[3], count($result), "test line $row. $re got\n".print_r($result, true)); + + $row++; + } + } + + function test_addremove() { + $sub = new MockupSubscription(); + + // no subscriptions + $this->assertArrayNotHasKey( + 'wiki:dokuwiki', + $sub->subscribers('wiki:dokuwiki', null, array('every', 'list', 'digest')) + ); + + // add page subscription + $sub->add('wiki:dokuwiki', 'testuser', 'every'); + + // one subscription + $this->assertArrayHasKey( + 'wiki:dokuwiki', + $sub->subscribers('wiki:dokuwiki', null, array('every', 'list', 'digest')) + ); + + // remove page subscription + $sub->remove('wiki:dokuwiki', 'testuser'); + + // no subscription + $this->assertArrayNotHasKey( + 'wiki:dokuwiki', + $sub->subscribers('wiki:dokuwiki', null, array('every', 'list', 'digest')) + ); + + // add namespace subscription + $sub->add('wiki:', 'testuser', 'every'); + + // one subscription + $this->assertArrayHasKey( + 'wiki:', + $sub->subscribers('wiki:dokuwiki', null, array('every', 'list', 'digest')) + ); + + // remove (non existing) page subscription + $sub->remove('wiki:dokuwiki', 'testuser'); + + // still one subscription + $this->assertArrayHasKey( + 'wiki:', + $sub->subscribers('wiki:dokuwiki', null, array('every', 'list', 'digest')) + ); + + // change namespace subscription + $sub->add('wiki:', 'testuser', 'digest', '1234567'); + + // still one subscription + $this->assertArrayHasKey( + 'wiki:', + $sub->subscribers('wiki:dokuwiki', null, array('every', 'list', 'digest')) + ); + + // check contents + $this->assertEquals( + array('wiki:' => array('testuser' => array('digest', '1234567'))), + $sub->subscribers('wiki:dokuwiki', null, array('every', 'list', 'digest')) + ); + + // change subscription data + $sub->add('wiki:', 'testuser', 'digest', '7654321'); + + // still one subscription + $this->assertArrayHasKey( + 'wiki:', + $sub->subscribers('wiki:dokuwiki', null, array('every', 'list', 'digest')) + ); + + // check contents + $this->assertEquals( + array('wiki:' => array('testuser' => array('digest', '7654321'))), + $sub->subscribers('wiki:dokuwiki', null, array('every', 'list', 'digest')) + ); + } + + function test_bulkdigest() { + $sub = new MockupSubscription(); + + // let's start with nothing + $this->assertEquals(0, $sub->send_bulk('sub1:test')); + + // create a subscription + $sub->add('sub1:', 'testuser', 'digest', '978328800'); // last mod 2001-01-01 + + // now create change + $_SERVER['REMOTE_USER'] = 'someguy'; + saveWikiText('sub1:test', 'foo bar', 'a subscription change', false); + + // should trigger a mail + $this->assertEquals(1, $sub->send_bulk('sub1:test')); + $this->assertEquals(array('arthur@example.com'), $sub->mails); + + $sub->reset(); + + // now create more changes + $_SERVER['REMOTE_USER'] = 'someguy'; + saveWikiText('sub1:sub2:test', 'foo bar', 'a subscription change', false); + saveWikiText('sub1:another_test', 'foo bar', 'a subscription change', false); + + // should not trigger a mail, because the subscription time has not been reached, yet + $this->assertEquals(0, $sub->send_bulk('sub1:test')); + $this->assertEquals(array(), $sub->mails); + + // reset the subscription time + $sub->add('sub1:', 'testuser', 'digest', '978328800'); // last mod 2001-01-01 + + // we now should get mails for three changes + $this->assertEquals(3, $sub->send_bulk('sub1:test')); + $this->assertEquals(array('arthur@example.com', 'arthur@example.com', 'arthur@example.com'), $sub->mails); + } + + function test_bulklist() { + $sub = new MockupSubscription(); + + // let's start with nothing + $this->assertEquals(0, $sub->send_bulk('sub1:test')); + + // create a subscription + $sub->add('sub1:', 'testuser', 'list', '978328800'); // last mod 2001-01-01 + + // now create change + $_SERVER['REMOTE_USER'] = 'someguy'; + saveWikiText('sub1:test', 'foo bar', 'a subscription change', false); + + // should trigger a mail + $this->assertEquals(1, $sub->send_bulk('sub1:test')); + $this->assertEquals(array('arthur@example.com'), $sub->mails); + + $sub->reset(); + + // now create more changes + $_SERVER['REMOTE_USER'] = 'someguy'; + saveWikiText('sub1:sub2:test', 'foo bar', 'a subscription change', false); + saveWikiText('sub1:another_test', 'foo bar', 'a subscription change', false); + + // should not trigger a mail, because the subscription time has not been reached, yet + $this->assertEquals(0, $sub->send_bulk('sub1:test')); + $this->assertEquals(array(), $sub->mails); + + // reset the subscription time + $sub->add('sub1:', 'testuser', 'list', '978328800'); // last mod 2001-01-01 + + // we now should get a single mail for all three changes + $this->assertEquals(1, $sub->send_bulk('sub1:test')); + $this->assertEquals(array('arthur@example.com'), $sub->mails); + } + + /** + * Tests, if overwriting subscriptions works even when subscriptions for the same + * user exist for two nested namespaces, this is a test for the bug described in FS#2580 + */ + function test_overwrite() { + $sub = new MockupSubscription(); + + $sub->add(':', 'admin', 'digest', '123456789'); + $sub->add(':wiki:', 'admin', 'digest', '123456789'); + $sub->add(':', 'admin', 'digest', '1234'); + $sub->add(':wiki:', 'admin', 'digest', '1234'); + + $subscriptions = $sub->subscribers(':wiki:', 'admin'); + + $this->assertCount(1, $subscriptions[':'], 'More than one subscription saved for the root namespace even though the old one should have been overwritten.'); + $this->assertCount(1, $subscriptions[':wiki:'], 'More than one subscription saved for the wiki namespace even though the old one should have been overwritten.'); + $this->assertCount(2, $subscriptions, 'Didn\'t find the expected two subscriptions'); + } +} + +/** + * makes protected methods visible for testing + */ +class MockupSubscription extends Subscription { + public $mails; // we keep sent mails here + + public function __construct() { + $this->reset(); + } + + /** + * resets the mail array + */ + public function reset() { + $this->mails = array(); + } + + public function isenabled() { + return true; + } + + public function buildregex($user = null, $style = null, $data = null) { + return parent::buildregex($user, $style, $data); + } + + protected function send($subscriber_mail, $subject, $id, $template, $trep, $hrep = null) { + $this->mails[] = $subscriber_mail; + return true; + } +} + +//Setup VIM: ex: et ts=4 : diff --git a/_test/tests/inc/subscription_set.test.php b/_test/tests/inc/subscription_set.test.php deleted file mode 100644 index 5c0a6c816..000000000 --- a/_test/tests/inc/subscription_set.test.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php -/** - * Tests the subscription set function - */ -class subscription_set_test extends DokuWikiTest { - /** - * Tests, if overwriting subscriptions works even when subscriptions for the same - * user exist for two nested namespaces, this is a test for the bug described in FS#2580 - */ - function test_overwrite() { - subscription_set('admin', ':', 'digest', '123456789'); - subscription_set('admin', ':wiki:', 'digest', '123456789'); - subscription_set('admin', ':', 'digest', '1234', true); - subscription_set('admin', ':wiki:', 'digest', '1234', true); - $subscriptions = subscription_find(':wiki:', array('user' => 'admin')); - $this->assertCount(1, $subscriptions[':'], 'More than one subscription saved for the root namespace even though the old one should have been overwritten.'); - $this->assertCount(1, $subscriptions[':wiki:'], 'More than one subscription saved for the wiki namespace even though the old one should have been overwritten.'); - $this->assertCount(2, $subscriptions, 'Didn\'t find the expected two subscriptions'); - } -} |