8ec17e238165c6dec7a6a585dcf2ace7bfd234c5
[yaffs-website] / web / core / modules / block_content / src / Tests / Views / BlockContentIntegrationTest.php
1 <?php
2
3 namespace Drupal\block_content\Tests\Views;
4
5 /**
6  * Tests the block_content integration into views.
7  *
8  * @group block_content
9  */
10 class BlockContentIntegrationTest extends BlockContentTestBase {
11
12   /**
13    * Views used by this test.
14    *
15    * @var array
16    */
17   public static $testViews = ['test_block_content_view'];
18
19   /**
20    * Tests basic block_content view with a block_content_type argument.
21    */
22   public function testBlockContentViewTypeArgument() {
23     // Create two content types with three block_contents each.
24     $types = [];
25     $all_ids = [];
26     $block_contents = [];
27     for ($i = 0; $i < 2; $i++) {
28       $type = $this->createBlockContentType();
29       $types[] = $type;
30
31       for ($j = 0; $j < 5; $j++) {
32         // Ensure the right order of the block_contents.
33         $block_content = $this->createBlockContent(['type' => $type->id()]);
34         $block_contents[$type->id()][$block_content->id()] = $block_content;
35         $all_ids[] = $block_content->id();
36       }
37     }
38
39     $this->drupalGet('test-block_content-view');
40     $this->assertResponse(404);
41
42     $this->drupalGet('test-block_content-view/all');
43     $this->assertResponse(200);
44     $this->assertIds($all_ids);
45     /* @var \Drupal\block_content\Entity\BlockContentType[] $types*/
46     foreach ($types as $type) {
47       $this->drupalGet("test-block_content-view/{$type->id()}");
48       $this->assertIds(array_keys($block_contents[$type->id()]));
49     }
50   }
51
52   /**
53    * Ensures that a list of block_contents appear on the page.
54    *
55    * @param array $expected_ids
56    *   An array of block_content IDs.
57    */
58   protected function assertIds(array $expected_ids = []) {
59     $result = $this->xpath('//span[@class="field-content"]');
60     $ids = [];
61     foreach ($result as $element) {
62       $ids[] = (int) $element;
63     }
64     $this->assertEqual($ids, $expected_ids);
65   }
66
67 }