diff -u b/modules/ctools_block/src/Tests/EntityFieldBlockTest.php b/modules/ctools_block/src/Tests/EntityFieldBlockTest.php --- b/modules/ctools_block/src/Tests/EntityFieldBlockTest.php +++ b/modules/ctools_block/src/Tests/EntityFieldBlockTest.php @@ -7,7 +7,7 @@ namespace Drupal\ctools_block\Tests; - +use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\simpletest\WebTestBase; /** @@ -20,32 +20,83 @@ + /** + * @todo Allow strict config schema once we figure out how to make it work + * without hurling exceptions at us. + */ + protected $strictConfigSchema = false; + + /** + * {@inheritdoc} + */ public static $modules = array('ctools_block', 'ctools_block_field_test'); - // Note: right now placing the body field appears to be broken :-( - function testBodyField() { - // @todo: place 'entity_field:node:body' block - // @todo: create a 'ctools_block_field_test' node - // @todo: visit the /node/XX page and verify it's displayed correctly - $this->assertTrue(FALSE); + public function testBodyField() { + $block = $this->drupalPlaceBlock('entity_field:node:body', [ + 'formatter' => [ + 'type' => 'text_default', + ], + 'context_mapping' => [ + 'entity' => '@node.node_route_context:node', + ], + ]); + $node = $this->drupalCreateNode(['type' => 'ctools_block_field_test']); + $this->drupalGet('node/' . $node->id()); + $this->assertText($block->label()); } function testImageField() { - // @todo: place 'entity_field:node:field_ctools_block_image' block - // @todo: create a 'ctools_block_field_test' node - // @todo: visit the /node/XX page and verify it's displayed correctly - $this->assertTrue(FALSE); + $block = $this->drupalPlaceBlock('entity_field:node:field_ctools_block_image', [ + 'formatter' => [ + 'type' => 'image', + ], + 'context_mapping' => [ + 'entity' => '@node.node_route_context:node', + ], + ]); + $node = $this->drupalCreateNode(['type' => 'ctools_block_field_test']); + $this->drupalGet('node/' . $node->id()); + $this->assertText($block->label()); } function testNodeBaseFields() { - // @todo: place some node base fields, etc - $this->assertTrue(FALSE); + $block = $this->drupalPlaceBlock('entity_field:node:uid', [ + 'formatter' => [ + 'type' => 'entity', + ], + 'context_mapping' => [ + 'entity' => '@node.node_route_context:node', + ], + ]); + $node = $this->drupalCreateNode(['type' => 'ctools_block_field_test']); + $this->drupalGet('node/' . $node->id()); + $this->assertText($block->label()); } function testRenderCache() { - // @todo: place one of the field blocks - // @todo: Create two 'ctools_block_field_test' nodes - // @todo: visit one and then then other - make sure the data changes - // @todo: edit one of the nodes - make sure the data changes - $this->assertTrue(FALSE); + /** @var \Drupal\Core\Entity\Entity\EntityViewDisplay $view */ + EntityViewDisplay::load('node.ctools_block_field_test.default') + ->removeComponent('body') + ->save(); + + $this->drupalPlaceBlock('entity_field:node:body', [ + 'formatter' => [ + 'type' => 'text_default', + ], + 'context_mapping' => [ + 'entity' => '@node.node_route_context:node', + ], + ]); + $a = $this->drupalCreateNode(['type' => 'ctools_block_field_test']); + $b = $this->drupalCreateNode(['type' => 'ctools_block_field_test']); + + $this->drupalGet('node/' . $a->id()); + $this->assertText($a->body->value); + $this->drupalGet('node/' . $b->id()); + $this->assertText($b->body->value); + + $text = 'This is my text. Are you not entertained?'; + $a->body->value = $text; + $a->save(); + $this->drupalGet('node/' . $a->id()); + $this->assertText($text); } } -