A unit must immediately test for panic if fleeing friends move through it.
For simplicity, resolve the movement of the fleeing friends before taking and resolving the Panic test.
This is the most destructive form of panic, as one unit can panic and flee through another unit, which in turn might panic and flee through a further unit, and so on until your battleline is reduced to tatters.