I saw this picture here:
Is this true? Can cancer be detected by a pregnancy test?
Yes, most pregnancy tests detect human chorionic gonadotropin (hCG), a hormone produced by fertilized eggs, but also by some kinds of cancer cells.
You can read more about different tumor markers on this info page from "The American Cancer Society".
There are also several other situations where a pregnancy test may give a false positive result (both for men and non-pregnant women). The Wikipedia article lists several possibilities:
False positive test results may occur for several reasons, including errors of test application, use of drugs containing the hCG molecule, and non-pregnant production of the hCG molecule. Urine tests can be falsely positive in those that are taking the medications: chlorpromazine, phenothiazines and methadone among others.
Spurious evaporation lines may appear on many home pregnancy tests if read after the suggested 3–5 minute window or reaction time, independent of an actual pregnancy. False positives may also appear on tests used past their expiration date.
A woman who has been given an hCG injection as part of infertility treatment will test positive on pregnancy tests that assay hCG, regardless of her actual pregnancy status. However, some infertility drugs (e.g., clomid) do not contain the hCG hormone.
Some diseases of the liver, cancers, and other medical conditions may produce elevated hCG and thus cause a false positive pregnancy test. These include choriocarcinoma and other germ cell tumors, IgA deficiencies, heterophile antibodies, enterocystoplasties, gestational trophoblastic diseases (GTD), and gestational trophoblastic neoplasms.