Same name in this branch
  1. 10 core/modules/rest/tests/src/Functional/Views/FieldCounterTest.php \Drupal\Tests\rest\Functional\Views\FieldCounterTest
  2. 10 core/modules/views/tests/src/Kernel/Handler/FieldCounterTest.php \Drupal\Tests\views\Kernel\Handler\FieldCounterTest
Same name and namespace in other branches
  1. 8.9.x core/modules/rest/tests/src/Functional/Views/FieldCounterTest.php \Drupal\Tests\rest\Functional\Views\FieldCounterTest
  2. 9 core/modules/rest/tests/src/Functional/Views/FieldCounterTest.php \Drupal\Tests\rest\Functional\Views\FieldCounterTest

Tests the display of counter field.

@group rest

Hierarchy

Expanded class hierarchy of FieldCounterTest

See also

\Drupal\rest\Plugin\views\display\RestExport

\Drupal\rest\Plugin\views\row\DataFieldRow

File

core/modules/rest/tests/src/Functional/Views/FieldCounterTest.php, line 18

Namespace

Drupal\Tests\rest\Functional\Views
View source
class FieldCounterTest extends ViewTestBase {

  /**
   * @var \Drupal\views\ViewExecutable
   */
  protected $view;

  /**
   * The views that are used by this test.
   *
   * @var array
   */
  public static $testViews = [
    'test_field_counter_display',
  ];

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

  /**
   * The modules that need to be installed for this test.
   *
   * @var array
   */
  protected static $modules = [
    'entity_test',
    'rest_test_views',
    'node',
    'field',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp($import_test_views = TRUE, $modules = [
    'rest_test_views',
  ]) : void {
    parent::setUp($import_test_views, $modules);

    // Create some test content.
    for ($i = 1; $i <= 10; $i++) {
      Node::create([
        'type' => 'article',
        'title' => 'Article test ' . $i,
      ])
        ->save();
    }
    $this
      ->enableViewsTestModule();
    $this->view = Views::getView('test_field_counter_display');
    $this->view
      ->setDisplay('rest_export_1');
  }

  /**
   * Tests the display of an excluded title field when used as a token.
   */
  public function testExcludedTitleTokenDisplay() {
    $actual_json = $this
      ->drupalGet($this->view
      ->getPath(), [
      'query' => [
        '_format' => 'json',
      ],
    ]);
    $this
      ->assertSession()
      ->statusCodeEquals(200);
    $expected = [
      [
        'counter' => '1',
      ],
      [
        'counter' => '2',
      ],
      [
        'counter' => '3',
      ],
      [
        'counter' => '4',
      ],
      [
        'counter' => '5',
      ],
      [
        'counter' => '6',
      ],
      [
        'counter' => '7',
      ],
      [
        'counter' => '8',
      ],
      [
        'counter' => '9',
      ],
      [
        'counter' => '10',
      ],
    ];
    $this
      ->assertSame(json_encode($expected), $actual_json);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FieldCounterTest::$defaultTheme protected property
FieldCounterTest::$modules protected static property The modules that need to be installed for this test. Overrides ViewTestBase::$modules
FieldCounterTest::$testViews public static property The views that are used by this test.
FieldCounterTest::$view protected property
FieldCounterTest::setUp protected function Sets up the test. Overrides ViewTestBase::setUp
FieldCounterTest::testExcludedTitleTokenDisplay public function Tests the display of an excluded title field when used as a token.
ViewResultAssertionTrait::assertIdenticalResultset protected function Verifies that a result set returned by a View matches expected values.
ViewResultAssertionTrait::assertIdenticalResultsetHelper protected function Performs View result assertions.
ViewResultAssertionTrait::assertNotIdenticalResultset protected function Verifies that a result set returned by a View differs from certain values.
ViewTestBase::dataSet protected function Returns a very simple test dataset. 1
ViewTestBase::enableViewsTestModule protected function Sets up the views_test_data.module.
ViewTestBase::executeView protected function Executes a view.
ViewTestBase::helperButtonHasLabel protected function Asserts the existence of a button with a certain ID and label.
ViewTestBase::orderResultSet protected function Orders a nested array containing a result set based on a given column.
ViewTestBase::schemaDefinition protected function Returns the schema definition. 1
ViewTestBase::viewsData protected function Returns the views data definition. 8