SourPHPTest
Current file: /var/www/github/SourPHP/tests/SourPHPCoreTest.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 21 / 21
100.00%100.00%
100.00% 84 / 84
 
SourPHPCoreTest
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 21 / 21
100.00%100.00%
100.00% 84 / 84
 function setUp()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 2 / 2
 function IfDataReturnedOnFetch()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 3 / 3
 function IfNoUrlSentToFetch()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 3 / 3
 function FetchingIntegerId()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 3 / 3
 function FetchingStringButCanBeCastToAnIntegerId()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 3 / 3
 function FetchingNonInteger()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 3 / 3
 function FetchEntry()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 3 / 3
 function FetchEntryOnSecondPage()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 3 / 3
 function FetchNullEntry()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 3 / 3
 function FetchEntryWhichHasTurkishChars()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 3 / 3
 function ToCreateDomDocumentFromData()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 5 / 5
 function ToCreateDomDocumentFromDataIfDataIsNull()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 3 / 3
 function XpathQuery()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 7 / 7
 function GetEntryTitleFromDoc()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 6 / 6
 function GetEntryTitleFromADocWhichDoesntHaveTitleField()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 5 / 5
 function GetNumberOfPages()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 5 / 5
 function GetNumberOfPagesForAnEntryWhichNotExists()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 5 / 5
 function GetNumberOfPagesForAnEntryWhichContainsTurkishCharsAndWhitespace()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 5 / 5
 function GetContentsOfEntriesFromDoc()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 6 / 6
 function GetContentsOfEntriesFromDocWhichDoesntHaveAnIdField()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 5 / 5
 function GetContentsOfEntriesFromNullDoc()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 3 / 3


       1                 : <?                                                                                                            
       2                 : /**                                                                                                           
       3                 :  * SourPHPTest                                                                                                
       4                 :  *                                                                                                            
       5                 :  * LICENSE                                                                                                    
       6                 :  *                                                                                                            
       7                 :  * This file can be distributed under terms of LGPL                                                           
       8                 :  *                                                                                                            
       9                 :  * @package    SourPHP                                                                                        
      10                 :  * @copyright  Osman Yuksel                                                                                   
      11                 :  * @LICENSE    http://www.gnu.org/licenses/lgpl-3.0.txt                                                       
      12                 :  * @version    0.1                                                                                            
      13                 :  */                                                                                                           
      14                 :                                                                                                               
      15                 :                                                                                                               
      16                 : include_once ("../classes/SourPHPCore.php");                                                                  
      17                 :                                                                                                               
      18                 : /**                                                                                                           
      19                 :  * SourPHPTest                                                                                                
      20                 :  *                                                                                                            
      21                 :  * Test Cases for SourPHP                                                                                     
      22                 :  * @author    Osman Yuksel <yuxel |AT| sonsuzdongu |DOT| com>                                                 
      23                 :  */                                                                                                           
      24                 : class SourPHPCoreTest extends PHPUnit_Framework_TestCase                                                      
      25                 : {                                                                                                             
      26                 :                                                                                                               
      27                 :     function setUp(){                                                                                         
      28              27 :         $this->obj = new SourPHPCore();                                                                       
      29              27 :     }                                                                                                         
      30                 :                                                                                                               
      31                 :                                                                                                               
      32                 :                                                                                                               
      33                 :     /**                                                                                                       
      34                 :      * @test                                                                                                  
      35                 :      */                                                                                                       
      36                 :     function IfDataReturnedOnFetch() {                                                                        
      37               1 :         $result = $this->obj->fetchUrl("http://sozluk.sourtimes.org/show.asp?t=madde+97%2F%2317410156&pad=1");
      38               1 :         $this->assertNotNull ($result);                                                                       
      39               1 :     }                                                                                                         
      40                 :                                                                                                               
      41                 :     /**                                                                                                       
      42                 :      * @test                                                                                                  
      43                 :      */                                                                                                       
      44                 :     function IfNoUrlSentToFetch(){                                                                            
      45               1 :         $result = $this->obj->fetchUrl("invalid-url");                                                        
      46               1 :         $this->assertFalse ($result);                                                                         
      47                 :                                                                                                               
      48               1 :     }                                                                                                         
      49                 :                                                                                                               
      50                 :                                                                                                               
      51                 :     /**                                                                                                       
      52                 :      * @test                                                                                                  
      53                 :      */                                                                                                       
      54                 :     function FetchingIntegerId() {                                                                            
      55               1 :         $result = $this->obj->fetchId(17410156);                                                              
      56               1 :         $this->assertNotNull ($result);                                                                       
      57               1 :     }                                                                                                         
      58                 :                                                                                                               
      59                 :     /**                                                                                                       
      60                 :      * @test                                                                                                  
      61                 :      * test if paramter is a string but can be casted as integer                                              
      62                 :      */                                                                                                       
      63                 :     function FetchingStringButCanBeCastToAnIntegerId() {                                                      
      64               1 :         $result = $this->obj->fetchId("17410156");                                                            
      65               1 :         $this->assertNotNull ($result);                                                                       
      66               1 :     }                                                                                                         
      67                 :                                                                                                               
      68                 :     /**                                                                                                       
      69                 :      * @test                                                                                                  
      70                 :      */                                                                                                       
      71                 :     function FetchingNonInteger() {                                                                           
      72               1 :         $result = $this->obj->fetchId("this_is_not_valid");                                                   
      73               1 :         $this->assertFalse ($result);                                                                         
      74               1 :     }                                                                                                         
      75                 :                                                                                                               
      76                 :     /**                                                                                                       
      77                 :      * @test                                                                                                  
      78                 :      */                                                                                                       
      79                 :     function FetchEntry() {                                                                                   
      80               1 :         $result = $this->obj->fetchEntry("php");                                                              
      81               1 :         $this->assertNotNull ($result);                                                                       
      82               1 :     }                                                                                                         
      83                 :                                                                                                               
      84                 :     /**                                                                                                       
      85                 :      * @test                                                                                                  
      86                 :      */                                                                                                       
      87                 :     function FetchEntryOnSecondPage() {                                                                       
      88               1 :         $result = $this->obj->fetchEntry("php",2);                                                            
      89               1 :         $this->assertNotNull ($result);                                                                       
      90               1 :     }                                                                                                         
      91                 :                                                                                                               
      92                 :                                                                                                               
      93                 :                                                                                                               
      94                 :     /**                                                                                                       
      95                 :      * @test                                                                                                  
      96                 :      */                                                                                                       
      97                 :     function FetchNullEntry(){                                                                                
      98               1 :         $result = $this->obj->fetchEntry(null);                                                               
      99               1 :         $this->assertFalse ($result);                                                                         
     100               1 :     }                                                                                                         
     101                 :                                                                                                               
     102                 :     /**                                                                                                       
     103                 :      * @test                                                                                                  
     104                 :      */                                                                                                       
     105                 :     function FetchEntryWhichHasTurkishChars() {                                                               
     106               1 :         $result = $this->obj->fetchEntry("neşet ertaş");                                                    
     107               1 :         $this->assertNotNull ($result);                                                                       
     108               1 :     }                                                                                                         
     109                 :                                                                                                               
     110                 :                                                                                                               
     111                 :                                                                                                               
     112                 :                                                                                                               
     113                 :     /**                                                                                                       
     114                 :      * @test                                                                                                  
     115                 :      * test if document created successfully                                                                  
     116                 :      */                                                                                                       
     117                 :     function ToCreateDomDocumentFromData() {                                                                  
     118               1 :         $data = $this->obj->fetchId(17410156);                                                                
     119               1 :         $returned = $this->obj->createDomDocumentFromData($data);                                             
     120                 :                                                                                                               
     121               1 :         $result =($returned instanceof DomDocument)?true:false;                                               
     122               1 :         $this->assertTrue($result);                                                                           
     123               1 :     }                                                                                                         
     124                 :                                                                                                               
     125                 :     /**                                                                                                       
     126                 :      * @test                                                                                                  
     127                 :      * test if document created successfully                                                                  
     128                 :      */                                                                                                       
     129                 :     function ToCreateDomDocumentFromDataIfDataIsNull() {                                                      
     130               1 :         $returned = $this->obj->createDomDocumentFromData(null);                                              
     131               1 :         $this->assertFalse($returned);                                                                        
     132               1 :     }                                                                                                         
     133                 :                                                                                                               
     134                 :                                                                                                               
     135                 :                                                                                                               
     136                 :                                                                                                               
     137                 :                                                                                                               
     138                 :     /**                                                                                                       
     139                 :      * @test                                                                                                  
     140                 :      */                                                                                                       
     141                 :     function XpathQuery(){                                                                                    
     142               1 :         $contentOfFirstDiv="hello";                                                                           
     143               1 :         $data = "<div id=\"test\">$contentOfFirstDiv</div><div>Second content</div>";                         
     144               1 :         $doc = $this->obj->createDomDocumentFromData($data);                                                  
     145                 :                                                                                                               
     146               1 :         $returned = $this->obj->XPathQueryToDoc($doc, "*//div");                                              
     147                 :                                                                                                               
     148               1 :         $result =($returned instanceof DomNodeList)?true:false;                                               
     149                 :                                                                                                               
     150               1 :         $this->assertTrue($result);                                                                           
     151               1 :     }                                                                                                         
     152                 :                                                                                                               
     153                 :                                                                                                               
     154                 :     /**                                                                                                       
     155                 :      * @test                                                                                                  
     156                 :      * this should return "php" as title                                                                      
     157                 :      */                                                                                                       
     158                 :     function GetEntryTitleFromDoc() {                                                                         
     159               1 :         $entryId = 8102; //entry for "php"                                                                     
     160               1 :         $data = $this->obj->fetchId(8102);                                                                    
     161               1 :         $doc = $this->obj->createDomDocumentFromData($data);                                                  
     162                 :                                                                                                               
     163               1 :         $title = $this->obj->getEntryTitleFromDoc($doc);                                                      
     164                 :                                                                                                               
     165               1 :         $this->assertEquals($title, "php");                                                                   
     166                 :                                                                                                               
     167               1 :     }                                                                                                         
     168                 :                                                                                                               
     169                 :                                                                                                               
     170                 :     /**                                                                                                       
     171                 :      * @test                                                                                                  
     172                 :      */                                                                                                       
     173                 :     function GetEntryTitleFromADocWhichDoesntHaveTitleField(){                                                
     174               1 :         $data = "<span>Foobar</span>";                                                                        
     175                 :                                                                                                               
     176               1 :         $doc = $this->obj->createDomDocumentFromData($data);                                                  
     177               1 :         $title = $this->obj->getEntryTitleFromDoc($doc);                                                      
     178                 :                                                                                                               
     179               1 :         $this->assertFalse($title);                                                                           
     180                 :                                                                                                               
     181                 :                                                                                                               
     182               1 :     }                                                                                                         
     183                 :                                                                                                               
     184                 :                                                                                                               
     185                 :     /**                                                                                                       
     186                 :      * @test                                                                                                  
     187                 :      * "php" entry has 7 pages for now                                                                        
     188                 :      * @fixme this could change later                                                                         
     189                 :      */                                                                                                       
     190                 :     function GetNumberOfPages(){                                                                              
     191               1 :         $data = $this->obj->fetchEntry("php");                                                                
     192               1 :         $doc = $this->obj->createDomDocumentFromData($data);                                                  
     193                 :                                                                                                               
     194               1 :         $numOfPages = $this->obj->getNumberOfPages($doc);                                                     
     195                 :                                                                                                               
     196               1 :         $this->assertEquals($numOfPages, 7);                                                                  
     197                 :                                                                                                               
     198               1 :     }                                                                                                         
     199                 :                                                                                                               
     200                 :     /**                                                                                                       
     201                 :      * @test                                                                                                  
     202                 :      * there's no such php_thats_not_exists entry so page num should be 0                                     
     203                 :      */                                                                                                       
     204                 :     function GetNumberOfPagesForAnEntryWhichNotExists(){                                                      
     205               1 :         $data = $this->obj->fetchEntry("php_thats_not_exist");                                                
     206               1 :         $doc = $this->obj->createDomDocumentFromData($data);                                                  
     207                 :                                                                                                               
     208               1 :         $numOfPages = $this->obj->getNumberOfPages($doc);                                                     
     209                 :                                                                                                               
     210               1 :         $this->assertEquals($numOfPages, 0);                                                                  
     211                 :                                                                                                               
     212               1 :     }                                                                                                         
     213                 :                                                                                                               
     214                 :     /**                                                                                                       
     215                 :      * @test                                                                                                  
     216                 :      * 'neşet ertaş' page (turkish chars and white space tested)                                            
     217                 :      */                                                                                                       
     218                 :     function GetNumberOfPagesForAnEntryWhichContainsTurkishCharsAndWhitespace(){                              
     219               1 :         $data = $this->obj->fetchEntry("neşet ertaş");                                                      
     220               1 :         $doc = $this->obj->createDomDocumentFromData($data);                                                  
     221                 :                                                                                                               
     222               1 :         $numOfPages = $this->obj->getNumberOfPages($doc);                                                     
     223                 :                                                                                                               
     224               1 :         $this->assertEquals($numOfPages, 10);                                                                 
     225                 :                                                                                                               
     226               1 :     }                                                                                                         
     227                 :                                                                                                               
     228                 :                                                                                                               
     229                 :     /**                                                                                                       
     230                 :      * @test                                                                                                  
     231                 :      */                                                                                                       
     232                 :     function GetContentsOfEntriesFromDoc() {                                                                  
     233               1 :         $data = $this->obj->fetchEntry("neşet ertaş");                                                      
     234               1 :         $doc = $this->obj->createDomDocumentFromData($data);                                                  
     235                 :                                                                                                               
     236               1 :         $entries = $this->obj->getContentOfEntriesFromDoc($doc);                                              
     237                 :                                                                                                               
     238               1 :         $this->assertArrayHasKey('0', $entries);                                                              
     239               1 :         $this->assertArrayHasKey('entryId', $entries[0]);                                                     
     240                 :                                                                                                               
     241               1 :     }                                                                                                         
     242                 :                                                                                                               
     243                 :                                                                                                               
     244                 :     /**                                                                                                       
     245                 :      * @test                                                                                                  
     246                 :      */                                                                                                       
     247                 :     function GetContentsOfEntriesFromDocWhichDoesntHaveAnIdField() {                                          
     248               1 :         $data = $this->obj->fetchEntry("this entry will never exists on eksisozluk foobar");                  
     249               1 :         $doc = $this->obj->createDomDocumentFromData($data);                                                  
     250               1 :         $entries = $this->obj->getContentOfEntriesFromDoc($doc);                                              
     251               1 :         $this->assertFalse($entries);                                                                         
     252                 :                                                                                                               
     253                 :                                                                                                               
     254               1 :     }                                                                                                         
     255                 :                                                                                                               
     256                 :     /**                                                                                                       
     257                 :      * @test                                                                                                  
     258                 :      */                                                                                                       
     259                 :     function GetContentsOfEntriesFromNullDoc() {                                                              
     260               1 :         $entries = $this->obj->getContentOfEntriesFromDoc(null);                                              
     261               1 :         $this->assertFalse($entries);                                                                         
     262               1 :     }                                                                                                         
     263                 :                                                                                                               
     264                 :                                                                                                               
     265                 : }                                                                                                             
     266                 :                                                                                                               

Generated by PHPUnit 3.4.1 and Xdebug 2.0.5 at Sat Dec 19 12:27:11 EET 2009.