MediaWiki  1.23.2
CdbTest.php
Go to the documentation of this file.
1 <?php
2 
8 class CdbTest extends MediaWikiTestCase {
9 
10  protected function setUp() {
11  parent::setUp();
12  if ( !CdbReader::haveExtension() ) {
13  $this->markTestSkipped( 'Native CDB support is not available' );
14  }
15  }
16 
20  public function testCdb() {
21  $dir = wfTempDir();
22  if ( !is_writable( $dir ) ) {
23  $this->markTestSkipped( "Temp dir isn't writable" );
24  }
25 
26  $phpcdbfile = $this->getNewTempFile();
27  $dbacdbfile = $this->getNewTempFile();
28 
29  $w1 = new CdbWriterPHP( $phpcdbfile );
30  $w2 = new CdbWriterDBA( $dbacdbfile );
31 
32  $data = array();
33  for ( $i = 0; $i < 1000; $i++ ) {
34  $key = $this->randomString();
35  $value = $this->randomString();
36  $w1->set( $key, $value );
37  $w2->set( $key, $value );
38 
39  if ( !isset( $data[$key] ) ) {
40  $data[$key] = $value;
41  }
42  }
43 
44  $w1->close();
45  $w2->close();
46 
47  $this->assertEquals(
48  md5_file( $phpcdbfile ),
49  md5_file( $dbacdbfile ),
50  'same hash'
51  );
52 
53  $r1 = new CdbReaderPHP( $phpcdbfile );
54  $r2 = new CdbReaderDBA( $dbacdbfile );
55 
56  foreach ( $data as $key => $value ) {
57  if ( $key === '' ) {
58  // Known bug
59  continue;
60  }
61  $v1 = $r1->get( $key );
62  $v2 = $r2->get( $key );
63 
64  $v1 = $v1 === false ? '(not found)' : $v1;
65  $v2 = $v2 === false ? '(not found)' : $v2;
66 
67  # cdbAssert( 'Mismatch', $key, $v1, $v2 );
68  $this->cdbAssert( "PHP error", $key, $v1, $value );
69  $this->cdbAssert( "DBA error", $key, $v2, $value );
70  }
71  }
72 
73  private function randomString() {
74  $len = mt_rand( 0, 10 );
75  $s = '';
76  for ( $j = 0; $j < $len; $j++ ) {
77  $s .= chr( mt_rand( 0, 255 ) );
78  }
79 
80  return $s;
81  }
82 
83  private function cdbAssert( $msg, $key, $v1, $v2 ) {
84  $this->assertEquals(
85  $v2,
86  $v1,
87  $msg . ', k=' . bin2hex( $key )
88  );
89  }
90 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
CdbWriterDBA
Writer class which uses the DBA extension.
Definition: CdbDBA.php:49
$s
$s
Definition: mergeMessageFileList.php:156
CdbTest\cdbAssert
cdbAssert( $msg, $key, $v1, $v2)
Definition: CdbTest.php:83
CdbTest
Test the CDB reader/writer @covers CdbWriterPHP @covers CdbWriterDBA.
Definition: CdbTest.php:8
MediaWikiTestCase\getNewTempFile
getNewTempFile()
Obtains a new temporary file name.
Definition: MediaWikiTestCase.php:156
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
CdbReader\haveExtension
static haveExtension()
Returns true if the native extension is available.
Definition: Cdb.php:52
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
CdbWriterPHP
CDB writer class.
Definition: CdbPHP.php:290
$value
$value
Definition: styleTest.css.php:45
CdbTest\randomString
randomString()
Definition: CdbTest.php:73
CdbReaderDBA
Reader class which uses the DBA extension.
Definition: CdbDBA.php:26
CdbReaderPHP
CDB reader class.
Definition: CdbPHP.php:102
CdbTest\setUp
setUp()
Definition: CdbTest.php:10
wfTempDir
wfTempDir()
Tries to get the system directory for temporary files.
Definition: GlobalFunctions.php:2564
$dir
if(count( $args)==0) $dir
Definition: importImages.php:49
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
CdbTest\testCdb
testCdb()
@group medium
Definition: CdbTest.php:20