public function testBirthday()
 {
     $birthday = 'December 12, 1982';
     $profileDetails = new ProfileDetails();
     $profileDetails->setBirthday($birthday);
     $this->assertEquals($birthday, $profileDetails->getBirthday());
 }
Exemple #2
0
 private static function parseDetails(Crawler $content, ProfileDetails $details, $apiVersion)
 {
     $userAccessLevel = $content->filterXPath('//*[contains(attribute::class,"profile-team-title")]');
     $userStats = $content->filter('.user-status');
     $userOnline = $userStats->filterXPath('//*[text()="Last Online"]/../span[2]');
     $userGender = $userStats->filterXPath('//*[text()="Gender"]/../span[2]');
     $userBDay = $userStats->filterXPath('//*[text()="Birthday"]/../span[2]');
     $userLoc = $userStats->filterXPath('//*[text()="Location"]/../span[2]');
     $userJoined = $userStats->filterXPath('//*[text()="Joined"]/../span[2]');
     $userForumPosts = $userStats->filterXPath('//*[text()="Forum Posts"]/../span[2]');
     $userWebsite = $content->filterXPath('//*[@class="user-profile-sns"][1]/a');
     $comments = $content->filter('span[class="floatRightHeader ff-Verdana"]');
     if ($comments->count() > 0) {
         $details->setComments((int) trim(preg_replace('/(.+?)\\((.+?)\\)/', '$2', $comments->text())));
     }
     if ($userAccessLevel->count() > 0) {
         $details->setAccessRank($userAccessLevel->text());
     } else {
         $details->setAccessRank('Member');
     }
     if ($userOnline->count() > 0) {
         $details->setLastOnline($userOnline->text());
     }
     if ($userGender->count() > 0) {
         $details->setGender($userGender->text());
     } else {
         $details->setGender('Not specified');
     }
     if ($userBDay->count() > 0) {
         //MAL allows partial birthdays, even just day and year (wth?)
         //We need to check combinations to handle this correctly.
         $bdParts = explode(' ', $userBDay->text());
         if (count($bdParts) == 3) {
             //Full date, normal processing
             $details->setBirthday(\DateTime::createFromFormat('M d, Y', $userBDay->text())->format('F j, Y'));
         } elseif (count($bdParts) == 2) {
             //We only have two parts, figure out what we were given
             $firstIsNumber = is_numeric($bdParts[0]);
             $hasComma = strpos($bdParts[0], ',');
             if ($firstIsNumber === false && $hasComma === false) {
                 //First Value must be a month
                 //This will cover month and day or month and year
                 $monthName = \DateTime::createFromFormat('M d', $bdParts[0] . ' 1')->format('F');
                 $details->setBirthday($monthName . ' ' . $bdParts[1]);
             } else {
                 //Day and year make no sense, just use year
                 $details->setBirthday($bdParts[1]);
             }
         } else {
             //It's either just one value or something else, just save the data.
             $details->setBirthday($userBDay->text());
         }
     }
     if ($userJoined->count() > 0) {
         $details->setJoinDate(\DateTime::createFromFormat('M d, Y', $userJoined->text())->format('F j, Y'));
     }
     if ($userLoc->count() > 0) {
         $details->setLocation($userLoc->text());
     }
     if ($userWebsite->count() > 0) {
         $details->setWebsite($userWebsite->attr('href'));
     }
     if ($userForumPosts->count() > 0) {
         $details->setForumPosts((int) str_replace(',', '', $userForumPosts->text()));
     }
     if ($apiVersion >= '2.1') {
         $userReviews = $userStats->filterXPath('//*[text()="Reviews"]/../span[2]');
         $userRecommendations = $userStats->filterXPath('//*[text()="Recommendations"]/../span[2]');
         $userBlogPosts = $userStats->filterXPath('//*[text()="Blog Posts"]/../span[2]');
         $userClub = $userStats->filterXPath('//*[text()="Clubs"]/../span[2]');
         if ($userReviews->count() > 0) {
             $details->setReviews((int) $userReviews->text());
         }
         if ($userRecommendations->count() > 0) {
             $details->setRecommedations((int) $userRecommendations->text());
         }
         if ($userBlogPosts->count() > 0) {
             $details->setBlogPosts((int) $userBlogPosts->text());
         }
         if ($userClub->count() > 0) {
             $details->setClubs((int) $userClub->text());
         }
     }
     return $details;
 }