aboutsummaryrefslogtreecommitdiff
path: root/tests/commonDescriptionTest.php
blob: f73b6468bfa0a2ffd4e6ce191a8b979f8ddb09c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
require_once 'PHPUnit/Framework.php';

/*
To launch this test, type the following line into a shell
at the root of the scuttlePlus directory :
     phpunit CommonDescriptionTest tests/commonDescriptionTest.php
*/

class CommonDescriptionTest extends PHPUnit_Framework_TestCase
{
    protected $us;
    protected $bs;
    protected $b2ts;
    protected $tts;
    protected $tsts;
    protected $cds;
 
    protected function setUp()
    {
        global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype, $tableprefix;
	require_once('./header.inc.php');

	$this->us =SemanticScuttle_Service_Factory::getServiceInstance('User');
	$this->bs =SemanticScuttle_Service_Factory::getServiceInstance('Bookmark');
	$this->bs->deleteAll();
	$this->b2ts =SemanticScuttle_Service_Factory::getServiceInstance('Bookmark2Tag');
	$this->b2ts->deleteAll();
	$this->tts =SemanticScuttle_Service_Factory::getServiceInstance('Tag2Tag');
	$this->tts->deleteAll(); 
	$this->tsts =SemanticScuttle_Service_Factory::getServiceInstance('TagStat');
	$this->tsts->deleteAll();
	$this->cds =SemanticScuttle_Service_Factory::getServiceInstance('CommonDescription');
	$this->cds->deleteAll();
    }
 
    public function testModifyDescription()
    {
	$cds = $this->cds;

	$uId1 = 1;
	$uId2 = 2;
	$title1 = "title1";
	$title2 = "title2";
	$desc1 = "&é\"'(-è_çà)=´~#'#{{[\\\\[||`\^\^@^@}¹²¡×¿ ?./§µ%";
	$desc2 = "æâ€êþÿûîîôôöŀï'üð’‘ßä«≤»©»  ↓¿×÷¡¹²³";
	$time1 = time();
	$time2 = time()+200;

	$tagDesc1 = array('cdId'=>1, 'tag'=>'taghouse', 'cdDescription'=>$desc1, 'uId'=>$uId1,'cdDatetime'=>$time1);
	$tagDesc2 = array('cdId'=>2, 'tag'=>'taghouse', 'cdDescription'=>$desc2, 'uId'=>$uId2,'cdDatetime'=>$time2);

	$cds->addTagDescription('taghouse', $desc1, $uId1, $time1);
	$cds->addTagDescription('taghouse', $desc2, $uId2, $time2);

	$desc = $cds->getLastTagDescription('taghouse');
	$this->assertContains('taghouse', $desc);
	$this->assertContains($desc2, $desc);
	$this->assertContains(gmdate('Y-m-d H:i:s', $time2), $desc);

	$desc = $cds->getAllTagsDescription('taghouse');
	$this->assertContains($desc1, $desc[1]);
	$this->assertContains(gmdate('Y-m-d H:i:s', $time1), $desc[1]);
	$this->assertContains($desc2, $desc[0]);
	$this->assertContains(gmdate('Y-m-d H:i:s', $time2), $desc[0]);
	
	$desc = $cds->getDescriptionById(1);
	$this->assertContains($desc1, $desc);

	$bkDesc1 = array('cdId'=>3, 'bHash'=>'10', 'cdTitle'=>$title1, 'cdDescription'=>$desc1, 'uId'=>$uId1,'cdDatetime'=>$time1);
	$bkDesc2 = array('cdId'=>4, 'bHash'=>'10', 'cdTitle'=>$title2, 'cdDescription'=>$desc2, 'uId'=>$uId2,'cdDatetime'=>$time2);

	$cds->addBookmarkDescription(10, $title1, $desc1, $uId1, $time1);
	$cds->addBookmarkDescription(10, $title2, $desc2, $uId2, $time2);

	$desc = $cds->getLastBookmarkDescription(10);
	$this->assertContains($title2, $desc);
	$this->assertContains($desc2, $desc);
	$this->assertContains(gmdate('Y-m-d H:i:s', $time2), $desc);

	$desc = $cds->getAllBookmarksDescription(10);
	$this->assertContains($title1, $desc[1]);
	$this->assertContains($desc1, $desc[1]);
	$this->assertContains(gmdate('Y-m-d H:i:s', $time1), $desc[1]);
	$this->assertContains($title2, $desc[0]);
	$this->assertContains($desc2, $desc[0]);
	$this->assertContains(gmdate('Y-m-d H:i:s', $time2), $desc[0]);
	
	$desc = $cds->getDescriptionById(3);
	$this->assertContains($desc1, $desc);


    }

}
?>