Ejemplo n.º 1
0
 public function test1()
 {
     try {
         // Check that all the non-namespaced options have been removed
         $this->checkOption("AdminTestMode");
         $this->checkOption("AttemptToBlockBotVisits");
         $this->checkOption("CollectStatistics");
         $this->checkOption("TrackGA");
         $this->checkOption("FirstSave");
         $this->checkOption("RecommendPosts");
         $this->checkOption("RecommendPages");
         $this->checkOption("BlockedIPs");
         $this->checkOption("HideFeedbackBox");
         $this->checkOption("FeedbackMsg");
         $test = true;
     } catch (Exception $e) {
         $test = false;
     }
     $testObj = new kp_test("Test 1", $test, "plugin options updated properly", "plugin options not updated properly");
     $testObj->render();
 }
 /**
  * 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();
 }
 /**
  * Test Tracking Code
  **/
 public function test5()
 {
     $test = true;
     $currentTrackingCode = get_option("kp_TrackingCode", "");
     $currentTracking = get_option("kp_Tracking", "");
     try {
         $this->rpObj = new kp_recommendedPost($this->post);
         update_option("kp_Tracking", "custom");
         // Test simple tracking: {post_id}
         $template = "{kp:trackingcode}";
         $expected = "" . $this->post->ID . "";
         $trackingCodeTemplate = "{post_id}";
         update_option("kp_TrackingCode", $trackingCodeTemplate);
         $data = kp_renderer::returnTemplateData($this->post);
         $data["kp:trackingcode"] = kp_renderer::render($trackingCodeTemplate, $data);
         $test5a = $this->rpObj->render($template) == kp_renderer::render($template, $data) && kp_renderer::render($template, $data) == $expected;
         $test = $test5a && $test;
         $testObj = new kp_test("Test 5a", $test5a, "kp_widget passed simple Tracking Code test", "kp_widget failed simple Tracking Code test");
         $testObj->render();
         // Test <a href="#" onclick="{post_id}"></a>
         $template = "<a href=\"#\" onclick=\"{kp:trackingcode}\">Empty Link</a>";
         $expected = "<a href=\"#\" onclick=\"" . $this->post->ID . "\">Empty Link</a>";
         $trackingCodeTemplate = "{post_id}";
         update_option("kp_TrackingCode", $trackingCodeTemplate);
         $data = kp_renderer::returnTemplateData($this->post);
         $data["kp:trackingcode"] = kp_renderer::render($trackingCodeTemplate, $data);
         $test5b = $this->rpObj->render($template) == kp_renderer::render($template, $data) && kp_renderer::render($template, $data) == $expected;
         $test = $test5b && $test;
         $testObj = new kp_test("Test 5b", $test5b, "kp_widget passed simple link test", "kp_widget failed simple link test");
         $testObj->render();
         // Test <a href="#" onclick="{post_slug}"></a> with single quote
         $template = "<a href=\"#\" onclick=\"{kp:trackingcode}\">Empty Link</a>";
         $expected = "<a href=\"#\" onclick=\"" . $this->post->post_name . "\">Empty Link</a>";
         $trackingCodeTemplate = "{post_slug}";
         update_option("kp_TrackingCode", $trackingCodeTemplate);
         $data = kp_renderer::returnTemplateData($this->post);
         $data["kp:trackingcode"] = kp_renderer::render($trackingCodeTemplate, $data);
         $test5c = $this->rpObj->render($template) == kp_renderer::render($template, $data) && kp_renderer::render($template, $data) == $expected;
         $test = $test5c && $test;
         $testObj = new kp_test("Test 5c", $test5c, "kp_widget passed post_name test", "kp_widget failed post_name test");
         $testObj->render();
     } catch (Exception $e) {
         $test = false;
     }
     update_option("kp_TrackingCode", $currentTrackingCode);
     update_option("kp_Tracking", $currentTracking);
     $testObj = new kp_test("Test 5", $test, "kp_widget passed Tracking Code tests", "kp_widget failed Tracking Code tests");
     $testObj->render();
 }
Ejemplo n.º 4
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();
 }
Ejemplo n.º 5
0
 /**
  * Test if the renderer works with if statements (with regular expressions as keys)
  **/
 public function test16()
 {
     try {
         $expected = "asdf";
         $key = "{\\d}";
         $template = "{if " . $key . "}" . $expected . "{/if " . $key . "}";
         $data = array($key => true);
         $test = kp_renderer::render($template, $data) == $expected;
     } catch (Exception $e) {
         $test = false;
     }
     $testObj = new kp_test("Test 16", $test, "renderer passed if statements (with regular expressions as keys)", "renderer failed if statements (with regular expressions as keys)");
     $testObj->render();
 }