Scenario: The unpublish date required setting is turned on. A node has gone through the publish and unpublish cycle and is now unpublished. On editing, the unpublish-on field is not required, which is correct. Enter just a publishing date and save. This node is now in an incorrect state because it will published and could remain that way, which contraditcts the 'unpublishing date required' setting. Also on subsequent editing before being published the unpublish-on 'required' marker is set, but the unpublish-on field is blank.

The fault is during editing of the unpublished node. The node can be edited and remain unpublished with both fields being left blank (this is ok). However if a publish-on date is entered then validation should enforce that an unpublish-on date is also entered.

The validation is simple to do, but I will also try to write a test to prove it is working as expected.

Comments

jonathan1055’s picture

Issue summary: View changes
jonathan1055’s picture

Status: Active » Needs review
StatusFileSize
new1.17 KB

Here's the new test, but without the new validation. This patch should fail one test.

Status: Needs review » Needs work

The last submitted patch, 2: 2365707_2.validation_for_unpublish_on_TEST_ONLY.patch, failed testing.

jonathan1055’s picture

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

Here's the patch with the new validation and the test. Also removed two debug messages from the tests, which do not need to be there.

pfrenssen’s picture

Status: Needs review » Fixed

Nice catch, this validation was indeed omitted. Thanks for adding a test too!

Status: Fixed » Closed (fixed)

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

AlexKirienko’s picture

Status: Closed (fixed) » Needs review
StatusFileSize
new2.03 KB

Hi.

I still have an issue with unpublish_on validation.

In my case only unpublish_on is required. On node creation unpublish_on validation works fine. But when node has gone through the publish and unpublish cycle and become unpublished. Then user can publish node without filling unpublish_on date.

#4 patch works well if published_on is required, but not in my case.

Please check attached patch. Validation for unpublish_on date will work when user try to publish node.

I also have changed test case for this validation.

But changes in validation will break testScheduledNodeDelete(). Nodes with Published checked and without unpublish_on date can't pass validation and be removed.
Maybe we need to check on validation if clicked button not Delete. This situation need to be discussed.

Anyway unpublish_on date need to be validated if it set to be required.

Status: Needs review » Needs work

The last submitted patch, 8: scheduler-unpublish-validation-2365707-8.patch, failed testing.

jonathan1055’s picture

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

Hi AlexKirienko,
Yes, you are right. If the 'unpublishing required' option is turned on, then publishing the node directly should come under the same validation rules as setting a publish-on date. In both cases the user should enter an unpublish-on date. The code change you made in sheduler_node_validate() is not quite right because you have altered the existing validation. We need to retain the check for !empty($node->publish_on) but also add the new check against $form_state['values']['status']

The changes for removing validation when deleting a node have already been fixed in other issues, so that should be OK.

This extra validation needs to be changed at 8.x first. Here's a patch with an updated test to check for it - the class testValidationDuringEdit should now fail one assertion.

Status: Needs review » Needs work
jonathan1055’s picture

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

As expected the new assertion fails. Here's a patch with the additional constraint and the new test. This should pass.

[By the way, it's really nice to be able to test patches at a selected version, and not have to change the issue version. I think this is a relatively new feature]

Status: Needs review » Needs work

The last submitted patch, 12: 2365707_12.validation_for_unpublish_on.8x.patch, failed testing.

jonathan1055’s picture

Status: Needs work » Needs review

That is a bit strange. The new test class passed, but the failure was in a completely different class which was not altered by the patch.

Show: Failing classes All
✓	✗	
34	1	Scheduler.Scheduler
1	1	Scheduler.Drupal\scheduler\Tests\SchedulerPermissionsTest
✓		- setUp
	✗	testUserPermissions

fail: [Other] Line 44 of modules/scheduler/src/Tests/SchedulerPermissionsTest.php:
The node was created and saved when the user does not have scheduler permissions.

That shows the benefit in having a good test coverage. More investigation is required ...

jonathan1055’s picture

OK, I can see what has happened. The new constraint has prevented a user from creating a published node if the user does not have scheduling permissions but the 'unpublishing required' option is enabled. That is good! If a user cannot set an unpublish date because they have not been granted scheduler permissions then it is correct that they should not be able to create a published node, as that node will not have an unpublish-on date.

I think the correct result in this case is that the user should only be allowed to create an unpublished node. Other user roles would then be able to schedule the node. This may require a change to the message text, as the user would see "To publish this node you must also set an 'unpublish-on' date" but they would not have access to the unpublish-on field. But the principle of not letting them create/save a published node is correct.

jonathan1055’s picture

StatusFileSize
new11.64 KB

Updated patch with the following changes:

  1. Changed the text of the new validation message to "Either you must set an 'unpublish on' date or save this node as unpublished."
  2. In SchedulerValidationTest, as well as checking the validation message text, I added additional assertions to check that the node is not saved
  3. Improved comments in SchedulerUnpublishOnConstraintValidator
  4. Changed SchedulerPermissionsTest so that it does not test with the 'required' options set
  5. Created #2707411: Conflict between 'required publishing' and not having scheduler permission to deal with this problem, and added @todo in the permissions test, referencing that issue

  • jonathan1055 committed 1ddd7c5 on 8.x-1.x
    Issue #2365707 by jonathan1055, AlexKirienko: Missing validation when...
jonathan1055’s picture

Now a patch for D7 with the new validation (as per 8.x), updated testValidationDuringEdit() and a new test function testPermissions() which we did not have at 7.x before.

  • jonathan1055 committed 8896721 on 7.x-1.x
    Issue #2365707 by jonathan1055, AlexKirienko: Missing validation when...
jonathan1055’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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