diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index dc52cfa..3b0b30d 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -102,21 +102,6 @@ function custom_block_menu() { } /** - * Implements hook_local_actions(). - */ -function custom_block_local_actions() { - return array( - array( - 'route_name' => 'custom_block_type_add', - 'title' => t('Add custom block type'), - 'appears_on' => array( - 'custom_block_type_list', - ), - ), - ); -} - -/** * Implements hook_theme(). */ function custom_block_theme($existing, $type, $theme, $path) { diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockListController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockListController.php index 2d41fa4..8ff888a 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockListController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockListController.php @@ -7,7 +7,6 @@ namespace Drupal\custom_block; -use Drupal\Component\Utility\String; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityListController; @@ -48,4 +47,13 @@ public function getOperations(EntityInterface $entity) { return $operations; } + /** + * {@inheritdoc} + */ + public function render() { + // @todo Remove this once https://drupal.org/node/1981644 is in. + drupal_set_title(t('Custom blocks')); + return parent::render(); + } + } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Menu/LocalAction/CustomBlockAdd.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Menu/LocalAction/CustomBlockAdd.php new file mode 100644 index 0000000..cfd307f --- /dev/null +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Menu/LocalAction/CustomBlockAdd.php @@ -0,0 +1,24 @@ + 'Custom Block listing', + 'description' => 'Tests the listing of custom blocks.', + 'group' => 'Custom Block', + ); + } + + public function testListing() { + $this->drupalLogin($this->drupalCreateUser(array('administer blocks'))); + $this->drupalGet('admin/structure/custom-blocks'); + $this->clickLink(t('Blocks')); + + // Test for the page title. + $this->assertTitle('Custom blocks | Drupal'); + + // Test for the table. + $element = $this->xpath('//div[@class="l-content"]//table'); + $this->assertTrue($element, 'Configuration entity list table found.'); + + // Test the table header. + $elements = $this->xpath('//div[@class="l-content"]//table/thead/tr/th'); + $this->assertEqual(count($elements), 2, 'Correct number of table header cells found.'); + + // Test the contents of each th cell. + $expected_items = array('Label', 'Operations'); + foreach ($elements as $key => $element) { + $this->assertIdentical((string) $element[0], $expected_items[$key]); + } + + // Add a new entity using the operations link. + $this->assertLink('Add custom block'); + $this->clickLink('Add custom block'); + $this->assertResponse(200); + $edit = array(); + $langcode = Language::LANGCODE_NOT_SPECIFIED; + $edit['info'] = 'Antelope'; + $edit["block_body[$langcode][0][value]"] = $this->randomName(16); + $this->drupalPost(NULL, $edit, t('Save')); + + // Confirm that once the user returns to the listing, the text of the label + // (versus elsewhere on the page). + $this->drupalGet('admin/structure/custom-blocks/blocks'); + $this->assertFieldByXpath('//td', 'Antelope', "Label found for added block."); + + + // Check the number of table row cells. + $elements = $this->xpath('//div[@class="l-content"]//table/tbody/tr[@class="odd"]/td'); + $this->assertEqual(count($elements), 2, 'Correct number of table row cells found.'); + // Check the contents of each row cell. The first cell contains the label, + // the second contains the machine name, and the third contains the + // operations list. + $this->assertIdentical((string) $elements[0], 'Antelope'); + //$this->assertTrue($elements[1]->children()->xpath('//ul'), 'Operations list found.'); + + // Edit the entity using the operations link. + $this->assertLinkByHref('block/1'); + $this->clickLink('Edit'); + $this->assertResponse(200); + $this->assertTitle('Edit custom block Antelope | Drupal'); + $edit = array('info' => 'Albatross'); + $this->drupalPost(NULL, $edit, t('Save')); + + // Confirm that once the user returns to the listing, the text of the label + // (versus elsewhere on the page). + $this->drupalGet('admin/structure/custom-blocks/blocks'); + $this->assertFieldByXpath('//td', 'Albatross', "Label found for updated 'Albatross' entity."); + + // Delete the added entity using the operations link. + $this->assertLinkByHref('block/1/delete'); + $this->clickLink('Delete'); + $this->assertResponse(200); + $this->assertTitle('Are you sure you want to delete Albatross? | Drupal'); + $this->drupalPost(NULL, array(), t('Delete')); + $this->drupalGet('admin/structure/custom-blocks/blocks'); + + // Verify that the text of the label and machine name does not appear in + // the list (though it may appear elsewhere on the page). + $this->assertNoFieldByXpath('//td', 'Albatross', "No label found for deleted 'Albatross' entity."); + + // Confirm that the empty text is displayed. + $this->assertText('There is no Custom Block yet.'); + } + +}