View source
<?php
namespace Drupal\instagram_block\Tests;
use Drupal\Core\Extension\ThemeInstallerInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\simpletest\WebTestBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class InstagramBlockPlaceBlockTest extends WebTestBase implements ContainerInjectionInterface {
public static $modules = [
'instagram_block',
];
protected $blocks;
protected $adminUser;
protected $themeInstaller;
public function __construct(ThemeInstallerInterface $theme_installer) {
parent::__construct();
$this->themeInstaller = $theme_installer;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('theme_installer'));
}
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'administer instagram block',
'administer blocks',
'access administration pages',
]);
$this
->drupalLogin($this->adminUser);
}
public function testBlockAdminUiPage() {
$this
->drupalGet('admin/structure/block');
$element = $this
->xpath('//tr[contains(@class, :class1) and contains(@class, :class2)]', [
':class1' => 'region-header-message',
':class2' => 'region-empty',
]);
$this
->assertTrue(!empty($element));
$values = [
'plugin_id' => 'instagram_block_block',
'settings' => [
'region' => 'header',
'id' => 'instagramblock',
],
];
$this
->drupalPlaceBlock($values['plugin_id'], $values['settings']);
$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));
$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.');
$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.');
$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.');
$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.');
$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.');
}
public function testCoreThemeBlockList() {
try {
$this->themeInstaller
->install([
'bartik',
'seven',
'stark',
]);
} catch (\Exception $e) {
}
foreach ([
'bartik',
'seven',
'stark',
] as $theme) {
$this
->drupalGet("admin/structure/block/library/{$theme}");
$this
->assertText('Instagram block', "Instagram block found in {$theme} theme block selection.");
}
}
}