Hey Slevy,
What do you mean with 'the php echo '<script....' does not work because of the two nested scripts'? In your main output HTML you call the test.php, which will independently run, and can produce the output you need it to. If you were to place:
echo "
<script language=\"javascript\" src=\"http://www.test.com/test.js\">
</script>
<noscript>
<a href=\"http://www.test.com/something.js\" target=\"_blank\">
<img src=\"http://www.test.com/image.jpg\">
</a>
</noscript>
";
That should work just fine.
That being said.. Why not create the .js straight away upon rendering of the main page?