public function testId() { $msgId = rand(); $message = new Messages(); $message->setId($msgId); $this->assertEquals($msgId, $message->getId()); }
public static function parseMessage($contents, $id) { $crawler = new Crawler(); $crawler->addHTMLContent(str_replace('<br />', '', $contents), 'UTF-8'); $message = new Messages(); $message->setId((int) $id); # Action id of the message. # Example: # <input type="button" onclick="document.location='/mymessages.php?go=send&replyid=21193061&threadid=16092543&toname=Ratan12'" class="inputButton" value=" Reply "> $actionId = $crawler->filterXPath('//form[contains(@action,"delete")]/input[@name="id"]'); $message->setActionId((int) $actionId->attr('value')); # Thread id of the message. # Example: # <a href="?go=read&id=0000000&threadid=00000000"> $threadId = $crawler->filterXPath('//div/input[contains(@value,"Reply")]'); $threadId = $threadId->attr('onclick'); if (preg_match('/threadid=([\\d]*)/', $threadId, $threadMatches)) { $message->setThreadId((int) $threadMatches[1]); } # Username of the sender. # Example: # <a href="http://myanimelist.net/profile/ratan12">ratan12</a> $message->setUsername($crawler->filterXPath('//td[@class="dialog-text"]/h2/a')->text()); # Time of the received message. # Example: # <small>50 minutes ago</small> $time = $crawler->filterXPath('//td[@class="dialog-text"]/div[contains(@class,"lightLink")]'); if (count($time) > 0) { $message->setTime($time->text()); } # Subject. # Example: # <div style="margin-bottom: 4px; font-weight: bold;">re: coolmessage</div> $messageSubject = $crawler->filterXPath('//td[@class="dialog-text"]/div[contains(@class,"fw-b")]')->text(); $message->setSubject($messageSubject); # Message. $messageText = $crawler->filterXPath('//td[@class="dialog-text"]'); if (preg_match('/Test Test<\\/div>(.*?)<div/s', $messageText->html(), $messageBody)) { $message->setMessage($messageBody[1]); } return $message; }