Services_Trackback
[ class tree: Services_Trackback ] [ index: Services_Trackback ] [ all elements ]

Source for file Services_Trackback_SpamCheck_Akismet_Test.php

Documentation is available at Services_Trackback_SpamCheck_Akismet_Test.php

  1. <?php
  2.  
  3.     // {{{ require_once
  4.  
  5. // Services_Trackback classes
  6. require_once 'Services/Trackback.php';
  7. require_once 'Services/Trackback/SpamCheck.php';
  8. require_once 'Services/Trackback/SpamCheck/Akismet.php';
  9.  
  10. // Unittest suite
  11. require_once 'PHPUnit.php';
  12.  
  13. // Testdata
  14. require_once dirname(__FILE__).'/trackback_data.php';
  15.  
  16. // Akismet.com API key
  17. require_once 'test/akismet_key.php';
  18.  
  19.     // }}}
  20.  
  21. class Webservices_Trackback_SpamCheck_Akismet_TestCase extends PHPUnit_TestCase
  22. {
  23.  
  24.     var $trackbacks = array();
  25.  
  26.     var $spamCheck;
  27.  
  28.     var $options = array();
  29.     
  30.     // {{{ Webservices_Trackback_SpamCheck_Akismet_TestCase()
  31.     
  32.     // constructor of the test suite
  33.     function Webservices_Trackback_SpamCheck_Akismet_TestCase($name{
  34.        $this->PHPUnit_TestCase($name);
  35.     }
  36.  
  37.     // }}}
  38.     // {{{ setup()
  39.     
  40.     function setUp({
  41.         global $trackbackData;
  42.         global $akismetApiKey;
  43.         if (!isset($akismetApiKey|| $akismetApiKey === false{
  44.             return false;
  45.         }
  46.         foreach ($trackbackData as $id => $set{
  47.             $this->trackbacks[$idServices_Trackback::create($set);
  48.             $this->trackbacks[$id]->set(
  49.                 'extra'
  50.                 array(
  51.                     'REFERER' => 'http://www.example.com',
  52.                     'USER_AGENT' => 'Test',
  53.                 )
  54.             );
  55.         }
  56.         $this->_options = array(
  57.             'url' => 'http://www.schlitt.info/applications/blog/',
  58.             'key' => $akismetApiKey,
  59.         );
  60.         $this->spamCheck Services_Trackback_SpamCheck::create('Akismet'$this->_options);
  61.     }
  62.  
  63.     // }}}
  64.     // {{{ tearDown()
  65.     
  66.     function tearDown({
  67.     }
  68.  
  69.     // }}}
  70.     // {{{ Test create()
  71.  
  72.     function test_create({
  73.         $realCheck = new Services_Trackback_SpamCheck_Akismet($this->_options);
  74.         $this->assertTrue($this->spamCheck == $realCheck);
  75.     }
  76.  
  77.     // }}}
  78.     // {{{ Test check()
  79.     function test_check_failure_nospam({
  80.         $this->assertFalse($this->spamCheck->check($this->trackbacks['nospam']));
  81.     }
  82.     function test_check_failure_undetected({
  83.         $this->assertFalse($this->spamCheck->check($this->trackbacks['undetected']));
  84.     }
  85.     function test_check_success_all({
  86.         $this->assertTrue($this->spamCheck->check($this->trackbacks['all']));
  87.     }
  88.     // }}}
  89.     // {{{ Test getResults()
  90.  
  91.     function test_getResults({
  92.         $this->spamCheck->check($this->trackbacks['all']);
  93.         $results $this->spamCheck->getResults();
  94.         $this->assertTrue($results[0]);
  95.     }
  96.  
  97.     // }}}
  98.     // {{{ Test reset()
  99.  
  100.     function test_reset({
  101.         $this->spamCheck->check($this->trackbacks['all']);
  102.         $this->spamCheck->reset();
  103.         $fakeCheck Services_Trackback_SpamCheck::create('Akismet'$this->_options);
  104.         $this->assertTrue($this->spamCheck == $fakeCheck);
  105.     }
  106.  
  107.     // }}}
  108.     // {{{ Test verifyKey()
  109.  
  110.     function test_verifyKey_success({
  111.         $this->assertTrue($this->spamCheck->verifyKey());
  112.     }
  113.     
  114.     function test_verifyKey_failure({
  115.         $this->spamCheck->_options['key''foobar';
  116.         $this->assertFalse($this->spamCheck->verifyKey());
  117.     }
  118.  
  119.     // }}}
  120.     // {{{ Test reportSpam()
  121.  
  122.     function test_reportSpam_success({
  123.         $this->assertTrue($this->spamCheck->submitSpam($this->trackbacks['all']));
  124.     }
  125.  
  126.     // }}}
  127.  
  128. }
  129.  
  130. if (isset($akismetApiKey&& $akismetApiKey !== false{
  131.     $suite  = new PHPUnit_TestSuite("Webservices_Trackback_SpamCheck_Akismet_TestCase");
  132.     $result = PHPUnit::run($suite);
  133.     echo $result->toString();
  134. else {
  135.     echo 'Skipped test case "Webservices_Trackback_SpamCheck_Akismet_TestCase" because Akismet API key is missing. Please configure it in test/akismet_key.php!';
  136. }
  137.  
  138. ?>

Documentation generated on Mon, 11 Mar 2019 14:36:53 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.