While porting a contrib project my tests blew up because of this. Most people won't care about the ordering, but if you want to do a straight port, you either have to fix expectations in test -which is a drag when checking a big chunk of HTML with lots of images- or pass everything in the correct order in $attributes instead of $variables, no matter if you're using default values.
Along the way in #555830: Clean up theme_image() to use drupal_attributes() for all attributes and revisit defaults for "alt" and "title" the default order was completely changed. Unintentionally, I think. See patches in #10 and #14 in [555830].
The situation for src is a bit funny. To control the order of src, it is currently possible to just pass any src value in $attributes and have theme_image() work with $path and override the src value.

By making use of the array union operator we can restore the original order, which will make it easier for contrib maintainers to port their code and prevent this type of regression. I suspect that there is only a very small number of maintainers that have ported their code *and* rely on the current default order.

Comments

eric_a’s picture

Status: Active » Needs review
StatusFileSize
new993 bytes

To be honest there remains a little regression anyways since the double space issue was fixed in D7 and remains in D6. Note: all of this applies mostly to the case where we used getsize TRUE. This option is gone now but was pretty common n D6.

The regression is from D6 and D7, though.

damien tournoud’s picture

Status: Needs review » Closed (won't fix)

Fix your tests. There was never been any guarantee of the order of the attributes in the HTML markup. You should use proper XPath instead of relying on exact match in the HTML.

eric_a’s picture

Status: Closed (won't fix) » Active

The fact of the matter is that in tests using the default theme implementation the order *was* guaranteed with the following usage (which is pretty common). It was mostly hardcoded.

D6:

theme('image', 'my path', 'my alt',  'my title', array('class' => 'class1 class2'), TRUE);

D7:

theme('image', array('path' => 'my path', 'alt' => 'my alt',  'title' => 'my title', 'attributes' => array('class' => array('class1', 'class2'))));

The src attribute always came out first, then alt, then title, then width, height and then any other passed attributes.

damien tournoud’s picture

Status: Active » Closed (works as designed)

It's HTML. The order of arguments is not guaranteed.

Stop using exact match in your tests, and use XPath. There are plenty of example in Drupal core's test suite.