Login   Register  
PHP Classes
elePHPant
Icontem

File: test/main_test.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Tufan Baris YILDIRIM  >  Apk Parser  >  test/main_test.php  >  Download  
File: test/main_test.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: Apk Parser
Extract Application Package files in APK format
Author: By
Last change: assertArrayHasKey added to testunit class. written assertation failed messages
Written the first test case yeah!
- Permissions count, has right perms.
Date: 2012-03-29 04:25
Size: 1,698 bytes
 

Contents

Class file image Download
<?php
    
//I used only "Equal" assertation so you can test without PHPUnit Framework.
    
if(!class_exists('PHPUnit_Framework_TestCase'))
    {
        class 
PHPUnit_Framework_TestCase
        
{
            public function 
assertEquals($a,$b)
            {
                return 
$this->assertTrue($a === $b);
            } 

            public function 
assertTrue($exp)
            {
                
                return 
assert($exp);
            }

            public function 
assertArrayHasKey($key, array $array,$message '')
            {
                  
$this->assertTrue(isset($array[$key]));
            } 
        }
    }



    include 
'../ApkParser.php';      
    
/**
    * @todo test! test! test! 
    */
    
class Test_Apk_Main extends PHPUnit_Framework_TestCase
    
{
        
/**
        We have 4 permissions in EBHS.apk/AndroidManifest.xml
        INTERNET
        CAMERA
        BLUETOOTH
        BLUETOOTH_ADMIN
        */
        
public function TestPermissions()
        {
            
$apk = new ApkParser('../examples/EBHS.apk');
            
$permissionArray $apk->getManifest()->getPermissions();
            
$this->assertEquals(count($permissionArray),4);
            
$this->assertArrayHasKey('INTERNET',$permissionArray,"INTERNET permission not found!");
            
$this->assertArrayHasKey('CAMERA',$permissionArray,"CAMERA permission not found!");
            
$this->assertArrayHasKey('BLUETOOTH',$permissionArray,"BLUETOOTH permission not found!");
            
$this->assertArrayHasKey('BLUETOOTH_ADMIN',$permissionArray,"BLUETOOTH_ADMIN permission not found!");
        }
    }

    echo 
'<pre>';
    
$test = new Test_Apk_Main();
    
$test->TestPermissions();