public function InstagramBlockPlaceBlockTest::testBlockAdminUiPage in Instagram Block 8.2
Same name and namespace in other branches
- 8.3 src/Tests/InstagramBlockPlaceBlockTest.php \Drupal\instagram_block\Tests\InstagramBlockPlaceBlockTest::testBlockAdminUiPage()
Test block admin page exists and functions correctly.
File
- src/
Tests/ InstagramBlockPlaceBlockTest.php, line 82
Class
- InstagramBlockPlaceBlockTest
- Test the placing of Instagram block blocks.
Namespace
Drupal\instagram_block\TestsCode
public function testBlockAdminUiPage() {
// Visit the blocks admin ui.
$this
->drupalGet('admin/structure/block');
// Check that there are no blocks in the header region.
$element = $this
->xpath('//tr[contains(@class, :class1) and contains(@class, :class2)]', [
':class1' => 'region-header-message',
':class2' => 'region-empty',
]);
$this
->assertTrue(!empty($element));
// Place an instagram block in the header region.
$values = [
'plugin_id' => 'instagram_block_block',
'settings' => [
'region' => 'header',
'id' => 'instagramblock',
],
];
$this
->drupalPlaceBlock($values['plugin_id'], $values['settings']);
// Check that the block was placed successfully.
$this
->drupalGet('admin/structure/block');
$element = $this
->xpath('//tr[contains(@class, :class1) and contains(@class, :class2)]', [
':class1' => 'region-header-message',
':class2' => 'region-populated',
]);
$this
->assertTrue(!empty($element));
// Test context mapping with valid data.
$this
->drupalGet('admin/structure/block/manage/instagramblock');
$edit = [
'settings[access_token]' => '412345678.123ab45.cde678fg901h234ij567klm89nop0123',
'settings[count]' => '4',
'settings[width]' => '150',
'settings[height]' => '150',
'settings[img_resolution]' => 'thumbnail',
'settings[cache_time_minutes]' => '1440',
];
$this
->drupalPostForm(NULL, $edit, 'Save block');
$this
->assertText('The block configuration has been saved.', 'Block save without errors.');
// @todo Test access_token validation.
// Test count with invalid data.
$edit = [
'settings[count]' => $this
->randomString(4),
];
$this
->drupalPostForm('admin/structure/block/manage/instagramblock', $edit, 'Save block');
$this
->assertText('Number of images to display must be a number.', 'Block failed to save.');
// Test width with invalid data.
$edit = [
'settings[width]' => $this
->randomString(4),
];
$this
->drupalPostForm('admin/structure/block/manage/instagramblock', $edit, 'Save block');
$this
->assertText('Image width in pixels must be a number.', 'Block failed to save.');
// Test height with invalid data.
$edit = [
'settings[height]' => $this
->randomString(4),
];
$this
->drupalPostForm('admin/structure/block/manage/instagramblock', $edit, 'Save block');
$this
->assertText('Image height in pixels must be a number.', 'Block failed to save.');
// Test cache_time_minutes with invalid data.
$edit = [
'settings[cache_time_minutes]' => $this
->randomString(4),
];
$this
->drupalPostForm('admin/structure/block/manage/instagramblock', $edit, 'Save block');
$this
->assertText('Cache time in minutes must be a number.', 'Block failed to save.');
}