User tests: Successful: Unsuccessful:
In case of a validation failure, the (error) message is not displayed. This is due to the fact that an Exception object is pushed onto the JForm::errors array, while this must be a text string apparently.
Line 1212
array_push($this->errors, $valid);
has now been changed into
array_push($this->errors, $valid->getMessage());
Which seems to solve the problem.
Test instructions:
This is for testing that a custom rule error message is not shown by Joomla in a component configuration.
Test instructions:
Labels |
Added:
?
|
Labels |
Added:
?
|
Hi whoever you are,
Thanx for the feed back. It's my first pull request and I didn't read
the instruction very well (understatement). I'm already in contact with
Roland Dalmulder to improve it.
Either this unit test is incorrect or another one somewhere higher up. I
tested my solution locally. When the Exception object is pushed onto the
error array, as si the case now, the message is not displayed. When I
push the actual text message onto the array, the message is displayed
perfectly. This raises the question which code and which unit test needs
to be adjusted.
I'll try to figure this out with Roland.
Regards,
Pieter-Jan de Vries
On 27-1-2015 18:08, zero-24 wrote:
@pjdevries https://github.com/pjdevries can you explain how we can
reproduce that? what kind of validation error you mean?BTW the unit test fails:
|There was 1 failure:
1) JFormTest::testGetErrors
Line:831 The errors should be exception objects.
Failed asserting that false is true.
/home/travis/build/joomla/joomla-cms/tests/unit/suites/libraries/joomla/form/JFormTest.php:832
|So maybe the exception object is correct?
—
Reply to this email directly or view it on GitHub
#5894 (comment).
Thanks @pjdevries
Thanx for the feed back. It's my first pull request and I didn't read
the instruction very well (understatement).
No Problem You are very welcome here!
I'll try to figure this out with Roland.
ok Thanks Let me know if you figured it out. So I can try to test it. Thanks!
I'll keep you in the loop. Good to know there's already one tester :)
Regards,
Pieter-Jan
On 27-1-2015 18:30, zero-24 wrote:
Thanks @pjdevries https://github.com/pjdevries
Thanx for the feed back. It's my first pull request and I didn't read the instruction very well (understatement).
No Problem You are very welcome here!
I'll try to figure this out with Roland.
ok Thanks Let me know if you figured it out. So I can try to
test it. Thanks!—
Reply to this email directly or view it on GitHub
#5894 (comment).
So this is one of those kinds of bugs which are horrible. There's no 'good' fix. The unit tests except an Exception (which personally I think is correct). But JModelForm expects a string (joys). I think JModelForm actually has the bug where it's looking for a string. But I might be wrong :/
I have run into this issue previously in framework applications I've built. While this change makes sense and make that errors array consistent, it is a potential backward compatibility breaker, demonstrated by the unit tests failing. For now, this should be fixed in JModelForm when the form is being validated so that the code checks for an Exception instance and re-factoring the error handling code in JForm to either consistently return strings or exceptions be done for 4.0.
I looked at JForm validate method in the past and saw that Exception is an expected value / behavior. When we call validate method of JForm and validation failure, all elements in $this->errors are Exception objects.
In Joomla core, these errors are displayed in JControllerForm in this block of code (which can be found at https://github.com/joomla/joomla-cms/blob/staging/libraries/legacy/controller/form.php#L706)
for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++)
{
if ($errors[$i] instanceof Exception)
{
$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
}
else
{
$app->enqueueMessage($errors[$i], 'warning');
}
}
Maybe in your case, the error is not displayed because you use different code / ways for displaying errors?
oh it will be huge b/c issue
So since this breaks backwards compatibility and should be solved differently, should this one be closed?
I think this PR is invalid, so it should be closed
Roland and me intend to pick this one up later this month. With all the cool feed back, I'm sure we will come up with the proper solution next time.
Thank you all.
Title |
|
Roland, who did most of the work to be honest, and I finally implemented a proper solution. Roland also created a rudimentary component to be used for testing purposes. A download link for the test component can be found in the test instructions.
Category | ⇒ | Administration Components |
Easy | No | ⇒ | Yes |
Just tested this Patch with Joomla version: 3.4.4-dev development.
Used the test-description from above and the test component: com_formtest
Everything worked like described!
Status | Pending | ⇒ | Ready to Commit |
Looks and works great and nothing is broken ;) --> RTC Thanks.
Labels |
Added:
?
|
Milestone |
Added: |
Thanks for your time!
Milestone |
Added: |
Milestone |
Removed: |
Status | Ready to Commit | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2015-10-01 18:08:48 |
Closed_By | ⇒ | rdeutz |
Labels |
Removed:
?
|
Milestone |
Milestone |
Added: |
Milestone |
Added: |
Milestone |
@pjdevries can you explain how we can reproduce that? what kind of validation error you mean?
BTW the unit test fails:
So maybe the exception object is correct?