You are here

public function GroupTest::testGroupFieldVisibility in farmOS 2.x

Test group field visibility.

File

modules/asset/group/tests/src/Functional/GroupTest.php, line 48

Class

GroupTest
Tests for farmOS group membership logic.

Namespace

Drupal\Tests\farm_group\Functional

Code

public function testGroupFieldVisibility() {

  // Create a log for testing.

  /** @var \Drupal\log\Entity\LogInterface $log */
  $log = Log::create([
    'type' => 'test',
  ]);
  $log
    ->save();

  // Go to the log edit form.
  $this
    ->drupalGet('log/' . $log
    ->id() . '/edit');

  // Test that the group field is hidden.
  $page = $this
    ->getSession()
    ->getPage();
  $group_field = $page
    ->findById('edit-group-wrapper');
  $this
    ->assertNotEmpty($group_field);
  $this
    ->assertFalse($group_field
    ->isVisible());

  // Make the log a group assignment.
  $log->is_group_assignment = TRUE;
  $log
    ->save();

  // Go back to the edit form.
  $this
    ->drupalGet('log/' . $log
    ->id() . '/edit');

  // Test that the group field is visible.
  $page = $this
    ->getSession()
    ->getPage();
  $group_field = $page
    ->findById('edit-group-wrapper');
  $this
    ->assertNotEmpty($group_field);
  $this
    ->assertTrue($group_field
    ->isVisible());
}