Error message

  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).
  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).

class TMGMTDemoTest

Tests the demo module for TMGMT.

@group TMGMT

Hierarchy

Expanded class hierarchy of TMGMTDemoTest

File

modules/demo/tests/src/Functional/TMGMTDemoTest.php, line 13

Namespace

Drupal\Tests\tmgmt_demo\Functional
View source
class TMGMTDemoTest extends TMGMTTestBase {

  /**
   * Modules to enable.
   *
   * @var string[]
   */
  protected static $modules = array(
    'tmgmt_demo',
    'ckeditor5',
  );

  /**
   * {@inheritdoc}
   */
  public function setUp() : void {
    parent::setUp();
    $basic_html_format = FilterFormat::load('basic_html');
    $restricted_html_format = FilterFormat::create(array(
      'format' => 'restricted_html',
      'name' => 'Restricted HTML',
    ));
    $restricted_html_format
      ->save();
    $full_html_format = FilterFormat::create(array(
      'format' => 'full_html',
      'name' => 'Full HTML',
    ));
    $full_html_format
      ->save();
    $this
      ->loginAsAdmin([
      'access content overview',
      'administer tmgmt',
      'translate any entity',
      'edit any translatable_node content',
      $basic_html_format
        ->getPermissionName(),
      $restricted_html_format
        ->getPermissionName(),
      $full_html_format
        ->getPermissionName(),
    ]);
  }

  /**
   * Asserts translation jobs can be created.
   */
  public function testInstalled() {

    // Try and translate node 1.
    $this
      ->drupalGet('node');
    $this
      ->assertSession()
      ->pageTextContains('First node');
    $this
      ->assertSession()
      ->pageTextContains('Second node');
    $this
      ->assertSession()
      ->pageTextContains('TMGMT Demo');
    $this
      ->clickLink('First node');
    $this
      ->clickLink('Translate');
    $edit = [
      'languages[de]' => TRUE,
      'languages[fr]' => TRUE,
    ];
    $this
      ->submitForm($edit, 'Request translation');
    $this
      ->assertSession()
      ->pageTextContains('2 jobs need to be checked out.');

    // Try and translate node 2.
    $this
      ->drupalGet('admin/content');
    $this
      ->clickLink('Second node');
    $this
      ->clickLink('Translate');
    $this
      ->submitForm($edit, 'Request translation');
    $this
      ->assertSession()
      ->pageTextContains('2 jobs need to be checked out.');

    // Test local translator.
    $edit = [
      'translator' => 'local',
    ];
    $this
      ->submitForm($edit, 'Submit to provider and continue');
    $this
      ->assertSession()
      ->pageTextContains('The translation job has been submitted.');

    // Check to see if no items are selected and the error message pops up.
    $this
      ->drupalGet('admin/tmgmt/sources');
    $this
      ->submitForm([], 'Request translation');
    $this
      ->assertSession()
      ->pageTextContainsOnce("You didn't select any source items.");
    $this
      ->submitForm([], 'Search');
    $this
      ->assertSession()
      ->pageTextNotContains("You didn't select any source items.");
    $this
      ->submitForm([], 'Cancel');
    $this
      ->assertSession()
      ->pageTextNotContains("You didn't select any source items.");
    $this
      ->submitForm([], 'Add to cart');
    $this
      ->assertSession()
      ->pageTextContainsOnce("You didn't select any source items.");

    // Test if the formats are set properly.
    $this
      ->drupalGet('node/1/edit');
    $this
      ->assertTrue($this
      ->assertSession()
      ->optionExists('edit-body-0-format--2', 'basic_html')
      ->isSelected());
    $this
      ->drupalGet('node/2/edit');
    $this
      ->assertTrue($this
      ->assertSession()
      ->optionExists('edit-body-0-format--2', 'restricted_html')
      ->isSelected());
    $this
      ->drupalGet('node/3/edit');
    $this
      ->assertTrue($this
      ->assertSession()
      ->optionExists('edit-body-0-format--2', 'full_html')
      ->isSelected());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TMGMTDemoTest::$modules protected static property Modules to enable. Overrides TMGMTTestBase::$modules
TMGMTDemoTest::setUp public function Overrides DrupalWebTestCase::setUp() Overrides TMGMTTestBase::setUp
TMGMTDemoTest::testInstalled public function Asserts translation jobs can be created.
TMGMTTestBase::$defaultTheme protected property
TMGMTTestBase::$default_translator protected property A default translator using the test translator.
TmgmtTestTrait::$admin_permissions protected property List of permissions used by loginAsAdmin().
TmgmtTestTrait::$admin_user protected property Drupal user object created by loginAsAdmin().
TmgmtTestTrait::$languageWeight protected property The language weight for new languages.
TmgmtTestTrait::$translator_permissions protected property List of permissions used by loginAsTranslator().
TmgmtTestTrait::$translator_user protected property Drupal user object created by loginAsTranslator().
TmgmtTestTrait::addLanguage function Sets the proper environment.
TmgmtTestTrait::assertJobItemLangCodes function Asserts job item language codes.
TmgmtTestTrait::assertTextByXpath protected function Asserts text in the page with an xpath expression.
TmgmtTestTrait::clickLinkWithImageTitle function Clicks on an image link with the provided title attribute.
TmgmtTestTrait::createJob function Creates, saves and returns a translation job.
TmgmtTestTrait::createTranslator function Creates, saves and returns a translator.
TmgmtTestTrait::loginAsAdmin function Will create a user with admin permissions and log it in.
TmgmtTestTrait::loginAsTranslator function Will create a user with translator permissions and log it in.