outline-8.x-1.x-dev/tests/src/Functional/OutlineEntryIndentationTest.php

tests/src/Functional/OutlineEntryIndentationTest.php
<?php

namespace Drupal\Tests\outline\Functional;

/**
 * Ensure that the entry indentation works properly.
 *
 * @group outline
 */
class OutlineEntryIndentationTest extends OutlineTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  protected static $modules = ['outline'];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * Outline for testing.
   *
   * @var \Drupal\outline\OutlineInterface
   */
  protected $outline;

  protected function setUp(): void {
    parent::setUp();
    $this->drupalLogin($this->drupalCreateUser([
      'administer outline',
      'bypass node access',
    ]));
    $this->outline = $this->createOutline();
  }

  /**
   * Tests entry indentation.
   */
  public function testEntryIndentation() {
    $assert = $this->assertSession();
    // Create three outline entries.
    $entry1 = $this->createEntry($this->outline);
    $entry2 = $this->createEntry($this->outline);
    $entry3 = $this->createEntry($this->outline);

    // Get the outline storage.
    $outline_storage = $this->container->get('entity_type.manager')->getStorage('outline_entry');

    // Indent the second entry under the first one.
    $this->drupalGet('admin/structure/outline/manage/' . $this->outline->get('oid') . '/overview');
    $hidden_edit = [
      'entries[tid:' . $entry2->id() . ':0][entry][tid]' => 2,
      'entries[tid:' . $entry2->id() . ':0][entry][parent]' => 1,
      'entries[tid:' . $entry2->id() . ':0][entry][depth]' => 1,
    ];
    // Because we can't post hidden form elements, we have to change them in
    // code here, and then submit.
    foreach ($hidden_edit as $field => $value) {
      $node = $assert->hiddenFieldExists($field);
      $node->setValue($value);
    }
    $edit = [
      'entries[tid:' . $entry2->id() . ':0][weight]' => 1,
    ];
    // Submit the edited form and check for HTML indentation element presence.
    $this->drupalPostForm(NULL, $edit, t('Save'));
    $this->assertPattern('|<div class="js-indentation indentation">&nbsp;</div>|');

    // Check explicitly that entry 2's parent is entry 1.
    $parents = $outline_storage->loadParents($entry2->id());
    $this->assertEqual(key($parents), 1, 'Entry 1 is the entry 2\'s parent');

    // Move the second entry back out to the root level.
    $this->drupalGet('admin/structure/outline/manage/' . $this->outline->get('oid') . '/overview');
    $hidden_edit = [
      'entries[tid:' . $entry2->id() . ':0][entry][tid]' => 2,
      'entries[tid:' . $entry2->id() . ':0][entry][parent]' => 0,
      'entries[tid:' . $entry2->id() . ':0][entry][depth]' => 0,
    ];
    // Because we can't post hidden form elements, we have to change them in
    // code here, and then submit.
    foreach ($hidden_edit as $field => $value) {
      $node = $assert->hiddenFieldExists($field);
      $node->setValue($value);
    }
    $edit = [
      'entries[tid:' . $entry2->id() . ':0][weight]' => 1,
    ];
    $this->drupalPostForm(NULL, $edit, t('Save'));
    // All entries back at the root level, no indentation should be present.
    $this->assertSession()->responseNotMatches('|<div class="js-indentation indentation">&nbsp;</div>|');

    // Check explicitly that entry 2 has no parents.
    \Drupal::entityTypeManager()->getStorage('outline_entry')->resetCache();
    $parents = $outline_storage->loadParents($entry2->id());
    $this->assertTrue(empty($parents), 'Entry 2 has no parents now');
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc