public function testScAddContent() { $room = 'njiSeDkea2'; $name = 'foo'; $idstr = '123'; $content = 'Hello <b>world</b>'; $dat_filename = sc_dat_filename($room); if (file_exists($dat_filename)) { unlink($dat_filename); } $pos = sc_add_content($room, $name, $idstr, $content); $this->assertTrue($pos > 0); $all_data = file($dat_filename); $this->assertEquals(2, sizeof($all_data)); $this->assertEquals($room, trim($all_data[0])); $contents = sc_get_contents($room); $this->assertEquals(1, $contents[0][1]); $this->assertEquals(1, $contents[0][2]); $this->assertEquals($name, $contents[1][0]); $this->assertEquals($idstr, $contents[1][1]); $this->assertEquals($content, $contents[1][3]); sc_add_content($room, $name, $idstr, $content); sc_add_content($room, $name, $idstr, "3"); sc_add_content($room, $name, $idstr, "4"); sc_add_content($room, '', $idstr, "5"); $contents = sc_get_contents($room, 4); $this->assertEquals(4, $contents[0][1]); $this->assertEquals(5, $contents[0][2]); $this->assertEquals(3, sizeof($contents)); $chat = $contents[1]; $this->assertEquals($name, $chat[0]); $this->assertEquals($idstr, $chat[1]); $this->assertEquals("4", $chat[3]); $chat = $contents[2]; $this->assertEquals('', $chat[0]); $this->assertEquals($idstr, $chat[1]); $this->assertEquals("5", $chat[3]); $contents = sc_get_contents($room, 6); $this->assertEquals(1, sizeof($contents[0])); array_shift($contents); $this->assertEquals(0, sizeof($contents)); }
$_GET[$key] = stripslashes($_GET[$key]); } $o[$key] = trim($_GET[$key]); } if (!isset($o['room']) || strlen($o['room']) >= MAX_ROOM_LEN) { exit; } foreach (array('m', 's', 'e') as $key) { if (isset($o[$key]) && is_numeric($o[$key])) { $o[$key] = (int) $o[$key]; if ($o[$key] <= 0) { $o[$key] = 1; } } } if (isset($_GET['last'])) { $contents = sc_get_last_contents($o['room'], $o['m']); } else { $contents = sc_get_contents($o['room'], $o['s'], $o['e'], true); } $len_contents = sizeof($contents) - 1; if ($len_contents == 0) { ini_set('zlib.output_compression', 'Off'); } session_name("stechat"); session_start(); sc_set_idstr(); header("Content-type: text/javascript"); if ($len_contents > 0) { print json_encode($contents); }