diff -u b/src/Tests/MonitoringUITest.php b/src/Tests/MonitoringUITest.php --- b/src/Tests/MonitoringUITest.php +++ b/src/Tests/MonitoringUITest.php @@ -99,7 +99,7 @@ $this->assertFieldByName('status', TRUE); // Test creation of Node entity aggregator sensor. - $this->drupalPostForm(NULL, array( + $this->drupalPostForm('admin/config/system/monitoring/sensors/add', array( 'label' => 'Node Entity Aggregator sensor', 'id' => 'ui_test_sensor', 'plugin_id' => 'entity_aggregator', @@ -108,30 +108,25 @@ $this->assertText('Sensor plugin settings'); $this->drupalPostForm(NULL, array('settings[entity_type]' => 'node'), t('Add another condition')); - // Get every available field for entity type node. - $node_fields = \Drupal::entityManager()->getBaseFieldDefinitions('node'); + $edit = array( + 'description' => 'Sensor created to test UI', + 'value_label' => 'Test Value', + 'caching_time' => 100, + 'settings[aggregation][time_interval_value]' => 86400, + 'settings[entity_type]' => 'node', + 'conditions[0][field]' => 'type', + 'conditions[0][value]' => 'article', + 'conditions[1][field]' => 'sticky', + 'conditions[1][value]' => 0, + ); - $edit = array(); - $edit['description'] = 'Sensor created to test UI'; - $edit['value_label'] = 'Test Value'; - $edit['caching_time'] = 100; - $edit['settings[aggregation][time_interval_value]'] = 86400; - $edit['settings[entity_type]'] = 'node'; - $edit['conditions[0][field]'] = 'type'; - $edit['conditions[0][value]'] = 'article'; - $edit['conditions[1][field]'] = 'sticky'; - $edit['conditions[1][value]'] = '0'; - $i = 2; - foreach ($node_fields as $field) { - $this->drupalPostForm(NULL, array(), t('Add another field')); - $edit['settings[verbose_fields][' . $i++ . ']'] = $field->getName(); - } - $this->drupalPostForm(NULL, $edit, t('Save')); + // Get every available field for the entity type node. + $node_fields = \Drupal::entityManager()->getBaseFieldDefinitions('node'); + $this->addFields($node_fields, $edit); $this->assertText(SafeMarkup::format('Sensor @label saved.', array('@label' => 'Node Entity Aggregator sensor'))); // Test details page by clicking the link in confirmation message. - $this->assertLink(t('Node Entity Aggregator sensor')); $this->clickLink(t('Node Entity Aggregator sensor')); $this->assertResponse(200); $this->assertText('Result'); @@ -163,7 +158,7 @@ // Create a file to test. $file_path = file_default_scheme() . '://test'; - $contents = "file_put_contents()."; + $contents = "some content here!!."; file_put_contents($file_path, $contents); // Test if the file exist. @@ -177,12 +172,10 @@ $file->save(); // Test if the entity was created. - $this->assertTrue($file->id() > 0); - - $this->drupalGet('admin/config/system/monitoring/sensors/add'); + $this->assertTrue($file->id()); // Test creation of File entity aggregator sensor. - $this->drupalPostForm(NULL, array( + $this->drupalPostForm('admin/config/system/monitoring/sensors/add', array( 'label' => 'File Entity Aggregator sensor', 'id' => 'file_test_sensor', 'plugin_id' => 'entity_aggregator', @@ -195,17 +188,11 @@ $file_fields = \Drupal::entityManager()->getBaseFieldDefinitions('file'); $edit = array(); - $i = 2; - foreach ($file_fields as $field) { - $this->drupalPostForm(NULL, array(), t('Add another field')); - $edit['settings[verbose_fields][' . $i++ . ']'] = $field->getName(); - } - $this->drupalPostForm(NULL, $edit, t('Save')); + $this->addFields($file_fields, $edit); $this->assertText(SafeMarkup::format('Sensor @label saved.', array('@label' => 'File Entity Aggregator sensor'))); // Test details page by clicking the link in confirmation message. - $this->assertLink(t('File Entity Aggregator sensor')); $this->clickLink(t('File Entity Aggregator sensor')); $this->assertResponse(200); $this->assertText('Result'); @@ -1076,2 +1063,14 @@ + /** + * Add verbose fields to the sensor creation form. + */ + public function addFields($fields = array(), $array = array()) { + $i = 2; + foreach ($fields as $field) { + $this->drupalPostForm(NULL, array(), t('Add another field')); + $array['settings[verbose_fields][' . $i++ . ']'] = $field->getName(); + } + $this->drupalPostForm(NULL, $array, t('Save')); + } + }