/**
  * Test kp_runRecommender returns the same results as the the recommender
  **/
 public function test8()
 {
     kp_resetVisitData();
     try {
         // Set up test data in database
         $testData = new kp_testData();
         $testPostIDs = $testData->insertTestPosts(10);
         $tK = array_keys($testPostIDs);
         // User Group #1
         $user1 = new kp_testUser(array($tK[0], $tK[1], $tK[2]), array());
         $user2 = new kp_testUser(array($tK[0], $tK[1], $tK[2], $tK[3]), array());
         // User Group #2
         $user3 = new kp_testUser(array($tK[4], $tK[5], $tK[6]), array());
         $user4 = new kp_testUser(array($tK[4], $tK[5], $tK[6]), array());
         // Get the recommendation from the recommender
         $user1->recommender->run(1, 1);
         // Get the recommendation from the lib function
         $posts = kp_getRecommendedWP_Posts(1, $user1->ipAddress, $user1->userAgent);
         $test = $user1->recommender->posts[0]->post_id == $posts[0]->post_id;
         $user1->deleteVisitData();
         $user2->deleteVisitData();
         $user3->deleteVisitData();
         $user4->deleteVisitData();
         $testData->deleteAllTestPosts();
     } catch (Exception $e) {
         $test = false;
     }
     $testObj = new kp_test("Test 8", $test, "results from recommendation function match results from recommendation engine", "results from recommendation function do not match results from recommendation engine");
     $testObj->render();
     kp_resetVisitData();
 }
예제 #2
0
 function test4()
 {
     $test = true;
     // Prepare the test data
     $testData = new kp_testData();
     $testPostIDs = $testData->insertTestPosts(3, "post");
     $testPageIDs = $testData->insertTestPosts(3, "page");
     $postKeys = array_keys($testPostIDs);
     $pageKeys = array_keys($testPageIDs);
     $user1 = new kp_testUser(array($postKeys[0], $pageKeys[0], $attachmentKeys[0]), array());
     $user2 = new kp_testUser(array($postKeys[0], $postKeys[1], $postKeys[2], $pageKeys[0], $pageKeys[1], $pageKeys[2]), array());
     try {
         // Recommend only posts
         $test4a = true;
         $widgetObj = new kp_widget();
         $widgetInstance = array("posttypes-post" => true, "posttypes-page" => false, "numposts" => 6);
         $widgetResults = $widgetObj->widget(array(), $widgetInstance, false, "", array(), array(), $user1->ipAddress, $user1->userAgent);
         $recommender = $widgetResults["recommender"];
         foreach ($recommender->posts as $recommendedPost) {
             $test4a = $test4a && $recommendedPost->post->post_type == "post";
         }
         $test = $test && $test4a;
         // Recommend only page (don't specify what to do with posts or pages)
         $test4b = true;
         $widgetObj = new kp_widget();
         $widgetInstance = array("posttypes-page" => true, "numposts" => 6);
         $widgetResults = $widgetObj->widget(array(), $widgetInstance, false, "", array(), array(), $user1->ipAddress, $user1->userAgent);
         $recommender = $widgetResults["recommender"];
         foreach ($recommender->posts as $recommendedPost) {
             $test4b = $test4b && $recommendedPost->post->post_type == "page";
         }
         $test = $test && $test4b;
         // Recommend only kp_test_custom and pages but not posts
         $test4c = true;
         $widgetObj = new kp_widget();
         $widgetInstance = array("posttypes-post" => true, "posttypes-page" => true, "numposts" => 10);
         $widgetResults = $widgetObj->widget(array(), $widgetInstance, false, "", array(), array(), $user1->ipAddress, $user1->userAgent);
         $recommender = $widgetResults["recommender"];
         foreach ($recommender->posts as $recommendedPost) {
             $test4c = $test4c && ($recommendedPost->post->post_type == "post" || $recommendedPost->post->post_type == "page");
         }
         $test = $test && $test4c;
         // Don't set any post types, default to all post types
         $test4d = true;
         $widgetObj = new kp_widget();
         $widgetInstance = array("numposts" => 10);
         $widgetResults = $widgetObj->widget(array(), $widgetInstance, false, "", array(), array(), $user1->ipAddress, $user1->userAgent);
         $recommender = $widgetResults["recommender"];
         foreach ($recommender->posts as $recommendedPost) {
             $test4d = $test4d && ($recommendedPost->post->post_type == "post" || $recommendedPost->post->post_type == "page");
         }
         $test = $test && $test4d;
     } catch (Exception $e) {
     }
     // Remove the test data
     $user1->deleteVisitData();
     $user2->deleteVisitData();
     $testData->deleteAllTestPosts();
     $testObj = new kp_test("Test 4", $test, "kp_widget passed different post types tests", "kp_widget failed different post types tests");
     $testObj->render();
 }