Monday, April 28, 2008

CSS conditional comments hacks

It seems impossible to run away from chasing display problems in IE7/6/5 vs Firefox. A wonderful way of dealing with issues (well maybe not "wonderful" but at least seems to work) is to have conditional CSS files depending on the browser. Read all about conditional comments to load per-browser-version specific CSS files.

But, there's a problem. I have IE7 in WinXP and I've downloaded an old version of a standalone IE6 from evolt.org. IE6 works fine (behaves as IE6 when troublshooting issues) but interprets conditional comments for the hack as if it was IE7. In other words, I can't use my local development box to see if conditional comments and CSS delivered through that will work. Hopefully will sort this out and post an update.

Thursday, April 24, 2008

When your testing environment is not cutting it

I was so surprised the other day when I discovered that despite the whole kitchen-sink testing setup (NUnit, selenium, Cruise Control) part of my application was using a fixed connection string in the TableAdapter I've created using VS2005.

I had a connection string in the Properties > Settings (called ConnStr) but I never noticed that its fully qualified name was something like ProjectX.My.Settings.ConnStr. When I added a ConnStr to my connectionStrings section of web.config I thought that all would be well. Obviously everything was working since I kept on testing on the same machine on which I develop and hence my development database was there.

Anyways, I wanted to see whether an installer would work properly so I started a VMWare Win 2003 server instance and discovered that the application was trying to connect to my development database on the server. That was a bummer...

OK, so I admit that it must be that one or two of my tests are definitely not up to speed since they ought to have been able to catch this, but I kind of discovered what a great thing a completely dedicated testing machine is. Hm, no wonder people keep on stressing that.

Thursday, April 17, 2008

Drupal Invalid argument supplied for foreach error

I've been getting this really weird error and could not track it for sometime but have finally managed to figure out a way to get rid of it, so perhaps others might find this useful too.

Summary: it was caused by a call to node_load() method passing nothing as an argument. So check if you have some code that assumes that an ID of a node is present and calls that function!

Long story:
First of all, my page would show in the central area a warning message like this:

* warning: Invalid argument supplied for foreach() in C:\Program Files\Apache Group\Apache2\htdocs\mcsonline\modules\node\node.module on line 521.
* warning: implode() [function.implode]: Bad arguments. in C:\Program Files\Apache Group\Apache2\htdocs\mcsonline\modules\node\node.module on line 525.
* user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 query: SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM node n INNER JOIN users u ON u.uid = n.uid INNER JOIN node_revisions r ON r.vid = n.vid WHERE in C:\Program Files\Apache Group\Apache2\htdocs\mcsonline\includes\database.mysql.inc on line 172.
Searching around led me to some other people complaining about the error but the major difference is that there was usually a hint in that the error would refer to a specific module. In my case, however, it was talking about the core node module! Not much help there.

First thing to do: try and figure out where is the error coming from. :) OK, so I suppose that's an obvious one. But honestly I was stuck a bit wondering where to start. So one easy way is to start turning off blocks until you can see that the error disappears. So this led me to a specific block which was actually a view (I'm using a module to display views as blocks which I know can't remember the name).

Next, after realizing that there was nothing interesting about the view since it just did a List View of a couple of CCK fields and a title for a user-defined content type I was off to search elsewhere. Since my memory does not serve me that well it took me a while to remember to check template.php since I could be overriding the list view (using the phptemplate_views_view_list_VIEW-NAME($view, $nodes, $type)). So there it was - a small snippet getting the view in question to render through a template.

Now the really really weird thing was that the view was showing the content - I saw a single item that I was supposed to see but I get the warning message as well (hm, now I realize its a "warning"). So it meant that the method did something wrong partially but managed to proceed.

Some context here: a day before I was actually removing some CCK fields from content types and I had this author field that I've removed for the (now problematic) event content type.

In the function that I had there was a line like:
$auth = node_load($targetnode->field_autor[0]['nid']);
I did this regardless of whether the author field was there or not! (hm, this is supposed to be a small helper method used when rendering list views so ...).

Doing a check if the field is there before calling node_load did the trick! Yay.

Beware of var_dump in Drupal nodes

Just had a scare when my Drupal site started showing weird stuff half-way through printing a view. Turns out that I left commented var_dump($node) in the code and the contents had an "appropriate" mix of comments and HTML that cause the comment to break and spill-over into the page.

Lesson learnt: keep them template files nice and tidy and leave the debug info for the development server. Hm, like that's new anyways? :)

Friday, April 11, 2008

Testing with old browsers

Corporate policies could be a nightmare at times. As much as I understand the hassle of changing browsers and adjusting the applications to work with them I cannot appreciate folks who use IE6, refuse to use IE7 (which is, after all, a better beast then its predecessor) and don't want to start using Firefox.

My development machines are all upgraded to IE7 (XP still, though) and I now have a need to test against IE6 which is exclusively used for my current project. Well, luckily you can get old browsers from http://browsers.evolt.org/. Installed it (well unzipped it, really) and seems to work (showing my messed-up UI as expected). About Us from Help incorrectly displays version 7 dialog box. Ah, well...

(Updated 23 May 2008):
One thing that does not work is the CSS hack through HTML comments. You probably know of being able to use a conditional inclusion of a CSS file by using IE-only conditional (

Labels