you have to maintain PR status until you get your citizenship, which implies you have to be physically be in Canada for 3 years out of the last five years. As long as you're in that range you're still eligible for citizenship even if you were outside of Canada for an extensive period of time.
Also, you don't need to be in Canada to take a test. You can notify them that you'll be taking the test outside of Canada and that would suffice. However for the oath you have to be on Canadian soil. Hope it helps.