/**
  * @param Questionnaire       $questionnaire
  * @param TranslatorInterface $translator
  */
 protected static function prepareResultsNarrative(Questionnaire $questionnaire, TranslatorInterface $translator)
 {
     $domain = ResultsNarrativeBuilder::SECTION_NAME;
     $rnb = new ResultsNarrativeBuilder();
     $narrative = $rnb->buildNarrative($questionnaire);
     $narrative->addSubstitution("{{NAME}}", $questionnaire->getPerson()->getFirstName());
     $subs = $narrative->getSubstitutions();
     $results = $narrative->getMessagesInSection($domain);
     self::$resultsNarrative = array('resultsNarrativeHeadline' => self::provideTranslation($translator, $results['headline'], $subs, $domain), 'resultsNarrativeIntroduction' => self::provideTranslation($translator, $results['intro'], $subs, $domain), 'resultsNarrativeOverview' => self::provideTranslation($translator, $results['overview'], $subs, $domain), 'resultsNarrativeBehavioursHeadline' => self::provideTranslation($translator, $results['behaviours_headline'], $subs, $domain), 'resultsNarrativeBehavioursBody' => self::provideTranslation($translator, $results['behaviours_body'], $subs, $domain), 'resultsNarrativeSmoking' => self::provideTranslation($translator, $results['smoking'], $subs, $domain), 'resultsNarrativeDrinking' => self::provideTranslation($translator, $results['drinking'], $subs, $domain), 'resultsNarrativeMoving' => self::provideTranslation($translator, $results['moving'], $subs, $domain), 'resultsNarrativeEating' => self::provideTranslation($translator, $results['eating'], $subs, $domain));
 }
 public function testSubstitutionOfThreeOrMoreMotivations()
 {
     $questionnaire = new Questionnaire(new Person());
     $questionnaire->getPerson()->setGender('male');
     $questionnaire->getMoving()->setCompletedDate(new \DateTime());
     $questionnaire->getEating()->setCompletedDate(new \DateTime());
     $questionnaire->getDrinking()->setCompletedDate(new \DateTime());
     $questionnaire->getSmoking()->setCompletedDate(new \DateTime());
     $questionnaire->getAboutYou()->getMotivations()->setAlertness(true)->setAppearance(true)->setWeight(true)->setEnergy(true);
     $priorityCopy = $this->instance->buildNarrative($questionnaire)->getSubstitutions()['{{PRIORITY_COPY}}'];
     $this->assertEquals(1, substr_count($priorityCopy, 'and'));
     $this->assertEquals(1, substr_count($priorityCopy, ', '));
 }
 /**
  * @param Questionnaire $questionnaire
  */
 protected function buildResultsNarrative(Questionnaire $questionnaire)
 {
     if (ResultsSpecification::isSatisfiedBy($questionnaire)) {
         $rnb = new ResultsNarrativeBuilder();
         $narrative = $rnb->buildNarrative($questionnaire);
         $this->narrative->merge($narrative);
     }
 }