You are here

rocket_chat.test in Rocket.Chat 7

Same filename and directory in other branches
  1. 7.2 rocket_chat.test

File

rocket_chat.test
View source
<?php

/**
 * Created by PhpStorm.
 * User: Sysosmaster
 * Date: 03/01/17
 * Time: 16:56
 */
use RocketChat\RocketChat;

/**
 * Although most core test cases are based on DrupalWebTestCase and are
 * functional tests (exercising the web UI) we also have DrupalUnitTestCase,
 * which executes much faster because a Drupal install does not have to be
 * one. No environment is provided to a test case based on DrupalUnitTestCase;
 * it must be entirely self-contained.
 *
 * @see DrupalUnitTestCase
 *
 * @ingroup simpletest_example
 */
class RocketChatTestUnitTest extends DrupalUnitTestCase {

  /**
   * {@inheritdoc}
   */
  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',
    );
  }

  /**
   * Set up the test environment.
   *
   * Note that we use drupal_load() instead of passing our module dependency
   * to parent::setUp(). That's because we're using DrupalUnitTestCase, and
   * thus we don't want to install the module, only load it's code.
   *
   * Also, DrupalUnitTestCase can't actually install modules. This is by
   * design.
   */
  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');
  }

  /**
   * Test RocketChat::checkIfTargetIsRocketChatPath().
   *
   * Note that no environment is provided; we're just testing the correct
   * behavior of a function when passed specific arguments.
   */
  public function testRocketChatUnitTestExampleFunction() {
    $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");

    //node is same as <front>
    $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");
  }

}

Classes

Namesort descending Description
RocketChatTestUnitTest Although most core test cases are based on DrupalWebTestCase and are functional tests (exercising the web UI) we also have DrupalUnitTestCase, which executes much faster because a Drupal install does not have to be one. No environment is provided to a…