Oil interaction with foams under static and flowing conditions in porous media