View source
<?php
use RocketChat\RocketChat;
class RocketChatTestUnitTest extends DrupalUnitTestCase {
public static function getInfo() {
return array(
'name' => 'Rocket.Chat unit tests',
'description' => 'Check if several different paths are process as ' . 'expected by the checkIfTargetIsRocketChatPath() ' . 'function.',
'group' => 'Rocket Chat',
);
}
public function setUp() {
drupal_load('module', 'rocket_chat');
module_load_include('class.inc', 'rocket_chat', 'RocketChat');
parent::setUp();
}
private function pathTest(&$paths, &$path) {
return RocketChat::checkIfTargetIsRocketChatPath($paths, $path);
}
private function pathTrueTest(&$paths, $path) {
return $this
->assertTrue($this
->pathTest($paths, $path), "Display Widget on [" . $path . "] ==> Yes", 'RocketChat');
}
private function pathFalseTest(&$paths, $path) {
return $this
->assertFalse($this
->pathTest($paths, $path), "Display Widget on [" . $path . "] ==> No", 'RocketChat');
}
private function javascriptVersionTest($version = null, $url = "https://default") {
$testValue = \RocketChat\LiveChat::getLivechatJavascript($url, $version);
if (empty($testValue)) {
return false;
}
if (substr_count(!empty($testValue) ? $testValue : "1.0.0", $url) > 0) {
return TRUE;
}
return false;
}
public function testLiveChatJavascriptGeneratorUnitTest() {
$group = "JavaScript";
$this
->assertTrue($this
->javascriptVersionTest("legacy"), "Livechat Javascipt Generation [legacy].", $group);
$state[] = $this
->assertTrue($this
->javascriptVersionTest("legacy"), "Livechat Javascipt Generation [legacy].", $group);
$state[] = $this
->assertTrue($this
->javascriptVersionTest("1.0.0"), "Livechat Javascipt Generation [1.0.0].", $group);
$state[] = $this
->assertFalse($this
->javascriptVersionTest("BOGUS"), "Livechat Javascipt Generation [BOGUS]. (Fail tesT)", $group);
$state[] = $this
->assertTrue($this
->javascriptVersionTest(), "Livechat Javascipt Generation [DEFAULT].", $group);
}
public function testRocketChatUnitTest() {
$paths = [
"<front>",
"node/*",
"admin/chat/*/secret",
"",
];
$state = array();
$state[] = $this
->pathFalseTest($paths, "<front>");
$state[] = $this
->pathTrueTest($paths, "");
$state[] = $this
->pathFalseTest($paths, "<back>");
$state[] = $this
->pathTrueTest($paths, "node");
$state[] = $this
->pathTrueTest($paths, "node/");
$state[] = $this
->pathTrueTest($paths, "node/1");
$state[] = $this
->pathTrueTest($paths, "node/9");
$state[] = $this
->pathTrueTest($paths, "node/42/edit");
$state[] = $this
->pathTrueTest($paths, "admin/chat/superduper/secret");
$state[] = $this
->pathFalseTest($paths, "admin/chat/realyImportant/falseSecret");
$state[] = $this
->pathTrueTest($paths, "admin/chat/realyImportant/f/secret");
$state[] = $this
->pathTrueTest($paths, "admin/chat/realyImportant/f/r/secret");
}
}