To prepare protected node for refactoring, and to avoid regression, we need to implement tests.

A first step of tests I see are:

Feel free to contribute your tests.

CommentFileSizeAuthor
#86 protected_node-debug_test-2277045-86.patch1.86 KBgrimreaper
#82 protected_node-add_test_private_file_multiple_node-2277045-82.patch3.98 KBgrimreaper
#79 protected_node-add_test_protect_nodes-2277045-79.patch2.01 KBgrimreaper
#75 protected_node-add_test_reset_passwords-2277045-75.patch2.4 KBgrimreaper
#72 protected_node-add_test_global_password-2277045-72.patch5.11 KBgrimreaper
#67 protected_node-add_test_restore_protection-2277045-67.patch4.16 KBgrimreaper
#66 protected_node-add_test_remove_protection-2277045-66.patch2.03 KBgrimreaper
#61 protected_node-test_clear_sessions-2277045-61.patch4.05 KBgrimreaper
#56 protected_node-add_tests_on_statistics-2277075-56.patch7.27 KBgrimreaper
#40 protected_node-test_styling-2277045-40.patch4.84 KBizus
#31 implement_tests_for-2277045-31-type.patch6.96 KBgrimreaper
#31 implement_tests_for-2277045-31-emails.patch3.38 KBgrimreaper
#31 implement_tests_for-2277045-31.patch9.72 KBgrimreaper
#27 implement_tests_for-2277045-27.patch9.58 KBgrimreaper
#26 implement_tests_for-2277045-26.patch6.81 KBgrimreaper
#17 test_node_password-2277045-17.patch8.06 KBgrimreaper
#15 test_node_password-2277045-15.patch8.08 KBgrimreaper
#13 test_node_password-2277045-13.patch8.1 KBgrimreaper
#12 test_node_password-2277045-12.patch7.44 KBizus
#11 test_node_password-2277045-11.patch7.44 KBizus
#10 test_node_password-2277045-10.patch6.78 KBizus
#9 test_node_password-2277045-9.patch5.53 KBgrimreaper
#8 test_node_password-2277045-8.patch5.15 KBgrimreaper
#4 tests-2277045.patch11.78 KBgrimreaper
#1 global_password_view-2277045.patch3.6 KBgrimreaper

Comments

grimreaper’s picture

StatusFileSize
new3.6 KB
grimreaper’s picture

Issue summary: View changes
Status: Active » Needs review
grimreaper’s picture

Issue summary: View changes
grimreaper’s picture

Issue summary: View changes
StatusFileSize
new11.78 KB

With global password, the view of the node fail. It is "normal", it is related to this issue https://drupal.org/node/2266507

I lost a lot of time in these tests because at the beginning I used :


// Create a protected node.
    $settings = array(
      'protected_node_is_protected' => TRUE,
      'protected_node_show_title'   => TRUE, // To be removed here to follow the test.
      'protected_node_emails'       => '',    // To be removed here to follow the test.
    );
    $node = $this->drupalCreateNode($settings);

To create node. But the protected node module stored nothing and I realised that when I wrote the tests for per node password. I was fooled because the assertText was on the nodes' title and its were shown even on the password form even when it fails.

So now I use the node's body.

I also lost a lot of time before founding that :


'protected_node_use_global_password'          => array(PROTECTED_NODE_GLOBAL_PASSWORD),

To set the password method was not good. No need of an array.

Now It should be good for those basic tests.

I wait your feedbacks.

Thanks for the review.

izus’s picture

ok
a quick look to the patch and here are my thoughts :
let's do it step by step :

let's focus first on :
password per node :

Creation (storage of the password) needs review
View needs review

only that until it got merged, then we go ahead.
i'd like us to work on that patch first as it's the first test we will have.

the users created for a test case should really have the minimum permissions that are needed.

if during test writing we need to fix a bug, let's do that first and even commit the test with the bug issue. tests should keep clean state of the project (well clean may not be the exact word for now, but let it be a target ;))

izus’s picture

also it would be more readable to use a single test file for each test category (edit or even each class)

grimreaper’s picture

For the tests in each file. I forgot to mention that I also want that, but I don't know the proper way to make that.

Ok, let's focus on password per node. While my first patch is not lost it's ok. :)

I will see that this weekend.

grimreaper’s picture

StatusFileSize
new5.15 KB

This patch only tests password per node. Creation and view.

The tests are in their own file.

grimreaper’s picture

StatusFileSize
new5.53 KB

I remade the previous patch to respect some coding style standards of POO and comments.

izus’s picture

StatusFileSize
new6.78 KB

hi,
here is a reworked version based on #9
- added a user with only access content permission
- added a test for that user
- handeld all the tests for "by node protection" in one single class
- added extra method for common used code to avoid duplication
- delete unneded global string definition
- made the test nodes load by title instead of by id, as the id may differ in the future.
- Added a test for user with permissions but wrong password

