Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Piwik.test.php « modules « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 864fa18d970f4df945d7cbe9f6591d28ebfcf8b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
if(!defined("PATH_TEST_TO_ROOT")) {
	define('PATH_TEST_TO_ROOT', '..');
}
if(!defined('CONFIG_TEST_INCLUDED'))
{
	require_once PATH_TEST_TO_ROOT ."/../tests/config_test.php";
}

//Zend_Loader::loadClass('Piwik_');

class Test_Piwik extends UnitTestCase
{
	function __construct( $title = '')
	{
		parent::__construct( $title );
	}
	
	public function setUp()
	{
	}
	
	public function tearDown()
	{
	}
	
    
    public function test_isNumericValid()
    {
    	$valid = array(
    			-1, 0 , 1, 1.5, -1.5, 21111, 89898, 99999999999, -4565656,
    			(float)-1, (float)0 , (float)1, (float)1.5, (float)-1.5, (float)21111, (float)89898, (float)99999999999, (float)-4565656,
    			(int)-1, (int)0 , (int)1, (int)1.5, (int)-1.5, (int)21111, (int)89898, (int)99999999999, (int)-4565656,
    			'-1', '0' , '1', '1.5', '-1.5', '21111', '89898', '99999999999', '-4565656',
    		);
    	foreach($valid as $toTest)
    	{
    		$this->assertTrue(Piwik::isNumeric($toTest), $toTest." not valid!");
    	}
    }
    
    public function test_isNumericNotValid()
    {
    	$notvalid = array(
    			'-1.0.0', '1e3','1,2',  '0x123', '--1', '-.',  "-1e-2",  '- 1', '1-', 
    		);
    	foreach($notvalid as $toTest)
    	{
    		$this->assertFalse(Piwik::isNumeric($toTest), $toTest." valid but shouldn't!");
    	}
    }

    public function test_secureDiv()
    {
    	$this->assertTrue( Piwik::secureDiv( 9,3 ) === 3 );
    	$this->assertTrue( Piwik::secureDiv( 9,0 ) === 0 );
    	$this->assertTrue( Piwik::secureDiv( 10,1 ) === 10 );
    	$this->assertTrue( Piwik::secureDiv( 10.0, 1.0 ) === 10.0 );
    	$this->assertTrue( Piwik::secureDiv( 11.0, 2 ) === 5.5 );
    	$this->assertTrue( Piwik::secureDiv( 11.0, 'a' ) === 0 );
    	
    }
}