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. // Testdata
  11. require_once dirname(__FILE__).'/trackback_data.php';
  12.  
  13. // Akismet.com API key
  14. require_once 'akismet_key.php';
  15.  
  16.     // }}}
  17.  
  18. class Services_Trackback_SpamCheck_Akismet_Test extends PHPUnit_Framework_TestCase
  19. {
  20.  
  21.     var $trackbacks = array();
  22.  
  23.     var $spamCheck;
  24.  
  25.     var $options = array();
  26.  
  27.     // {{{ setup()
  28.  
  29.     function setUp({
  30.         global $trackbackData;
  31.         global $akismetApiKey;
  32.         if (!isset($akismetApiKey|| $akismetApiKey === false{
  33.             $this->markTestSkipped("No Akismet API key defined - see test/akismet_key.php for more");
  34.         }
  35.         foreach ($trackbackData as $id => $set{
  36.             $this->trackbacks[$idServices_Trackback::create($set);
  37.             $this->trackbacks[$id]->set(
  38.                 'extra',
  39.                 array(
  40.                     'HTTP_REFERER' => 'http://www.example.com',
  41.                     'HTTP_USER_AGENT' => 'Test',
  42.                 )
  43.             );
  44.         }
  45.         $this->_options = array(
  46.             'url' => 'http://www.schlitt.info/applications/blog/',
  47.             'key' => $akismetApiKey,
  48.         );
  49.         $this->spamCheck Services_Trackback_SpamCheck::create('Akismet'$this->_options);
  50.     }
  51.  
  52.     // }}}
  53.     // {{{ tearDown()
  54.  
  55.     function tearDown({
  56.     }
  57.  
  58.     // }}}
  59.     // {{{ Test create()
  60.  
  61.     function test_create({
  62.         $realCheck = new Services_Trackback_SpamCheck_Akismet($this->_options);
  63.         $this->assertTrue($this->spamCheck == $realCheck);
  64.     }
  65.  
  66.     // }}}
  67.     // {{{ Test check()
  68.     function test_check_failure_nospam({
  69.         $this->assertFalse($this->spamCheck->check($this->trackbacks['nospam']));
  70.     }
  71.     function test_check_failure_undetected({
  72.         $this->assertFalse($this->spamCheck->check($this->trackbacks['undetected']));
  73.     }
  74.     function test_check_success_all({
  75.         $this->assertTrue($this->spamCheck->check($this->trackbacks['all']));
  76.     }
  77.     // }}}
  78.     // {{{ Test getResults()
  79.  
  80.     function test_getResults({
  81.         $this->spamCheck->check($this->trackbacks['all']);
  82.         $results $this->spamCheck->getResults();
  83.         $this->assertTrue($results[0]);
  84.     }
  85.  
  86.     // }}}
  87.     // {{{ Test reset()
  88.  
  89.     function test_reset({
  90.         $this->spamCheck->check($this->trackbacks['all']);
  91.         $this->spamCheck->reset();
  92.         $fakeCheck Services_Trackback_SpamCheck::create('Akismet'$this->_options);
  93.         $this->assertTrue($this->spamCheck == $fakeCheck);
  94.     }
  95.  
  96.     // }}}
  97.     // {{{ Test verifyKey()
  98.  
  99.     function test_verifyKey_success({
  100.         $this->assertTrue($this->spamCheck->verifyKey());
  101.     }
  102.  
  103.     function test_verifyKey_failure({
  104.         $this->spamCheck->_options['key''foobar';
  105.         $this->assertFalse($this->spamCheck->verifyKey());
  106.     }
  107.  
  108.     // }}}
  109.     // {{{ Test reportSpam()
  110.  
  111.     function test_reportSpam_success({
  112.         $this->assertTrue($this->spamCheck->submitSpam($this->trackbacks['all']));
  113.     }
  114.  
  115.     // }}}
  116.  
  117. }

Documentation generated on Mon, 11 Mar 2019 15:25:47 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.