tests pass but simpletest complains about
Undefined property: stdClass::$protected_node_emails Notice protected_node.module 865 _protected_node_save()
i think we should fix this.

so Todos here :
- fix the Notice issue
- Review the patch and if needed complete it

izus’s picture

StatusFileSize
new7.44 KB

fixed the the notice in #10
all green now :)
will just need a review and maybe feed up the patch with extra cases if necessary.

izus’s picture

StatusFileSize
new7.44 KB

testing if automated tests will be triggered

grimreaper’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new8.1 KB

Your version is much clearer. :)

I just had messages on the asserts to locate them easily among the debug messages.

Now I understand better how you wanted the tests to be organized.

About the notice, I already have it in the patch at #2266507-2: Global password does not work properly

If it's ok, I will wait the first test to be merged. Then I will rebase #2266507-2: Global password does not work properly and write the other tests in this issue.

izus’s picture

i think the $group thing needs a decision before we go far on all the other tests.
https://api.drupal.org/api/drupal/modules!simpletest!drupal_web_test_cas...
actually the $group added in #13 seems more like a short version of $message, but this is not the intention of $group.
i still think that it can be sth that is good to have if we use a defined set of groups needed in this module, but it should be general and not specific to a test. i belive the groups can be related to a feature or one of this module submodules (rules, views) it also can be the feature teste in the file (per_node_protection, global_password_protection,...) or even a mix of all that.
anyway it should really be $global :)

how about this ?

grimreaper’s picture

StatusFileSize
new8.08 KB

Hum, no... the $group in #13 is more like the name of the test function, that's how I thought them when I wrote them.

I don't think the $group should be feature specific as a feature is already in (its own file and) its own class. So in the UI of testing, it's easy to separate them.

And as I retest to see the impact in the UI. I just realize that for assertresponse there is no $group... So I add this new patch...

So, ok, If you want something global; global $group = 'Protected node' ?

I think the name of project or the name of the module, therefore the submodules will be hightlighted.

a global variable or a constant ?

izus’s picture

So, ok, If you want something global; global $group = 'Protected node' ?

I think the name of project or the name of the module, therefore the submodules will be hightlighted.

i'm ok with that :) let's keep it as simple as 'Protected node' :)

grimreaper’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new8.06 KB

Ok.

Add $this->group = 'Protected node'; in test's setup().

Remove protected $adminuser and protected $normaluser in ProtectedNodeBaseTestCase as they are useless.

Hoping it will be good this time :)

izus’s picture

oki thanks,
this is merged now
We should update the issue summary and keep going n for other tests

izus’s picture

Status: Needs review » Needs work

back to needs work status for other tests

  • Commit c24e08d on 7.x-1.x authored by Grimreaper, committed by izus:
    Issue #2277045 by Grimreaper, izus: Implement tests for protected node.
    
grimreaper’s picture

Issue summary: View changes
grimreaper’s picture

Issue summary: View changes
grimreaper’s picture

Do you prefer a patch (containing tests) per feature or a patch with tests for several features ?

izus’s picture

hi,
actually the same order as in the issue summary seems good.
let's move to "password per content type" tests or "global password"
Thanks

izus’s picture

Issue summary: View changes
grimreaper’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new6.81 KB

Hi,

Here is a patch that add tests for per content type protection.

Thanks for the review.

grimreaper’s picture

StatusFileSize
new9.58 KB

Hello,

I add a test about the email. So this patch contains both protected_node.per_type.test and protected_node.mail.test

But I don't know why protected node does not detect anymore the tests in protected_node.per_type.test.

izus’s picture

Status: Needs review » Needs work

Hi,
juste to make it easier to follow, i'll drop the 2 reviews separately, so this one is for the easiest one : emails :)

  1. +++ b/tests/protected_node.mail.test
    @@ -0,0 +1,89 @@
    +    $this->group = 'Protected node';
    

    This one should definitely belong to the parent setup for all tests

  2. +++ b/tests/protected_node.mail.test
    @@ -0,0 +1,89 @@
    +    $node = $this->createProtectedNode($password, $to);
    

    $node is not used, so we can delete this extra variable.

izus’s picture

also de we really need $this->group as getInfo already defines the group ?

izus’s picture

and here is the remaining.

i belive we have more code to do for a lot of cases but actually what is really good is that we are building a good and solid base here.
Thanks for contributing !

  1. +++ b/tests/protected_node.per_type.test
    @@ -0,0 +1,156 @@
    +    $this->type_password = $this->randomName(10);
    

    let's call it page_type_password or page_password or eaven page_content_type_password to be clear that it's specified for page content type !

  2. +++ b/tests/protected_node.per_type.test
    @@ -0,0 +1,156 @@
    +    // An authenticated user see the node.
    

    "sees" or better : "is viewing"

grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new9.72 KB
new3.38 KB
new6.96 KB

Hello,

emails

  1. $this->group = 'Protected node'; : I don't know if it is possible to put something that is in the method getInfo in the setup method. And there is no heritance of getInfo method.

    Note: Do not declare a getInfo() or any test methods (e.g. testExample()) in your parent class (MyModuleWebTestCase above). Doing so will cause errors.

    from https://www.drupal.org/node/583030

  2. ok
  3. $this->group : it's for debug messages. In the getInfo it's for the global organization of tests as you can see in the testing UI.

per type

  1. renamed in page_content_type_password
  2. is viewing

I attached a patch containing the two tests. As well as two patches with the tests separated.

Thanks for the review.

The last submitted patch, 31: implement_tests_for-2277045-31-emails.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 31: implement_tests_for-2277045-31-type.patch, failed testing.

izus’s picture

with local tests, it fails for emails

izus’s picture

locally, when i process the email test step by step in the UI, i have an error when i submit the page create form :

Warning: class_implements(): Class DevelMailLog does not exist and could not be loaded in drupal_mail_system() (line 278 of drupal7/includes/mail.inc).
Exception: Class DevelMailLog does not implement interface MailSystemInterface in drupal_mail_system() (line 283 of drupal7/includes/mail.inc).

i don't know yet if it's due to some local hack or if others can reproduce this

izus’s picture

i think it's due to local configuration
drush vget mail_system
mail_system: array (
'default-system' => 'DevelMailLog',
)

but what is really weird is that simpletest reported back this issue, i thought simpletest creates a new envirement to be dependent from local configuration ! oO

  • izus committed 2d427de on 7.x-1.x authored by Grimreaper
    Issue #2277045 by Grimreaper, Add email and per node type fetaures tests...
izus’s picture

Status: Needs work » Active

it was juste that tests pass now, thanks.
it's merged now, back to active state to continue this effort

izus’s picture

i wil add this little patch to :
- have good comment style inside methods and functions.
- add the group in the parent setup instead of doing it in each test setup.
- code styling

izus’s picture

Status: Active » Needs review

triggering the tests bot

  • izus committed 4967603 on 7.x-1.x
    Issue #2277045 by Grimreaper, izus: Correct some code styling and use...
izus’s picture

Status: Needs review » Active

The last submitted patch, 4: tests-2277045.patch, failed testing.

Status: Active » Needs work

The last submitted patch, 40: protected_node-test_styling-2277045-40.patch, failed testing.

grimreaper’s picture

Issue summary: View changes

Hi,

Sorry to have forgotten to warn you about the devel problem. I also got it and I was also surprised of that.

Sorry for the coding style problems, I thought my IDE was well configured. It seems not..., maybe I configured for one project and not globally. :(

Updating issue summary.

izus’s picture

all tests are green locally, nomatter what test bot is saying ;)

grimreaper’s picture

Issue summary: View changes

Updating issue summary has test for global password feature has been postes here : https://www.drupal.org/node/2266507#comment-9062857

izus’s picture

Issue summary: View changes
grimreaper’s picture

Issue summary: View changes

Updating issue summary.

grimreaper’s picture

Hiding files. Sorry for double post.

grimreaper’s picture

Hello,

I manually test the cardinality tests.

I found that with the core with the upload widget you can use a file in only one place (or I miss something).

Therefore to be able to use a file in several places, I enable file_entity and media modules. Using the media selector widget.

With the default file_entity and media permissions as file_entity add the specific permission "view private files", checked for anonymous user by default.

I test that if a private file is added in an unpublished unprotected node, anonymous user can't access the file with the URL. Ok, normal.

I test that if the same file is added to a publish protected node, anonymous user is then redirected to the password form and if he/she enters the correct password he/she gains access to the file. OK, normal.

I think I am going to write those tests. But I wonder, should I make another separated files for the test as it requires file_entity and media or use the current test file for private files ?

I also wonder if those tests are relevant, as it use contributed modules and the contributed modules on media management can have different approaches.

Waiting your go Izus to write those tests.

izus’s picture

ok so here is how i see it

1) without any additionnal custom module we should handle multiple file field values (actually we are assuming a file field has only one file value in it) this will implie current code change and maybe test also, but it will be a small patch.

