Thanks to all for the replies. I've got the following flights, DFW-MIA-MAD, MAD-LHR-DFW. The only one that will not earn will be MAD-LHR.
Another question is does an AA flight operated by a non OneWorld partner earn elite miles?
ie AA flight # xxx operated by Mexicana