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

TablePartitioning.test.php « modules « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e512ba991e14638ee6ae4703ebdce5f8a4d45bac (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
if(!defined("PATH_TEST_TO_ROOT")) {
	define('PATH_TEST_TO_ROOT', getcwd().'/../../');
}
if(!defined('CONFIG_TEST_INCLUDED'))
{
	require_once PATH_TEST_TO_ROOT."tests/config_test.php";
}
require_once "Database.test.php";

require_once 'TablePartitioning.php';
class Test_Piwik_TablePartitioning extends Test_Database
{
    function __construct() 
    {
        parent::__construct('');
    }
    public function setUp()
	{
		parent::setUp();
		Piwik_TablePartitioning::$tablesAlreadyInstalled = null;
	}
	
    // test no timestamp  => exception
    function test_noTimestamp()
    {
    	$p = new Piwik_TablePartitioning_Monthly('testtable');
    	
    	try {
    		$p->getTableName();
        	$this->fail("Exception not raised.");
    	}
    	catch (Exception $expected) {
            return;
        }
    }
	
	// test table absent  => create
    function test_noTable()
    {
    	$tableName ='archive_numeric';
    	$p = new Piwik_TablePartitioning_Monthly($tableName);
    	$timestamp = strtotime("10 September 2000");
    	$suffixShouldBe = "_2000_09";
		$config = Zend_Registry::get('config');
		$prefixTables = $config->database->tables_prefix;
		$tablename = $prefixTables.$tableName.$suffixShouldBe;
		
    	$p->setTimestamp( $timestamp );
    	
    	$allTablesInstalled = Piwik::getTablesInstalled($forceReload = true);
    	
    	$this->assertTrue( in_array($tablename, $allTablesInstalled), "$tablename !==".var_export($allTablesInstalled,true));
    	$this->assertTrue( $tablename, $p->getTableName());
    	$this->assertEqual( $tablename, (string)$p);
    }
	
	// test monthly
    function test_monthlyPartition()
    {
    	
    	$tableName ='archive_numeric';
    	$p = new Piwik_TablePartitioning_Monthly($tableName);
    	$timestamp = strtotime("10 September 2000");
    	$suffixShouldBe = "_2000_09";
		$config = Zend_Registry::get('config');
		$prefixTables = $config->database->tables_prefix;
		$tablename = $prefixTables.$tableName.$suffixShouldBe;
		
    	$p->setTimestamp( $timestamp );
    	
    	$allTablesInstalled = Piwik::getTablesInstalled( $forceReload = true );
    	$this->assertTrue( in_array($tablename, $allTablesInstalled));
    	$this->assertTrue( $tablename, $p->getTableName());
    	$this->assertEqual( $tablename, (string)$p);
    }
        
	// test daily
    function test_dailyPartition()
    {
    	
    	$tableName ='archive_numeric';
    	$p = new Piwik_TablePartitioning_Daily($tableName);
    	$timestamp = strtotime("10 September 2000");
    	$suffixShouldBe = "_2000_09_10";
		$config = Zend_Registry::get('config');
		$prefixTables = $config->database->tables_prefix;
		$tablename = $prefixTables.$tableName.$suffixShouldBe;
		
    	$p->setTimestamp( $timestamp );
    	
    	$allTablesInstalled = Piwik::getTablesInstalled();
    	$this->assertTrue( in_array($tablename, $allTablesInstalled));
    	$this->assertTrue( $tablename, $p->getTableName());
    	$this->assertEqual( $tablename, (string)$p);
    }
    
    
    /**
     * -> exception
     */
    public function _test_()
    {
    	try {
    		test();
        	$this->fail("Exception not raised.");
    	}
    	catch (Exception $expected) {
    		$this->assertPattern("()", $expected->getMessage());
            return;
        }
    }
}