2) caring about the file reuse stuff.
here we can add a new file test and enable file_entity in it using the simple test static variable $modules
example of this in d8 (i think it's the same with D7)

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array('mymodule');

here we will implement the wanted tests and should pay attention to the code modification that thios will implie (it should be wrapped in if(module_exists(....

document this feature in readme with the table in the link https://www.drupal.org/node/2179473#comment-8744327

if media does the reusing files differently , we can add another thing fo it, but i belive it's all done the same way : injecting the file object content
media requires file_entity, so i belive it's the same mechanism

:)

grimreaper’s picture

Assigned: grimreaper » Unassigned
damienmckenna’s picture

grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new7.27 KB

Here is a patch that add tests on statistics.

  • izus committed 2af6d06 on 7.x-1.x authored by Grimreaper
    Issue #2277045 by Grimreaper, izus: Implement tests for protected node
    
izus’s picture

Status: Needs review » Needs work

Thanks for the statistics test patch
This is now merged
back to needs work for the other parts to test

izus’s picture

Issue summary: View changes
izus’s picture

Issue summary: View changes
grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new4.05 KB

Hello,

I attach a patch to add test for the bulk actions. I have started with the "clear sessions" action.

Thanks for the review.

izus’s picture

Status: Needs review » Active

Reviewed and merged #61
Thanks

  • izus committed 669077d on 7.x-1.x authored by Grimreaper
    Issue #2277045 by Grimreaper, izus: Implement tests for protected node:...
damienmckenna’s picture

Status: Active » Fixed

I believe this is the correct status? :)

grimreaper’s picture

Issue summary: View changes
Status: Fixed » Active

Hello,

Unfortunately no, there are still tests to implement.

I update the issue summary.

grimreaper’s picture

Status: Active » Needs review
StatusFileSize
new2.03 KB

Add test for remove protection.

grimreaper’s picture

Add test for restore protection.

  • Grimreaper committed da77830 on 7.x-1.x
    Issue #2277045 by Grimreaper: Add test for the restore protection action...

  • Grimreaper committed 8c85080 on 7.x-1.x
    Issue #2277045 by Grimreaper: Add test for the "remove protection" bulk...
grimreaper’s picture

Issue summary: View changes
Status: Needs review » Needs work
grimreaper’s picture

Issue summary: View changes

Fix issue markup.

grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new5.11 KB

Add tests for use global password.

  • Grimreaper committed 511720a on 7.x-1.x
    Issue #2277045 by Grimreaper: Add test for the "use global password"...
grimreaper’s picture

Issue summary: View changes
Status: Needs review » Needs work
grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new2.4 KB

Add test for reset passwords action.

Status: Needs review » Needs work

The last submitted patch, 75: protected_node-add_test_reset_passwords-2277045-75.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 75: protected_node-add_test_reset_passwords-2277045-75.patch, failed testing.

grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new2.01 KB

Add test for protect node action.

About the falling test for reset password action. If someone can test it locally, I will be very thankful. I think I will open an issue that will regroup the test falling on the testbot.

  • Grimreaper committed 11ab1a0 on 7.x-1.x
    Issue #2277045 by Grimreaper: Add test for "protect nodes" action.
    
grimreaper’s picture

Issue summary: View changes
Status: Needs review » Needs work
grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new3.98 KB

Add test for private file reused across multiple nodes.

  • Grimreaper committed 2c7bab5 on 7.x-1.x
    Issue #2277045 by Grimreaper: Add test for private file reused across...

  • Grimreaper committed 4c10028 on 7.x-1.x
    Issue #2277045 by Grimreaper: Add test for "reset passwords" action.
    
grimreaper’s picture

Issue summary: View changes
Status: Needs review » Needs work
grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new1.86 KB

Let's debug the two remaining tests that do not pass on the testbot.

Status: Needs review » Needs work

The last submitted patch, 86: protected_node-debug_test-2277045-86.patch, failed testing.

Status: Needs work » Needs review
grimreaper’s picture

And now both tests pass!!!??? Are you kidding me testbot? lol.

So, could we close the issue?

izus’s picture

cool,
so https://www.drupal.org/node/2179473#comment-8744327 just needed tests without any code fix ?
great work here :)
Thanks man !
i think we can close it if everything is ok.

grimreaper’s picture

For https://www.drupal.org/node/2179473#comment-8744327, Yeah, very lucky :), no code fix needed

It was the test added with https://www.drupal.org/node/2277045#comment-10092610, do you see another test for that feature ?

I begin to feel the pleasure to close an issue that has been opened more than an year ago :D

digitgopher’s picture

What is the status here? It is not clear to me what work is left to do.

  • Grimreaper committed be7751b on 7.x-1.x
    Issue #2277045 by izus, Grimreaper: last bulk and fork tests now pass.
    
grimreaper’s picture

Issue summary: View changes
Status: Needs review » Fixed

Hello digitgopher,

I had to merge a last change. I waited any comment.

As nobody sees another test to implements since one week. I close the issue.

I update the issue summary so it is clear there is nothing more to do.

Thanks all.

Status: Fixed » Closed (fixed)

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