You are here

class BasicTest in Plug 7

Hierarchy

  • class \Drupal\plug_example\Tests\BaseTest extends \Drupal\plug_example\Tests\DrupalWebTestCase

Expanded class hierarchy of BasicTest

File

modules/plug_example/lib/Drupal/plug_example/Tests/BasicTest.php, line 12
Basic tests cases for plug_example module.

Namespace

Drupal\plug_example\Tests
View source
class BasicTest extends BaseTest {

  /**
   * Expected output for default name plugins.
   *
   * @var array
   */
  protected $namePlugins = array(
    // Check that John is not a company, modified in hook_name_plugin_alter().
    'My name is: John Doe',
    'My name is: John Doe',
    'My name is: Mom',
    'Company name: Acme Inc.',
    'Company name: Acme Inc.',
  );

  /**
   * Cache id defined for name plugins.
   *
   * @var string
   */
  protected $nameCache = 'name_plugins';

  /**
   * Expected output for default fruit plugins.
   *
   * @var array
   */
  protected $fruitPlugins = array(
    // Check that Banana is in, added in hook_fruit_plugin_alter().
    'Fruit name: Banana',
    'Fruit name: Apple',
    'Fruit name: Orange',
    'Fruit name: Melon',
    'Yikes, Mamoncillo!',
  );

  /**
   * Cache id defined for name plugins.
   *
   * @var string
   */
  protected $fruitCache = 'fruit_plugins';

  /**
   * Annotated plugins test page path.
   *
   * @var string
   */
  protected $annotatedTestPath = 'plug/test/annotated';

  /**
   * YAML plugins test page path.
   *
   * @var string
   */
  protected $yamlTestPath = 'plug/test/yaml';

  /**
   * The plugin manager.
   *
   * @var NamePluginManager
   */
  protected $manager;

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'Plug Example tests',
      'description' => 'Plug example basic tests',
      'group' => 'Plug',
    );
  }

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp('registry_autoload', 'plug_example');

    // Get a new Name plugin manager to instantiate the test plugins.
    $this->manager = NamePluginManager::create();
  }

  /**
   * Tests annotated plugins example page output.
   */
  public function testBasicAnnotationExamplePage() {
    $this
      ->assertExamplePageResults($this->namePlugins, $this->annotatedTestPath);
  }

  /**
   * Tests YAML plugins example page output.
   */
  public function testBasicYamlExamplePage() {
    $this
      ->assertExamplePageResults($this->fruitPlugins, $this->yamlTestPath);
  }

  /**
   * Test if displayName() handles the names right.
   */
  function testDisplayName() {

    /** @var \Drupal\plug_example\Plugin\name\JohnTest $plugin */
    $plugin = $this->manager
      ->createInstance('john_test', array(
      'em' => TRUE,
    ));
    $this
      ->assertEqual($plugin
      ->displayName(), 'My name is: %name');
    $plugin = $this->manager
      ->createInstance('john_test', array(
      'em' => FALSE,
    ));
    $this
      ->assertEqual($plugin
      ->displayName(), 'My name is: @name');

    /** @var \Drupal\plug_example\Plugin\name\AcmeTest $plugin */
    $plugin = $this->manager
      ->createInstance('acme_test', array(
      'em' => TRUE,
    ));
    $this
      ->assertEqual($plugin
      ->displayName(), 'Company name: %name Inc.');
    $plugin = $this->manager
      ->createInstance('acme_test', array(
      'em' => FALSE,
    ));
    $this
      ->assertEqual($plugin
      ->displayName(), 'Company name: @name Inc.');
  }

  /**
   * Test plugin internals.
   */
  function testPluginInternals() {

    /** @var \Drupal\plug_example\Plugin\name\JohnTest $plugin */
    $plugin = $this->manager
      ->createInstance('john_test', array(
      'em' => TRUE,
    ));
    $definition = $plugin
      ->getPluginDefinition();
    $expected = array(
      'class' => 'Drupal\\plug_example\\Plugin\\name\\JohnTest',
      'company' => FALSE,
      'id' => 'john_test',
      'provider' => 'plug_example',
    );
    $this
      ->assertEqual($expected, $definition);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BaseTest::assertCountXpathItems protected function Asserts the number of items in a XPath selector.
BaseTest::assertExamplePageResults protected function Checks the example page content.
BaseTest::assertTestModulePlugins protected function Checks the behavior when enabling/disabling plug_test module.
BasicTest::$annotatedTestPath protected property Annotated plugins test page path. Overrides BaseTest::$annotatedTestPath
BasicTest::$fruitCache protected property Cache id defined for name plugins. Overrides BaseTest::$fruitCache
BasicTest::$fruitPlugins protected property Expected output for default fruit plugins. Overrides BaseTest::$fruitPlugins
BasicTest::$manager protected property The plugin manager. Overrides BaseTest::$manager
BasicTest::$nameCache protected property Cache id defined for name plugins. Overrides BaseTest::$nameCache
BasicTest::$namePlugins protected property Expected output for default name plugins. Overrides BaseTest::$namePlugins
BasicTest::$yamlTestPath protected property YAML plugins test page path. Overrides BaseTest::$yamlTestPath
BasicTest::getInfo public static function
BasicTest::setUp public function
BasicTest::testBasicAnnotationExamplePage public function Tests annotated plugins example page output.
BasicTest::testBasicYamlExamplePage public function Tests YAML plugins example page output.
BasicTest::testDisplayName function Test if displayName() handles the names right.
BasicTest::testPluginInternals function Test plugin internals.