Let `is_attachment()` accept an $attachment parameter, similar to `is_page()` and `is_single()`. Adds Unit Tests for all 3.

Props alex-ye for the initial patch.
Fixes #24257.


Built from https://develop.svn.wordpress.org/trunk@27016


git-svn-id: http://core.svn.wordpress.org/trunk@26893 1a063a9b-81f0-0310-95a4-ce76da25c4cd