Example #1
0
 /**
  * @covers YAYOG\History::addExercises
  */
 public function testAddExercises()
 {
     $method = new ReflectionMethod('YAYOG\\History', 'addExercises');
     $method->setAccessible(true);
     $exercise1 = new Exercise();
     $exercise1->setType('Ladders')->setName('Squats')->setVariation('Slow');
     $exercise2 = new Exercise();
     $exercise2->setType('Ladders')->setName('Squats')->setVariation('Fast');
     $exercise3 = new Exercise();
     $exercise3->setType('Ladders')->setName('Squats')->setVariation('Slow');
     $exercise4 = new Exercise();
     $exercise4->setType('Ladders')->setName('Squats')->setVariation('Slow');
     $exercise5 = new Exercise();
     $exercise5->setType('Ladders')->setName('Squats')->setVariation('Slow');
     $exercise6 = new Exercise();
     $exercise6->setType('Ladders')->setName('Swimmers')->setVariation('Slow');
     $exercise7 = new Exercise();
     $exercise7->setType('Ladders')->setName('Squats')->setVariation('Fast');
     $exercise8 = new Exercise();
     $exercise8->setType('Ladders')->setName('Squats')->setVariation('Fast');
     $method->invoke($this->history, array($exercise1, $exercise2, $exercise3));
     $method->invoke($this->history, array($exercise4, $exercise5, $exercise6, $exercise7));
     $method->invoke($this->history, array($exercise8));
     $this->assertEmpty($exercise1->getPreviousExercises(), 'First exercise does not have any previous exercises');
     $this->assertEmpty($exercise2->getPreviousExercises(), 'Different variation is considered');
     $this->assertEmpty($exercise3->getPreviousExercises(), 'Same workout is considered');
     $this->assertSame(array($exercise1), $exercise4->getPreviousExercises(), 'Same number is considered');
     $this->assertSame(array($exercise3), $exercise5->getPreviousExercises(), 'Same number is considered even if they do not have the same order');
     $this->assertEmpty($exercise6->getPreviousExercises(), 'Exercise, which was not in the first workout, has no previous exercises');
     $this->assertSame(array($exercise2), $exercise7->getPreviousExercises(), 'Previous exercise is added even if there is only one');
     $this->assertSame(array($exercise7, $exercise2), $exercise8->getPreviousExercises(), 'Multiple previous exercises are added too');
 }
Example #2
0
 /**
  * Creates and returns the HTML for the previous exercises.
  *
  * @param Exercise $currentExercise The current exercise
  * @param int $amount How many previous exercises should be rendered
  * @return string HTML of the previous exercises
  */
 protected function renderPreviousExercises(Exercise $currentExercise, $amount = 5)
 {
     $previousExercises = $currentExercise->getPreviousExercises();
     if (empty($previousExercises)) {
         return '';
     }
     $html = '<li class="list-group-item list-previous-exercises"><ul class="list-unstyled">';
     $date = $currentExercise->getWorkout()->getDate();
     foreach ($previousExercises as $previousExercise) {
         $previousWorkout = $previousExercise->getWorkout();
         $html .= sprintf('<li>%s&ensp; <a class="workout-link" href="#workout-%d" title="Jump to this workout">' . '%s</a> <span class="text-muted">(%s): %d reps</span></li>', $this->renderRepsDelta($currentExercise->getReps(), $previousExercise->getReps()), $previousWorkout->getId(), $previousWorkout->getLabel(), $this->renderRelativeDate($previousWorkout->getDate(), $date), $previousExercise->getReps());
         if (--$amount == 0) {
             break;
         }
     }
     return $html . '</ul></li>';
 }