Speed up platal engine.
[platal.git] / ut / xdbtest.php
index 72b1686..8fd3b2b 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
 
 require_once dirname(__FILE__) . '/../include/test.inc.php';
 
+class FormatBlah implements XDBFormat
+{
+    private $text;
+
+    public function __construct($text)
+    {
+        $this->text = $text;
+    }
+
+    public function format()
+    {
+        return 'blah' . $this->text . 'blah';
+    }
+}
+
 class XDBTest extends PlTestCase
 {
     public function testEscapeString()
     {
-        $this->assertEquals("'blah'", XDB::format('{?}', 'blah'));
-        $this->assertEquals("'blah\\''", XDB::format('{?}', "blah'"));
-        $this->assertEquals("'bl\\'ah'", XDB::format('{?}', "bl'ah"));
-        $this->assertEquals("'\\'blah\\''", XDB::format('{?}', "'blah'"));
+        $this->assertSame("'blah'", XDB::format('{?}', 'blah'));
+        $this->assertSame("'blah\\''", XDB::format('{?}', "blah'"));
+        $this->assertSame("'bl\\'ah'", XDB::format('{?}', "bl'ah"));
+        $this->assertSame("'\\'blah\\''", XDB::format('{?}', "'blah'"));
     }
 
     public function testEscapeInt()
     {
-        $this->assertEquals("1", XDB::format('{?}', 1));
+        $this->assertSame("1", XDB::format('{?}', 1));
     }
 
     public function testEscapeFlagSet()
     {
         $flagset = new PlFlagSet();
         $flagset->addFlag('toto');
-        $this->assertEquals("'toto'", XDB::format('{?}', $flagset));
+        $this->assertSame("'toto'", XDB::format('{?}', $flagset));
         $flagset->addFlag('titi');
-        $this->assertEquals("'toto,titi'", XDB::format('{?}', $flagset));
+        $this->assertSame("'toto,titi'", XDB::format('{?}', $flagset));
         $flagset->addFlag('titi');
-        $this->assertEquals("'toto,titi'", XDB::format('{?}', $flagset));
+        $this->assertSame("'toto,titi'", XDB::format('{?}', $flagset));
     }
 
     public function testEscapeArray()
     {
-        $this->assertEquals("(1, 'toto')", XDB::format('{?}', array(1, 'toto')));
+        $this->assertSame("(1, 'toto')", XDB::format('{?}', array(1, 'toto')));
+    }
+
+    public function testEscapeFormat()
+    {
+        $this->assertSame('blahblah', XDB::format('{?}', new FormatBlah('')));
+        $this->assertSame('blahblahblah', XDB::format('{?}', new FormatBlah('blah')));
+        $this->assertSame('blahBloumblah', XDB::format('{?}', new FormatBlah('Bloum')));
     }
 }