MonitoringViewDisplayTest.php in Monitoring 8
File
tests/src/Functional/MonitoringViewDisplayTest.php
View source
<?php
namespace Drupal\Tests\monitoring\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\monitoring\Entity\SensorConfig;
class MonitoringViewDisplayTest extends MonitoringTestBase {
public static $modules = array(
'views',
'node',
);
public function testViewDisplaySensor() {
$account = $this
->drupalCreateUser(array(
'administer monitoring',
'monitoring reports',
));
$this
->drupalLogin($account);
$this
->drupalGet('admin/config/system/monitoring/sensors/add');
$this
->drupalPostForm(NULL, array(
'label' => 'All users',
'id' => 'view_user_count',
'plugin_id' => 'view_display_aggregator',
), t('Select sensor'));
$this
->assertText('Sensor plugin settings');
$this
->drupalPostForm(NULL, array(
'description' => 'Count all users through the users view.',
'value_label' => 'Users',
'caching_time' => 0,
'settings[view]' => 'user_admin_people',
), t('Select view'));
$this
->drupalPostForm(NULL, array(
'settings[display]' => 'default',
), t('Save'));
$this
->assertText(new FormattableMarkup('Sensor @label saved.', array(
'@label' => 'All users',
)));
$sensor_config = SensorConfig::load('view_user_count');
$this
->assertEqual($sensor_config
->getValueType(), 'number');
$this
->drupalGet('admin/config/system/monitoring/sensors/view_user_count');
$this
->assertOptionSelected('edit-settings-view', 'user_admin_people');
$this
->assertOptionSelected('edit-settings-display', 'default');
$result = $this
->runSensor('view_user_count');
$this
->assertTrue($result
->isOk());
$this
->assertEqual($result
->getMessage(), '2 users');
$this
->drupalCreateUser();
$result = $this
->runSensor('view_user_count');
$this
->assertTrue($result
->isOk());
$this
->assertEqual($result
->getMessage(), '3 users');
}
}