Comments

lucassc created an issue. See original summary.

lucassc’s picture

Title: Add unit test for ModalPageService » Add unit test for Modal Page Service
lucassc’s picture

Status: Active » Needs work
StatusFileSize
new4.6 KB

Hi!

I started to write something. I'm still working on this but any tips/contributions are welcome as it's my first unit test.

I got help from @diegors and @gquisini, if you can please give credits.

lucassc’s picture

StatusFileSize
new6.62 KB
new6.4 KB
  • added variable doc comments;
  • changed mocks creation to build it with the general best-practice defaults instead of create with my own requirements;
  • fixed testIfModalHasNoType doc comments;
  • created method to tests getCurrentPath().
gquisini’s picture

StatusFileSize
new10.3 KB
new4.67 KB

What we did:

  • Added two tests to verifyUserHasPermissionOnModal()
  • Added test to loadModalsToShow()
gquisini’s picture

StatusFileSize
new12.83 KB
new4.12 KB

Hello, so...
I created some new tests to:
- loadModalsToShow()
- getModalToShowByPage()
- prepareClass()

lucassc’s picture

StatusFileSize
new60.11 KB

Hi!

We couldn't set up a modal by parameters so we don't write tests for this now. Here's what we did:

  • we edit the welcome modal that comes by default changing the extra config to use modal by parameter instead of page;
  • fill the "Delay to display" field with 0;
  • fill the "Parameters" textarea with /?modal=welcome as suggested in the field's description.

See modal-by-parameter-settings.png attached.

Maybe a bug here?

I checkout the Modal Settings documentation and didn't find any references to "parameter". Maybe can we create an issue to add this later?

With that, the methods left to test/discuss if it's worth testing are:

  • getModalToShowByParameter
  • verifyModalShouldAppearOnThisLanguage
  • clearText
  • verifyModalShouldAppearOnThisPath
  • getAllowTags
  • importModalConfigToEntity
  • extractFilesUuid
  • recordFileUsage
renatog’s picture

Awesome job! Thanks a lot for your contribution on this

We couldn't set up a modal by parameters so we don't write tests for this now.

Maybe a bug here?

I checkout the Modal Settings documentation and didn't find any references to "parameter". Maybe can we create an issue to add this later?

Actually I'm thinking about to deprecate this option to "Modal by parameter". We can think in a way to remove this functionality in the future

I kept this only because I don't know if we have sites in production using this. But I think we don't need to create tests for this functionality

lucassc’s picture

StatusFileSize
new12.84 KB
new1.12 KB

Ok, @RenatoG!
Thanks for the quick response!

submitting new patch:

  • removed experimental test for getModalToShowByParameter;
  • added test to verifyModalShouldAppearOnThisLanguage() method without languages to show.
lucassc’s picture

Assigned: lucassc » Unassigned
Status: Needs work » Needs review

Changing status to "needs review" because we're starting to feel stuck.

This is our first unit test, so we may have made some mistakes. Feel free to suggest modifications and improvements, we'll be willing to fix them out.

Kindly review.

gquisini’s picture

StatusFileSize
new12.79 KB
new5.38 KB

There is nothing new in this patch, I just put the tests in order.

paulocs’s picture

Status: Needs review » Needs work

Found some CS erros:

FILE: drupal-composer-install/web/modules/contrib/modal_page/tests/src/Unit/ModalPageServiceTest.php

FOUND 1 ERROR AFFECTING 1 LINE

 360 | ERROR | [x] Expected 1 blank line after function; 2 found
lucassc’s picture

Status: Needs work » Needs review
StatusFileSize
new12.79 KB
new378 bytes

Fixed! Thanks.

sophiavs’s picture

Assigned: Unassigned » sophiavs

I'll do the review

sophiavs’s picture

Assigned: sophiavs » Unassigned
Status: Needs review » Needs work

While reviewing i didn't found any coding standard error and the tests seems to be fine.

I think we could add a new test for the loadModalsToShow(), testing multiple modals with different attributes to check the quantity of modals to show.
ex: 4 modals with null type, 2 modals with page type, 1 modal unpublished...
And maybe the getModalToShowByPage() in a modal with multiple pages to test
ex: front and /node/1 added on the same modal

lucassc’s picture

Assigned: Unassigned » lucassc

Hi!

Thanks for the review, @sophiavs! I'll work on this.

lucassc’s picture

StatusFileSize
new15.69 KB
new3.25 KB

Added method to test loadModalsToShow() with multiple modals having different attributes.

lucassc’s picture

StatusFileSize
new16.17 KB
new1.36 KB

I found out a bug in testGetModalsToShowWithoutModals(). The mock was not made correctly, so the modals used to build the object came actually from setUp() - which had created 1 modal. As it was not defined in setUp() if the modal was published, getModalsToShow() returned FALSE anyway.

Fixed!

I took the opportunity to add a forgotten $this-> in the previous method.

After I finish @sophiavs suggestions, I'll debug all tests and double check if they're really working as they should.

lucassc’s picture

StatusFileSize
new16.59 KB
new771 bytes

Added method to test getModalToShowByPage() with multiple pages.

lucassc’s picture

Assigned: lucassc » Unassigned
Status: Needs work » Needs review
StatusFileSize
new16.82 KB
new2.9 KB

In this patch I:
- replaced assertTrue with assertEquals where it's more suitable;
- broke lines to be no longer than 80 characters, whenever possible, to follow the coding standards.

lucassc’s picture

Assigned: Unassigned » lucassc
Status: Needs review » Needs work

Addressed #18:

After I finish @sophiavs suggestions, I'll debug all tests and double check if they're really working as they should.

I debugged the real behavior of getModalToShowByPage method setting the modal with multiple pages from site. With this, I verified that testShowByPageWithMultiplePages was not correct. It's a void function in this case, we have to assert this.

I also checked that testIfUserHasPermissionOnModal is returning FALSE before getRoles is called. Futhermore it's duplicated with testIfUserHasPermissionOnModalWithPermissions. Must be deleted.

I'm working on it.

lucassc’s picture

StatusFileSize
new16.75 KB
new1.73 KB

Patch addressed #21.

lucassc’s picture

Assigned: lucassc » Unassigned
Status: Needs work » Needs review
lucassc’s picture

sophiavs’s picture

Assigned: Unassigned » sophiavs

I'll do the review :)

lucassc’s picture

StatusFileSize
new16.76 KB
new1.12 KB

@sophiavs warned me about another bug, since testShowByPageSetToNode is checking if the modal is displayed for /node/1, its current path must also be node/1.

Thank you, @sophiavs! Attaching new patch to fix this.

sophiavs’s picture

Assigned: sophiavs » Unassigned
Status: Needs review » Reviewed & tested by the community

Everything seems to be right know, passing to RTBC :)

  • 4bcf63a committed on 4.1.x
    Issue #3305168 by lucassc, gquisini: Add unit test for Modal Page...
paulocs’s picture

Status: Reviewed & tested by the community » Fixed

Thanks!

paulocs’s picture

Status: Fixed » Closed (fixed)

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