<?php # -*- coding: utf-8 -*-

$root '../';
$home dirname(__FILE__).'/';
$tmpdir $home.$root.'tmp/';

require_once(
$home.$root.'class.comments.php');
require_once(
$home.$root.'simpletest/unit_tester.php');
require_once(
$home.$root.'simpletest/reporter.php');

class 
TestOfCommenting extends UnitTestCase {
    var 
$filename// same as in the class
    
var $comment;
    var 
$tmpdir;
    var 
$uid// see testReadComment
    
    
function setUp() {
        
$this->tmpdir $home.$root.'tmp/';
        
$this->comments = new Comments($this->tmpdir);
        
        
$this->filename $this->comments->file;
        
        
$fp fopen($this->tmpdir.$this->filename'w');
        if(
$fp) {
            
fwrite($fp"[]\n");
            
fclose($fp);
        }
    }
    
    function 
tearDown() {
        
//unlink($this->tmpdir.$this->filename);
    
}
    
    function 
testSetFilename() {
        
$filename $this->comments->file;
        
        
$this->comments->setFilename('toto');
        
        
$this->assertTrue($this->comments->file == 'toto');
        
        
$this->comments->setFilename($filename);
    }
    
    function 
testOneComment() {
        
$this->comments->comment('$title''$link''$comment''$email''$name');
        
        
$values $this->comments->getAll();
        
        
$this->assertTrue(count($values) == 1);
        
$this->assertTrue($values[0]->title == '$title');
        
$this->assertTrue($values[0]->link == '$link');
        
$this->assertTrue($values[0]->description == '$comment');
        
$this->assertTrue($values[0]->author == md5('$email'));
        
$this->assertTrue($values[0]->dc->creator == '$name');
        
        
$this->comments->del($values[0]->uid);
        
$values2 $this->comments->getAll();
        
        
$this->assertTrue(count($values2) == count($values) - 1);
    }
    
    function 
testLostOfComments() {
        
$size 69;
        for(
$i 0$i<$size$i++) {
            
$this->comments->comment('title'.$i'link'.$i'comment'.$i'email'.$i'name'.$i);
        }
        
        
$values $this->comments->getAll();
        
        
$this->assertTrue(count($values) == $size);
        
        
$this->comments->delAll();
        
$values $this->comments->getAll();
        
$this->assertTrue(count($values) == 0);
    }
}

?>