Comments

giancarlosotelo’s picture

Status: Active » Needs review
StatusFileSize
new5.28 KB

Added tests for every field for both entity types.

berdir’s picture

Status: Needs review » Needs work

Nice.

  1. +++ b/src/Tests/MonitoringUITest.php
    @@ -95,31 +95,41 @@ class MonitoringUITest extends MonitoringTestBase {
         // Test details page by clicking the link in confirmation message.
    -    $this->assertLink(t('UI created Sensor'));
    -    $this->clickLink(t('UI created Sensor'));
    +    $this->assertLink(t('Node Entity Aggregator sensor'));
    +    $this->clickLink(t('Node Entity Aggregator sensor'));
         $this->assertText('Result');
    

    We should assert some of the values that we are expecting there.

  2. +++ b/src/Tests/MonitoringUITest.php
    @@ -128,11 +138,51 @@ class MonitoringUITest extends MonitoringTestBase {
    +    // 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->assertText('Result');
    

    Same here.

giancarlosotelo’s picture

Status: Needs work » Needs review
StatusFileSize
new5.73 KB
new1.1 KB

Added some values to assert.

LKS90’s picture

Status: Needs review » Needs work
StatusFileSize
new30.13 KB

Take a look at the verbose output for the pages you test, there is no verbose output for the node sensor, but the test passes anyway. All the fields you assert aren't actually displayed, they are only listed as a setting in the Settings detail inset. I attached a screenshot of the verbose table which is empty.

giancarlosotelo’s picture

Status: Needs work » Needs review
StatusFileSize
new1.97 KB
new6.13 KB

Yeah, I didn't realize that, I added a node and also changed the assert type to assert the verbose output not the settings.

giancarlosotelo’s picture

I also added more asserts to the output.

LKS90’s picture

Status: Needs review » Needs work
+++ b/src/Tests/MonitoringUITest.php
@@ -128,11 +156,64 @@ class MonitoringUITest extends MonitoringTestBase {
+      $this->drupalPostForm(NULL, array('settings[entity_type]' => 'node'), t('Add another field'));
...
+    $this->assertLink($node->getTitle());
+    $this->assertLink($node->getOwner()->getUsername());
+    $this->assertText($node->uuid());
+    $this->assertText(\Drupal::service('date.formatter')->format($node->getCreatedTime(), 'short'));
+    $this->assertText($node->getChangedTime());

You are using the node for the file sensor? I'd expect you create a file, create the sensor and check the sensor output to match what the file has. At the moment the file sensor is just a copy of the node sensor with rather useless output (the output of a node, after all :P). Take a look at this test to see how to create a file in a test and do stuff with it.

giancarlosotelo’s picture

Now a file is created and the verbose output of the file entity is checked.

giancarlosotelo’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 8: add_test_coverage_verbose_fields-2542852-8.patch, failed testing.

The last submitted patch, 8: add_test_coverage_verbose_fields-2542852-8.patch, failed testing.

juanse254’s picture

+++ b/src/Tests/MonitoringUITest.php
@@ -91,36 +91,64 @@ class MonitoringUITest extends MonitoringTestBase {
+    $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 would recommend merging it into one single declaration, ex: array( 'key'=> 'value', 'key2'=> 'value'). Just the way it was before. will have a look about failing tests.

giancarlosotelo’s picture

Could be but a foreach is needed with the array.

foreach ($node_fields as $field) {
      $edit['settings[verbose_fields][' . $i++ . ']'] = $field->getName();
    }

so better to have the same format.

And about the test, are failing because of some recent changes in the Search API module, has nothing todo with this patch ;)

LKS90’s picture

And about the test, are failing because of some recent changes in the Search API module, has nothing todo with this patch ;)

The fails are because of a dependency on SearchAPI which was broken by a core update. The issue to fix SearchAPI: #2545464: Fix database backend after recent core change.

mbovan’s picture

  1. +++ b/src/Tests/MonitoringUITest.php
    @@ -91,36 +91,64 @@ class MonitoringUITest extends MonitoringTestBase {
    -    $this->assertLink(t('UI created Sensor'));
    -    $this->clickLink(t('UI created Sensor'));
    +    $this->assertLink(t('Node Entity Aggregator sensor'));
    +    $this->clickLink(t('Node Entity Aggregator sensor'));
    

    I see this is from before, but we don't need to assert link before clicking to it.

  2. +++ b/src/Tests/MonitoringUITest.php
    @@ -128,11 +156,83 @@ class MonitoringUITest extends MonitoringTestBase {
    +    $contents = "file_put_contents().";
    

    Looks a bit strange, but okay. :)

  3. +++ b/src/Tests/MonitoringUITest.php
    @@ -91,36 +91,64 @@ class MonitoringUITest extends MonitoringTestBase {
    +    $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'));
    
    @@ -128,11 +156,83 @@ class MonitoringUITest extends MonitoringTestBase {
    +    $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'));
    

    What about adding a helper method (e.g. addFields())?

  4. +++ b/src/Tests/MonitoringUITest.php
    @@ -128,11 +156,83 @@ class MonitoringUITest extends MonitoringTestBase {
    +    $this->assertTrue($file->id() > 0);
    

    Can we use $this->assertTrue($file->id())?

  5. +++ b/src/Tests/MonitoringUITest.php
    @@ -128,11 +156,83 @@ class MonitoringUITest extends MonitoringTestBase {
    +    $this->drupalGet('admin/config/system/monitoring/sensors/add');
    +
    +    // Test creation of File entity aggregator sensor.
    +    $this->drupalPostForm(NULL, array(
    

    Maybe to remove drupalGet() and add the path to drupalPostForm().

  6. +++ b/src/Tests/MonitoringUITest.php
    @@ -128,11 +156,83 @@ class MonitoringUITest extends MonitoringTestBase {
    +    $this->assertLink(t('File Entity Aggregator sensor'));
    +    $this->clickLink(t('File Entity Aggregator sensor'));
    

    Same as (1).

giancarlosotelo’s picture

Status: Needs work » Needs review
StatusFileSize
new4.46 KB
new6.96 KB

1. Done
2. Changed a bit.
3. Added a method.
4. Done.
5. Done.
6. Done

And also made the recommendation #13.

LKS90’s picture

Status: Needs review » Needs work
+++ b/src/Tests/MonitoringUITest.php
@@ -91,19 +91,24 @@ class MonitoringUITest extends MonitoringTestBase {
-

Revert unnecessary change

+++ b/src/Tests/MonitoringUITest.php
@@ -91,19 +91,24 @@ class MonitoringUITest extends MonitoringTestBase {
+    $this->drupalPostForm('admin/config/system/monitoring/sensors/add', array(

The path is not necessary, we already are on that page. Replace the path with NULL like it was before.

+++ b/src/Tests/MonitoringUITest.php
@@ -974,4 +1061,16 @@ class MonitoringUITest extends MonitoringTestBase {
+  /**
+   * Add verbose fields to the sensor creation form.
+   */
+  public function addFields($fields = array(), $array = array()) {

Missing documentation for both params, and while you are at it, the second parameter could really use a more helpful variable name (it's called $edit most of the time, IIRC)

After that it seems good to go. Adding fields isn't really that elegant, but it works for now.

giancarlosotelo’s picture

Status: Needs work » Needs review
StatusFileSize
new1.06 KB
new7.11 KB

1. Reverted.
2. Not possible, its necessary.
3. Added.

LKS90’s picture

Status: Needs review » Reviewed & tested by the community

Nice! Looks good now.

miro_dietiker’s picture

Hm, tests failed because testbot lost dependencies for monitoring again...

berdir’s picture

Yeah, but we also still have search api and captcha failing even with those. This is postponed on having passing tests again.

miro_dietiker’s picture

I have requested a new alpha release from search api. IMHO it would fix the search_api issue: #2552075: New alpha release
Dunno about the others and if we have issues RTBC / committed?

miro_dietiker’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/src/Tests/MonitoringUITest.php
@@ -112,15 +118,33 @@ class MonitoringUITest extends MonitoringTestBase {
+    $this->addFields($node_fields, $edit);

@@ -128,11 +152,75 @@ class MonitoringUITest extends MonitoringTestBase {
+    $this->addFields($file_fields, $edit);

I don't like this signature with eating a half prepared $edit and doing the PostForm on its own to NULL.
I would prefer to let it populate $edit with all fields. Name it addAllVerboseFields.

giancarlosotelo’s picture

Status: Needs work » Needs review
StatusFileSize
new1.68 KB
new7.29 KB

Ok now the function returns the $edit array with every field and then is saved.

miro_dietiker’s picture

Status: Needs review » Needs work

Oh sorry, i just realised that addAllVerboseFields still does and always did some posts on its own to add more items...
I think we should decouple it completely from the other $edit thingies and let it post again on its own.

How about providing some PostFormMultiple(t('Add another field'), 5) that then loop on the button 5 times.
Then adding the values to the $edit is a matter of the caller, followed by the regular Post.
Also, mind that you are using an API to fetch data about base fields. That's indirection. We know what base fields are existing. We can name them in code. You also name them when asserting.

giancarlosotelo’s picture

Status: Needs work » Needs review
StatusFileSize
new3.19 KB
new7.91 KB

Well, I decouple it, I added the postFormMultiple function and I also avoid the indirection adding the known fields manually.

I think now is less cryptic :)

miro_dietiker’s picture

Looks pretty good now!

Status: Needs review » Needs work

The last submitted patch, 27: add_test_coverage_verbose_fields-2542852-27.patch, failed testing.

miro_dietiker’s picture

Status: Needs work » Fixed

MonitoringUITest is passing. Rest is unrelated.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

The last submitted patch, 17: add_test_coverage_verbose_fields-2542852-17.patch, failed testing.

The last submitted patch, 19: add_test_coverage_verbose_fields-2542852-19.patch, failed testing.

The last submitted patch, 25: add_test_coverage_verbose_fields-2542852-25.patch, failed testing.

The last submitted patch, 17: add_test_coverage_verbose_fields-2542852-17.patch, failed testing.

The last submitted patch, 19: add_test_coverage_verbose_fields-2542852-19.patch, failed testing.

The last submitted patch, 25: add_test_coverage_verbose_fields-2542852-25.patch, failed testing.

Status: Closed (fixed) » Needs work

The last submitted patch, 27: add_test_coverage_verbose_fields-2542852-27.patch, failed testing.

giancarlosotelo’s picture

Status: Needs work » Closed (fixed)