datatable.test.php

来自「一款可以和GOOGLE媲美的开源统计系统,运用AJAX.功能强大. 无色提示:」· PHP 代码 · 共 904 行 · 第 1/3 页

PHP
904
字号
	  	$table->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array( 'visits'=>245,'visitors'=>245),	  						Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $table,));	  							  	    	try {    		$table->getSerialized();        	$this->fail("Exception not raised.");    	}    	catch (Exception $expected) {            return;        }	}	/**	 * Test to filter a column with a pattern	 */	 function test_filter_Pattern()	 {	 	$table = new Piwik_DataTable;	 		 	$idcol = Piwik_DataTable_Row::COLUMNS;	 		  	$rows = array(	  		array( $idcol => array('label'=>'google')),	  		array( $idcol => array('label'=>'ask')),	  		array( $idcol => array('label'=>'piwik')),	  		array( $idcol => array('label'=>'yahoo')),	  		array( $idcol => array('label'=>'amazon')),	  		array( $idcol => array('label'=>'238975247578949')),	  		array( $idcol => array('label'=>'Q*(%&*("$&%*(&"$*")"))')));	  		  	$table->loadFromArray( $rows );	  		  		 	$expectedtable = clone $table;	 	$expectedtable->deleteRows(array(1,2,4,5,6));	  		  	$filter = new Piwik_DataTable_Filter_Pattern($table, 'label', 'oo');	  		  		  	$this->assertEqual($table->getRows(), $expectedtable->getRows());	 }	/**	 * Test to filter a column with a pattern	 */	 function test_filter_Pattern2()	 {	 	$table = new Piwik_DataTable;	 		 	$idcol = Piwik_DataTable_Row::COLUMNS;	 		  	$rows = array(	  		array( $idcol => array('label'=>'google')),	  		array( $idcol => array('label'=>'ask')),	  		array( $idcol => array('label'=>'piwik')),	  		array( $idcol => array('label'=>'yahoo')),	  		array( $idcol => array('label'=>'amazon')),	  		array( $idcol => array('label'=>'238975247578949')),	  		array( $idcol => array('label'=>'Q*(%&*("$&%*(&"$*")"))')));	  		  	$table->loadFromArray( $rows );	  		  		 	$expectedtable = clone $table;	 	$expectedtable->deleteRows(array(0,1,2,3,4,5));	  		  	$filter = new Piwik_DataTable_Filter_Pattern($table, 'label', '*');	  		  		  	$this->assertEqual($table->getRows(), $expectedtable->getRows());	 }	/**	 * Test to filter a table with a offset, limit	 */	 function test_filter_OffsetLimit()	 {	 	$table = new Piwik_DataTable;	 		 	$idcol = Piwik_DataTable_Row::COLUMNS;	 		  	$rows = array(	  		array( $idcol => array('label'=>'google')),//0	  		array( $idcol => array('label'=>'ask')),//1	  		array( $idcol => array('label'=>'piwik')),//2	  		array( $idcol => array('label'=>'yahoo')),//3	  		array( $idcol => array('label'=>'amazon')),//4	  		array( $idcol => array('label'=>'238975247578949')),//5	  		array( $idcol => array('label'=>'Q*(%&*("$&%*(&"$*")"))'))//6	  		);	  		  	$table->loadFromArray( $rows );	  		  		 	$expectedtable = clone $table;	 	$expectedtable->deleteRows(array(0,1,6));	  		  	$filter = new Piwik_DataTable_Filter_Limit($table, 2, 4);	  		  	$colAfter=$colExpected=array();	  	foreach($table->getRows() as $row) $colAfter[] = $row->getColumn('label');	  	foreach($expectedtable->getRows() as $row) $colExpected[] = $row->getColumn('label');	  		  	$this->assertEqual(array_values($table->getRows()), array_values($expectedtable->getRows()),	  		implode(", ",array_values($colAfter)) ." does not match the expected ".implode(", ",array_values($colExpected)) );	 }	/**	 * Test to filter a column with a offset, limit off bound	 */	 function test_filter_OffsetLimitOffbound()	 {	 	$table = new Piwik_DataTable;	 		 	$idcol = Piwik_DataTable_Row::COLUMNS;	 		  	$rows = array(	  		array( $idcol => array('label'=>'google')),//0	  		array( $idcol => array('label'=>'ask')),//1	  		array( $idcol => array('label'=>'piwik')),//2	  		array( $idcol => array('label'=>'yahoo')),//3	  		array( $idcol => array('label'=>'amazon')),//4	  		array( $idcol => array('label'=>'238975247578949')),//5	  		array( $idcol => array('label'=>'Q*(%&*("$&%*(&"$*")"))'))//6	  		);	  		  	$table->loadFromArray( $rows );	  		  		 	$expectedtable = clone $table;	 	$expectedtable->deleteRows(array(0,1,3,4,5,6));	  		  	$filter = new Piwik_DataTable_Filter_Limit($table, 2, 1);	  		  	$colAfter=$colExpected=array();	  	foreach($table->getRows() as $row) $colAfter[] = $row->getColumn('label');	  	foreach($expectedtable->getRows() as $row) $colExpected[] = $row->getColumn('label');	  		  	$this->assertEqual(array_values($table->getRows()), array_values($expectedtable->getRows()));	 }	/**	 * Test to filter a column with a offset, limit 2	 */	 function test_filter_OffsetLimit2()	 {	 	$table = new Piwik_DataTable;	 		 	$idcol = Piwik_DataTable_Row::COLUMNS;	 		  	$rows = array(	  		array( $idcol => array('label'=>'google')),//0	  		array( $idcol => array('label'=>'ask')),//1	  		array( $idcol => array('label'=>'piwik')),//2	  		array( $idcol => array('label'=>'yahoo')),//3	  		array( $idcol => array('label'=>'amazon')),//4	  		array( $idcol => array('label'=>'238975247578949')),//5	  		array( $idcol => array('label'=>'Q*(%&*("$&%*(&"$*")"))'))//6	  		);	  		  	$table->loadFromArray( $rows );	  		  		 	$expectedtable = clone $table;	  		  	$filter = new Piwik_DataTable_Filter_Limit($table, 0, 15);	  		  	$colAfter=$colExpected=array();	  	foreach($table->getRows() as $row) $colAfter[] = $row->getColumn('label');	  	foreach($expectedtable->getRows() as $row) $colExpected[] = $row->getColumn('label');	  		  	$this->assertEqual(array_values($table->getRows()), array_values($expectedtable->getRows()));	 }		/**	 * Test to filter a column with a offset, limit 3	 */	 function test_filter_OffsetLimit3()	 {	 	$table = new Piwik_DataTable;	 		 	$idcol = Piwik_DataTable_Row::COLUMNS;	 		  	$rows = array(	  		array( $idcol => array('label'=>'google')),//0	  		array( $idcol => array('label'=>'ask')),//1	  		array( $idcol => array('label'=>'piwik')),//2	  		array( $idcol => array('label'=>'yahoo')),//3	  		array( $idcol => array('label'=>'amazon')),//4	  		array( $idcol => array('label'=>'238975247578949')),//5	  		array( $idcol => array('label'=>'Q*(%&*("$&%*(&"$*")"))'))//6	  		);	  		  	$table->loadFromArray( $rows );	  		  		 	$expectedtable = new Piwik_DataTable;	  		  	$filter = new Piwik_DataTable_Filter_Limit($table, 8, 15);	  		  	$colAfter=$colExpected=array();	  	foreach($table->getRows() as $row) $colAfter[] = $row->getColumn('label');	  	foreach($expectedtable->getRows() as $row) $colExpected[] = $row->getColumn('label');	  		  	$this->assertEqual(array_values($table->getRows()), array_values($expectedtable->getRows()));	 }	 		/**	 * Test to sort by label	 */	 function test_filter_SortString()	 {	 		 	$idcol = Piwik_DataTable_Row::COLUMNS;	 		  	$table = new Piwik_DataTable;	 	$rows = array(	  		array( $idcol => array('label'=>'google')),//0	  		array( $idcol => array('label'=>'ask')),//1	  		array( $idcol => array('label'=>'piwik')),//2	  		array( $idcol => array('label'=>'yahoo')),//3	  		array( $idcol => array('label'=>'amazon')),//4	  		array( $idcol => array('label'=>'238975247578949')),//5	  		array( $idcol => array('label'=>'Q*(%&*("$&%*(&"$*")"))'))//6	  		);	  	$table->loadFromArray( $rows );	  		  	$expectedtable = new Piwik_DataTable;	 	$rows = array(	  		array( $idcol => array('label'=>'238975247578949')),//5	  		array( $idcol => array('label'=>'amazon')),//4	  		array( $idcol => array('label'=>'ask')),//1	  		array( $idcol => array('label'=>'google')),//0	  		array( $idcol => array('label'=>'piwik')),//2	  		array( $idcol => array('label'=>'Q*(%&*("$&%*(&"$*")"))')),//6	  		array( $idcol => array('label'=>'yahoo')),//3	  		);	  	$expectedtable->loadFromArray( $rows );	  		  	$expectedtableReverse = new Piwik_DataTable;	  	$expectedtableReverse->loadFromArray(array_reverse($rows));	  		  		 	$filter = new Piwik_DataTable_Filter_Sort($table, 'label', 'asc');	 	$this->assertTrue(Piwik_DataTable::isEqual($expectedtable,$table));	  		  	$filter = new Piwik_DataTable_Filter_Sort($table, 'label', 'desc');	  	$this->assertTrue(Piwik_DataTable::isEqual($table, $expectedtableReverse));	 	 }		/**	 * Test to sort by label queing the filter	 */	 function test_filter_Queue_SortString()	 {	 		 	$idcol = Piwik_DataTable_Row::COLUMNS;	 		  	$table = new Piwik_DataTable;	 	$rows = array(	  		array( $idcol => array('label'=>'google')),//0	  		array( $idcol => array('label'=>'tsk')),//1	  		array( $idcol => array('label'=>'Q*(%&*("$&%*(&"$*")"))')),//2	  		);	  	$table->loadFromArray( $rows );	  		  	$expectedtable = new Piwik_DataTable;	 	$rows = array(	  		array( $idcol => array('label'=>'google')),//0	  		array( $idcol => array('label'=>'Q*(%&*("$&%*(&"$*")"))')),//2	  		array( $idcol => array('label'=>'tsk')),//1	  		);	  	$expectedtable->loadFromArray( $rows );	  		  	$expectedtableReverse = new Piwik_DataTable;	  	$expectedtableReverse->loadFromArray(array_reverse($rows));	  			$tableCopy = clone $table;		$this->assertTrue(Piwik_DataTable::isEqual($tableCopy, $table));				// queue the filter and check the table didnt change		$table->queueFilter("Piwik_DataTable_Filter_Sort", array('label', 'asc'));		$this->assertTrue(Piwik_DataTable::isEqual($tableCopy, $table));				// apply filter and check the table is sorted		$table->applyQueuedFilters();		$this->assertTrue(Piwik_DataTable::isEqual($expectedtable, $table));				// apply one more filter check it hasnt changed		$table->queueFilter("Piwik_DataTable_Filter_Sort", array('label', 'desc'));		$this->assertTrue(Piwik_DataTable::isEqual($expectedtable, $table));				// now apply the second sort and check it is correctly sorted		$table->applyQueuedFilters();		$this->assertTrue(Piwik_DataTable::isEqual($expectedtableReverse, $table));				// do one more time to make sure it doesnt change		$table->applyQueuedFilters();		$this->assertTrue(Piwik_DataTable::isEqual($expectedtableReverse, $table));	 }		/**	 * Test to sort by visit	 */	 function test_filter_SortNumeric()	 {	 		 	$idcol = Piwik_DataTable_Row::COLUMNS;	 		  	$table = new Piwik_DataTable;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?