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

Source for file Services_Trackback_Test.php

Documentation is available at Services_Trackback_Test.php

  1. <?php
  2. require_once 'Services/Trackback.php';
  3. require_once 'Services/Trackback/SpamCheck.php';
  4. require_once 'Services/Trackback/SpamCheck/Mock.php';
  5.  
  6. require_once 'PHPUnit/Framework/TestCase.php';
  7.  
  8. require_once dirname(__FILE__).'/trackback_data.php';
  9.  
  10. class Services_Trackback_Test extends PHPUnit_Framework_TestCase
  11. {
  12.  
  13.     var $xml;
  14.  
  15.     function setUp({
  16.         $path dirname(__FILE__'/data/Services_Trackback_Test/';
  17.  
  18.         $dir = new DirectoryIterator($path);
  19.         $this->xml = array();
  20.         foreach ($dir as $file{
  21.             @list($testName$extensionexplode('.'(string)$file);
  22.  
  23.             if ($extension !== 'xml'{
  24.                 continue;
  25.             }
  26.             $full_path $path "/" $file;
  27.  
  28.             $xml file_get_contents($full_path);
  29.             $this->xml[$testNametrim($xml);
  30.         }
  31.     }
  32.  
  33.     function testCreate()
  34.     {
  35.         global $trackbackData;
  36.  
  37.         $options = array(
  38.             'strictness'        => SERVICES_TRACKBACK_STRICTNESS_HIGH,
  39.             'timeout'           => 10,
  40.             'fetchlines'        => 100,
  41.             'fetchextra'        => true,
  42.             'httprequest'       => array(
  43.                 'allowRedirects'    => false,
  44.                 'maxRedirects'      => 0,
  45.                 'useragent'         => 'Mozilla 10.0',
  46.             ),
  47.         );
  48.  
  49.         $fakeTrack = new Services_Trackback;
  50.  
  51.         $fakeTrack->_options = $options;
  52.         $fakeTrack->_data    = $trackbackData['nospam'];
  53.  
  54.         $this->assertTrue(Services_Trackback::create($trackbackData['nospam']$options== $fakeTrack);
  55.     }
  56.  
  57.     function testSetOptionsSuccess()
  58.     {
  59.         $options = array(
  60.             'strictness'        => SERVICES_TRACKBACK_STRICTNESS_HIGH,
  61.             'timeout'           => 10,
  62.             'fetchlines'        => 100,
  63.             'fetchextra'        => true,
  64.             'httprequest'       => array(
  65.                 'allowRedirects'    => false,
  66.                 'maxRedirects'      => 0,
  67.                 'useragent'         => 'Mozilla 10.0',
  68.             ),
  69.         );
  70.  
  71.         $fakeTrack = new Services_Trackback;
  72.         $realTrack = new Services_Trackback;
  73.  
  74.         $fakeTrack->_options = $options;
  75.         $realTrack->setOptions($options);
  76.  
  77.         $this->assertTrue($realTrack == $fakeTrack);
  78.     }
  79.  
  80.  
  81.     function testGetOptionsSuccess()
  82.     {
  83.         $options = array(
  84.             'strictness'        => SERVICES_TRACKBACK_STRICTNESS_HIGH,
  85.             'timeout'           => 10,
  86.             'fetchlines'        => 100,
  87.             'httpRequest'       => array(
  88.                 'allowRedirects'    => false,
  89.                 'maxRedirects'      => 0,
  90.                 'useragent'         => 'Mozilla 10.0',
  91.             ),
  92.         );
  93.  
  94.         $track = new Services_Trackback;
  95.  
  96.         $track->_options = $options;
  97.  
  98.         $this->assertTrue($track->getOptions(== $options);
  99.     }
  100.  
  101.  
  102.     function testAutodiscoverSuccess()
  103.     {
  104.         $data = array(
  105.             'id' => 'Test',
  106.             'url' => 'http://pear.php.net/package/net_ftp'
  107.         );
  108.  
  109.         $track1 Services_Trackback::create($data);
  110.         $track1->autodiscover();
  111.  
  112.         $data['trackback_url''http://pear.php.net/trackback/trackback.php?id=Net_FTP';
  113.  
  114.         $track2 Services_Trackback::create($data);
  115.  
  116.         $this->assertTrue($track1 == $track2);
  117.     }
  118.  
  119.     function testAutodiscoverFailure()
  120.     {
  121.         $data = array(
  122.             'id' => 'Test',
  123.             'url' => 'http://pear.php.net/'
  124.         );
  125.  
  126.         $track1 Services_Trackback::create($data);
  127.         $res    $track1->autodiscover();
  128.         $this->assertTrue(PEAR::isError($res));
  129.     }
  130.  
  131.     function testSend()
  132.     {
  133.         global $trackbackData;
  134.         $track Services_Trackback::create($trackbackData['nospam']);
  135.     }
  136.  
  137.  
  138.     function testGetAutodiscoveryCodeNoComments()
  139.     {
  140.         global $trackbackData;
  141.         $data $trackbackData['nospam'];
  142.  
  143.         $xml $this->xml['testGetAutodiscoveryCodeNoComments'];
  144.         $xml sprintf($xml$data['url']$data['url']$data['title']$data['trackback_url']);
  145.  
  146.         $track Services_Trackback::create($data);
  147.  
  148.         $result trim($track->getAutodiscoveryCode(false));
  149.  
  150.         $this->assertSame($xml$result);
  151.     }
  152.  
  153.     function testGetAutodiscoveryCodeComments()
  154.     {
  155.         global $trackbackData;
  156.         $data $trackbackData['nospam'];
  157.  
  158.         $xml $this->xml['testGetAutodiscoveryCodeComments'];
  159.         $xml sprintf($xml$data['url']$data['url']$data['title']$data['trackback_url']);
  160.  
  161.         $track Services_Trackback::create($data);
  162.  
  163.         $result trim($track->getAutodiscoveryCode());
  164.  
  165.         $this->assertSame($xml$result);
  166.     }
  167.  
  168.  
  169.     function testReceive()
  170.     {
  171.         global $trackbackData;
  172.         $postData $trackbackData['nospam'];
  173.         $data $postData;
  174.  
  175.         $data['id'= 1;
  176.         // Not set during receive()
  177.         // unset($data['host']);
  178.         unset($data['trackback_url']);
  179.  
  180.         $recTrack Services_Trackback::create(array('id' => 1));
  181.         $recTrack->receive($postData);
  182.  
  183.         $fakeTrack Services_Trackback::create($data);
  184.         $fakeTrack->set('extra'$_SERVER);
  185.  
  186.         $this->assertTrue($recTrack == $fakeTrack);
  187.     }
  188.  
  189.  
  190.     function testGetResponseSuccess()
  191.     {
  192.         $xml $this->xml['testGetResponseSuccess'];
  193.         $this->assertTrue(!empty($xml)"Test was unable to locate sample data");
  194.  
  195.         $generated_response Services_Trackback::getResponseSuccess();
  196.         $this->assertSame($xml$generated_response);
  197.     }
  198.  
  199.     function testGetResponseError()
  200.     {
  201.         $xml $this->xml['testGetResponseError'];
  202.         $this->assertTrue(!empty($xml)"Test was unable to locate sample data");
  203.  
  204.         $generated_error Services_Trackback::getResponseError('Me & you'-2);
  205.         $this->assertSame($xml$generated_error);
  206.     }
  207.  
  208.     function testAddSpamCheckSuccess()
  209.     {
  210.         $trackback = new Services_Trackback();
  211.         $spamCheck = new Services_Trackback_SpamCheck_Mock();
  212.  
  213.         $result $trackback->addSpamCheck($spamCheck);
  214.         $this->assertFalse(PEAR::isError($result));
  215.     }
  216.  
  217.     function testAddSpamCheckFailure()
  218.     {
  219.         $trackback = new Services_Trackback();
  220.         $spamCheck = new Services_Trackback();
  221.         $this->assertTrue(PEAR::isError($trackback->addSpamCheck($spamCheck)));
  222.     }
  223.  
  224.     function testCreateSpamCheckSuccess()
  225.     {
  226.         global $trackbackData;
  227.         $trackback = new Services_Trackback($trackbackData['nospam']);
  228.         $spamCheck Services_Trackback_SpamCheck::create('DNSBL');
  229.         $this->assertTrue($trackback->createSpamCheck('DNSBL'== $spamCheck);
  230.     }
  231.  
  232.     function testCreateSpamCheckFailure()
  233.     {
  234.         global $trackbackData;
  235.         $trackback = new Services_Trackback($trackbackData['nospam']);
  236.         $spamCheck Services_Trackback_SpamCheck::create('DNS');
  237.         $this->assertTrue(PEAR::isError($spamCheck));
  238.     }
  239.  
  240.     function testRemoveSpamCheckSuccess()
  241.     {
  242.         $trackback = new Services_Trackback();
  243.         $spamCheck = new Services_Trackback_SpamCheck_Mock();
  244.         $trackback->addSpamCheck($spamCheck);
  245.         
  246.         $this->assertFalse(PEAR::isError($result)"Failed to add SpamCheck, can't complete test");
  247.  
  248.         $result $trackback->removeSpamCheck($spamCheck);
  249.         $this->assertFalse(PEAR::isError($result));
  250.     }
  251.  
  252.     function testRemoveSpamCheckFailure()
  253.     {
  254.         $trackback = new Services_Trackback();
  255.         $spamCheck = new Services_Trackback_SpamCheck();
  256.         $trackback->addSpamCheck($spamCheck);
  257.         $spamCheck2 = new Services_Trackback_SpamCheck();
  258.         $this->assertTrue(PEAR::isError($trackback->removeSpamCheck($spamCheck2)));
  259.     }
  260.  
  261.     function testFromArray()
  262.     {
  263.         global $trackbackData;
  264.         $fakeTrack = new Services_Trackback;
  265.         $fakeTrack->_data = $trackbackData['nospam'];
  266.         $realTrack = new Services_Trackback;
  267.         $realTrack->_fromArray($trackbackData['nospam']);
  268.         $this->assertTrue($realTrack == $fakeTrack);
  269.     }
  270.  
  271.     function testGetContent()
  272.     {
  273.         $this->markTestSkipped("See Bug #13456");
  274.  
  275.         global $trackbackData;
  276.         $trackback Services_Trackback::create($trackbackData['nospam']);
  277.         $url 'http://schlitt.info/projects/PEAR/Services_Trackback/test_getContent.txt';
  278.         $fakeRes "Test text.\n";
  279.  
  280.         $res $trackback->_getContent($url);
  281.  
  282.         if (PEAR::isError($res)) {
  283.             $this->fail($res->getMessage());
  284.             return;
  285.         }
  286.  
  287.         $this->assertTrue(trim($res== trim($fakeRes));
  288.     }
  289.  
  290.     function testGetEncodedData()
  291.     {
  292.         $in = array(
  293.             'foo' => 'bar & baz',
  294.             'bar' => 'foo << baz',
  295.             'baz' => 'foo && bar'
  296.         );
  297.  
  298.         $out = array(
  299.             'foo' => 'bar &amp; baz',
  300.             'bar' => 'foo &lt;&lt; baz',
  301.             'baz' => 'foo &amp;&amp; bar'
  302.         );
  303.  
  304.         $this->assertTrue(Services_Trackback::_getEncodedData(array('foo''bar''baz')$in== $out);
  305.     }
  306.  
  307.     function testGetDecodedData()
  308.     {
  309.         $in = array(
  310.             'foo' => 'bar & baz',
  311.             'bar' => 'foo << baz',
  312.             'baz' => 'foo && bar'
  313.         );
  314.  
  315.         $out = array(
  316.             'foo' => 'bar & baz',
  317.             'baz' => 'foo && bar'
  318.         );
  319.  
  320.         $this->assertTrue(Services_Trackback::_getDecodedData(array('foo''baz')$in== $out);
  321.     }
  322.  
  323.     function testCheckDataTrue()
  324.     {
  325.         $keys = array('id''test');
  326.         $data = array('id' => 1'test' => 'x''test2' => 0);
  327.         $this->assertTrue(Services_Trackback::_checkData($keys$data));
  328.     }
  329.  
  330.     function testCheckDataFalse()
  331.     {
  332.         $keys = array('id''test');
  333.         $data = array('id' => 1'test2' => 0);
  334.         $this->assertTrue(PEAR::isError(Services_Trackback::_checkData($keys$data)));
  335.     }
  336.  
  337.  
  338.     function testCheckURLsTrue1()
  339.     {
  340.         $strictness SERVICES_TRACKBACK_STRICTNESS_LOW;
  341.         $url1 "http://www.example.com/trackback/index.php";
  342.         $url2 "http://www.example.net/trackbike/index.htm";
  343.         $this->assertTrue(Services_Trackback::_checkURLs($url1$url2$strictness));
  344.     }
  345.  
  346.     function testCheckURLsTrue2()
  347.     {
  348.         $strictness SERVICES_TRACKBACK_STRICTNESS_MIDDLE;
  349.         $url1 "http://www.example.com/trackback/index.php";
  350.         $url2 "http://www.example.com/trackbike/index.htm";
  351.         $this->assertTrue(Services_Trackback::_checkURLs($url1$url2$strictness));
  352.     }
  353.  
  354.     function testCheckURLsTrue3()
  355.     {
  356.         $strictness SERVICES_TRACKBACK_STRICTNESS_HIGH;
  357.         $url1 "http://www.example.com/trackback/index.php";
  358.         $url2 "http://www.example.com/trackback/index.php";
  359.         $this->assertTrue(Services_Trackback::_checkURLs($url1$url2$strictness));
  360.     }
  361.  
  362.  
  363.     function testCheckURLsFalse1()
  364.     {
  365.         // No real test, should always return true
  366.         $strictness SERVICES_TRACKBACK_STRICTNESS_LOW;
  367.         $url1 "http://www.example.com/trackback/index.php";
  368.         $url2 "https://test.net/trackbike/index.htm";
  369.         $this->assertTrue(Services_Trackback::_checkURLs($url1$url2$strictness));
  370.     }
  371.  
  372.     function testCheckURLsFalse2()
  373.     {
  374.         $strictness SERVICES_TRACKBACK_STRICTNESS_MIDDLE;
  375.         $url1 "http://www.example.com/trackback/index.php";
  376.         $url2 "http://www.example.net/trackback/index.php";
  377.         $this->assertTrue(PEAR::isError(Services_Trackback::_checkURLs($url1$url2$strictness)));
  378.     }
  379.  
  380.     function testCheckURLsFalse3()
  381.     {
  382.         $strictness SERVICES_TRACKBACK_STRICTNESS_HIGH;
  383.         $url1 "http://www.example.com/trackback/index.php";
  384.         $url2 "http://www.example.com/trackback/index.htm";
  385.         $this->assertTrue(PEAR::isError(Services_Trackback::_checkURLs($url1$url2$strictness)));
  386.     }
  387.  
  388.     function testCheckURLsInvalid1()
  389.     {
  390.         // No real test, should always return true
  391.         $strictness SERVICES_TRACKBACK_STRICTNESS_LOW;
  392.  
  393.         $url1 "http://www.example.com/trackback/index.php";
  394.         $url2 "https://test.net/trackbike/index.htm";
  395.  
  396.         $this->assertTrue(Services_Trackback::_checkURLs($url1$url2$strictness));
  397.     }
  398.  
  399.     function testCheckURLsInvalid2()
  400.     {
  401.         $strictness SERVICES_TRACKBACK_STRICTNESS_MIDDLE;
  402.  
  403.         $url1 "http:///trackback/index.php";
  404.         $url2 "http://www.example.net/trackback/index.php";
  405.  
  406.         $this->assertTrue(PEAR::isError(Services_Trackback::_checkURLs($url1$url2$strictness)));
  407.     }
  408.  
  409.     function testCheckURLsInvalid3()
  410.     {
  411.         // No real test, URLs are not invalid, but unequal
  412.         $strictness SERVICES_TRACKBACK_STRICTNESS_HIGH;
  413.  
  414.         $url1 "http://www.example.com/trackback/index.php";
  415.         $url2 "http://www.example.com/trackback/index.htm";
  416.  
  417.         $this->assertTrue(PEAR::isError(Services_Trackback::_checkURLs($url1$url2$strictness)));
  418.     }
  419.  
  420.     function testInterpretTrackbackResponseSuccess()
  421.     {
  422.         $xml $this->xml['testInterpretTrackbackResponseSuccess'];
  423.         $res Services_Trackback::_interpretTrackbackResponse($xml);
  424.         $this->assertTrue($res);
  425.     }
  426.  
  427.     function testInterpretTrackbackResponseFailure()
  428.     {
  429.         $xml $this->xml['testInterpretTrackbackResponseFailure'];
  430.         $res Services_Trackback::_interpretTrackbackResponse($xml);
  431.         $this->assertTrue(PEAR::isError($res));
  432.     }
  433.  
  434.     function testInterpretTrackbackResponseInvalid1()
  435.     {
  436.         $xml $this->xml['testInterpretTrackbackResponseInvalid1'];
  437.         $res Services_Trackback::_interpretTrackbackResponse($xml);
  438.         $this->assertTrue(PEAR::isError($res));
  439.     }
  440.  
  441.     function testInterpretTrackbackResponseInvalid2()
  442.     {
  443.         $xml $this->xml['testInterpretTrackbackResponseInvalid2'];
  444.  
  445.         $res Services_Trackback::_interpretTrackbackResponse($xml);
  446.         $this->assertTrue(PEAR::isError($res));
  447.     }
  448. }

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