[Piwik-svn] r141 - in trunk: modules modules/DataTable/Renderer modules/ViewDataTable plugins plugins/Home/templates tests/modules

svnmaster at piwik.org svnmaster at piwik.org
Thu Jan 10 22:19:44 CET 2008


Author: matt
Date: 2008-01-10 22:19:43 +0100 (Thu, 10 Jan 2008)
New Revision: 141

Modified:
   trunk/modules/DataTable/Renderer/Json.php
   trunk/modules/Date.php
   trunk/modules/Period.php
   trunk/modules/Piwik.php
   trunk/modules/ViewDataTable.php
   trunk/modules/ViewDataTable/Html.php
   trunk/plugins/Home/templates/datatable.css
   trunk/plugins/Installation.php
   trunk/tests/modules/Period.test.php
Log:
- Fixed a bug introduced by factoring
- fixed a CSS bug
- fixed typo in installation error message
- added tests of the class Period

Modified: trunk/modules/DataTable/Renderer/Json.php
===================================================================
--- trunk/modules/DataTable/Renderer/Json.php	2008-01-10 20:52:42 UTC (rev 140)
+++ trunk/modules/DataTable/Renderer/Json.php	2008-01-10 21:19:43 UTC (rev 141)
@@ -18,7 +18,7 @@
 	{
 		return $this->renderTable($this->table);
 	}
-	
+
 	protected function renderTable($table)
 	{
 		$renderer = new Piwik_DataTable_Renderer_Php($table, $serialize = false);

Modified: trunk/modules/Date.php
===================================================================
--- trunk/modules/Date.php	2008-01-10 20:52:42 UTC (rev 140)
+++ trunk/modules/Date.php	2008-01-10 21:19:43 UTC (rev 141)
@@ -104,7 +104,8 @@
 			return $this->getTimestamp();
 		}
 		return date($part, $this->getTimestamp());
-	}
+	}
+	
     /**
      * Adds days to the existing date object.
      * Returned is the new date object

Modified: trunk/modules/Period.php
===================================================================
--- trunk/modules/Period.php	2008-01-10 20:52:42 UTC (rev 140)
+++ trunk/modules/Period.php	2008-01-10 21:19:43 UTC (rev 141)
@@ -48,14 +48,12 @@
 				break;
 		}
 	}
-
-	//TODO test getDate
-	public function getDate()
-	{
-		return $this->date;
-	}
-	
-	//TODO test getDateStart
+
+	/**
+	 * Returns the first day of the period
+	 *
+	 * @return Piwik_Date First day of the period
+	 */
 	public function getDateStart()
 	{
 		if(count($this->subperiods) == 0)
@@ -71,8 +69,12 @@
 		}
 		return $currentPeriod->getDate();
 	}
-	
-	//TODO test getDateEnd
+	
+	/**
+	 * Returns the last day of the period ; can be a date in the future
+	 *
+	 * @return Piwik_Date Last day of the period 
+	 */
 	public function getDateEnd()
 	{
 		if(!$this->subperiodsProcessed)
@@ -93,16 +95,20 @@
 		return $currentPeriod->getDate();
 	}
 	
-	//TODO test getId
 	public function getId()
 	{
 		return Piwik::$idPeriods[$this->getLabel()];
-	}
-	//TODO test getLabel
+	}
+
 	public function getLabel()
 	{
 		return $this->label;
 	}
+	
+	protected function getDate()
+	{
+		return $this->date;
+	}	
 	
 	protected function checkInputDate($date)
 	{
@@ -139,7 +145,7 @@
 		}
 		return $this->subperiods;
 	}
-		
+
 	/**
 	 * Add a date to the period.
 	 * 

Modified: trunk/modules/Piwik.php
===================================================================
--- trunk/modules/Piwik.php	2008-01-10 20:52:42 UTC (rev 140)
+++ trunk/modules/Piwik.php	2008-01-10 21:19:43 UTC (rev 141)
@@ -14,10 +14,10 @@
 	const CLASSES_PREFIX = "Piwik_";
 	
 	static $idPeriods =  array(
-			'day'	=>1,
-			'week'	=>2,
-			'month'	=>3,
-			'year'	=>4,
+			'day'	=> 1,
+			'week'	=> 2,
+			'month'	=> 3,
+			'year'	=> 4,
 		);
 	
 	/**

Modified: trunk/modules/ViewDataTable/Html.php
===================================================================
--- trunk/modules/ViewDataTable/Html.php	2008-01-10 20:52:42 UTC (rev 140)
+++ trunk/modules/ViewDataTable/Html.php	2008-01-10 21:19:43 UTC (rev 141)
@@ -7,10 +7,12 @@
 	public $arrayDataTable; // phpArray
 	
 	function init($currentControllerAction, 
-						$moduleNameAndMethod )
+						$moduleNameAndMethod,						
+						$actionToLoadTheSubTable = null )
 	{
 		parent::init($currentControllerAction, 
-						$moduleNameAndMethod );
+						$moduleNameAndMethod,						
+						$actionToLoadTheSubTable);
 		$this->dataTableTemplate = 'Home/templates/datatable.tpl';
 	}
 	

Modified: trunk/modules/ViewDataTable.php
===================================================================
--- trunk/modules/ViewDataTable.php	2008-01-10 20:52:42 UTC (rev 140)
+++ trunk/modules/ViewDataTable.php	2008-01-10 21:19:43 UTC (rev 141)
@@ -12,7 +12,7 @@
 	
 	protected $currentControllerAction;
 	
-	protected $actionToLoadTheSubTable;
+	protected $actionToLoadTheSubTable = null;
 	
 	public $dataTable; // data table
 	

Modified: trunk/plugins/Home/templates/datatable.css
===================================================================
--- trunk/plugins/Home/templates/datatable.css	2008-01-10 20:52:42 UTC (rev 140)
+++ trunk/plugins/Home/templates/datatable.css	2008-01-10 21:19:43 UTC (rev 141)
@@ -1,6 +1,6 @@
 * {
 	font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
-	font-size:0.95em;
+	font-size:1em;
 }
 
 /* main data table */

Modified: trunk/plugins/Installation.php
===================================================================
--- trunk/plugins/Installation.php	2008-01-10 20:52:42 UTC (rev 140)
+++ trunk/plugins/Installation.php	2008-01-10 21:19:43 UTC (rev 141)
@@ -59,7 +59,7 @@
 		{
 			Piwik::exitWithErrorMessage("
 				The Piwik configuration file couldn't be found and you are trying to access a Piwik page.<br>
-				<b>&nbsp;&nbsp;» You can <a href='index.php'>install Piwik now</a></b>
+				<b>&nbsp;&nbsp;» You can <a href='index.php'>install Piwik now</a></b>
 				<br><small>If you installed Piwik before and have some tables in your DB, don't worry, 
 				you can reuse the same tables and keep your existing data!</small>");
 		}

Modified: trunk/tests/modules/Period.test.php
===================================================================
--- trunk/tests/modules/Period.test.php	2008-01-10 20:52:42 UTC (rev 140)
+++ trunk/tests/modules/Period.test.php	2008-01-10 21:19:43 UTC (rev 141)
@@ -26,14 +26,41 @@
 	{
 //		echo $this->timer . "<br> ";
 	}
+	
+	public function test_getId()
+	{
+		$period = new Piwik_Period_Day( Piwik_Date::today() );
+		$this->assertTrue(  $period->getId() !== 0 );
+		$period = new Piwik_Period_Week( Piwik_Date::today() );
+		$this->assertTrue(  $period->getId() !== 0 );
+		$period = new Piwik_Period_Month( Piwik_Date::today() );
+		$this->assertTrue(  $period->getId() !== 0 );
+		$period = new Piwik_Period_Year( Piwik_Date::today() );
+		$this->assertTrue(  $period->getId() !== 0 );
+	}
+	
+	public function test_getLabel()
+	{
+		$period = new Piwik_Period_Day( Piwik_Date::today() );
+		$label = $period->getLabel();
+		$this->assertTrue(  is_string($label) && !empty($label));
+		$period = new Piwik_Period_Week( Piwik_Date::today() );
+		$label = $period->getLabel();
+		$this->assertTrue(  is_string($label) && !empty($label));
+		$period = new Piwik_Period_Month( Piwik_Date::today() );
+		$label = $period->getLabel();
+		$this->assertTrue(  is_string($label) && !empty($label));
+		$period = new Piwik_Period_Year( Piwik_Date::today() );
+		$label = $period->getLabel();
+		$this->assertTrue(  is_string($label) && !empty($label));
+	}
 	
-	
 	/**
 	 * Testing Period_Day
 	 */
 	
 	// today is NOT finished
-	function test_isFinished_today()
+	function test_day_isFinished_today()
 	{
 		$period = new Piwik_Period_Day( Piwik_Date::today());
 		$this->assertEqual( $period->isFinished(), false);
@@ -42,7 +69,7 @@
 		$this->assertEqual( $period->getNumberOfSubperiods(), 0);
 	}
 	// yesterday 23:59:59 is finished
-	function test_isFinished_yesterday()
+	function test_day_isFinished_yesterday()
 	{
 		
 		$period = new Piwik_Period_Day( Piwik_Date::yesterday());
@@ -53,7 +80,7 @@
 	}
 	
 	// tomorrow is not finished
-	function test_isFinished_tomorrow()
+	function test_day_isFinished_tomorrow()
 	{	
 		$period = new Piwik_Period_Day( new Piwik_Date(date("Y-m-d",time()+86400)));
 		$this->assertEqual( $period->isFinished(), false);
@@ -62,8 +89,8 @@
 		$this->assertEqual( $period->getNumberOfSubperiods(), 0);
 	}
 	
-	// TODO test day doesnt exist 31st feb
-	function test_isFinished_31stfeb()
+	// test day doesnt exist 31st feb
+	function test_day_isFinished_31stfeb()
 	{	
 		$period = new Piwik_Period_Day( new Piwik_Date("2007-02-31"));
 		$this->assertEqual( $period->isFinished(), true);
@@ -71,13 +98,104 @@
 		$this->assertEqual( $period->getSubperiods(), array());
 		$this->assertEqual( $period->getNumberOfSubperiods(), 0);
 	}
-		
+	
+	// test date that doesn't exist, should return the corresponding correct date
+	function test_day_getDateStart1()
+	{
+		// create the period
+		$period = new Piwik_Period_Day( new Piwik_Date("2007-02-31"));
+		
+		// start date
+		$startDate = $period->getDateStart();
+		
+		// expected string
+		$this->assertEqual( $startDate->toString(), "2007-03-03");
+		
+		// check that for a day, getDateStart = getStartEnd
+		$this->assertEqual($startDate, $period->getDateEnd() );		
+	}
+	
+	// test normal date
+	function test_day_getDateStart2()
+	{
+		// create the period
+		$period = new Piwik_Period_Day( new Piwik_Date("2007-01-03"));
+		
+		// start date
+		$startDate = $period->getDateStart();
+		
+		// expected string
+		$this->assertEqual( $startDate->toString(), "2007-01-03");
+		
+		// check that for a day, getDateStart = getStartEnd
+		$this->assertEqual($startDate, $period->getDateEnd() );		
+	}
+	
+	// test last day of year
+	function test_day_getDateStart3()
+	{
+		// create the period
+		$period = new Piwik_Period_Day( new Piwik_Date("2007-12-31"));
+		
+		// start date
+		$startDate = $period->getDateStart();
+		
+		// expected string
+		$this->assertEqual( $startDate->toString(), "2007-12-31");
+		
+		// check that for a day, getDateStart = getStartEnd
+		$this->assertEqual($startDate, $period->getDateEnd() );		
+	}
+	
+
+	// test date that doesn't exist, should return the corresponding correct date
+	function test_day_getDateEnd1()
+	{		
+		// create the period
+		$period = new Piwik_Period_Day( new Piwik_Date("2007-02-31"));
+		
+		// end date
+		$endDate = $period->getDateEnd();
+		
+		// expected string
+		$this->assertEqual( $endDate->toString(), "2007-03-03");
+		
+	}
+	
+	// test normal date
+	function test_day_getDateEnd2()
+	{
+		// create the period
+		$period = new Piwik_Period_Day( new Piwik_Date("2007-04-15"));
+		
+		// end date
+		$endDate = $period->getDateEnd();
+		
+		// expected string
+		$this->assertEqual( $endDate->toString(), "2007-04-15");
+	}
+	
+	// test last day of year
+	function test_day_getDateEnd3()
+	{
+		// create the period
+		$period = new Piwik_Period_Day( new Piwik_Date("2007-12-31"));
+		
+		// end date
+		$endDate = $period->getDateEnd();
+		
+		// expected string
+		$this->assertEqual( $endDate->toString(), "2007-12-31");
+	}
+	
+	// test date that doesn't exist, should return the corresponding correct date
+	
 	/**
 	 * Testing Period_Month
 	 *
 	 */
 	 // testing december
-	 function test_monthDec()
+	 function test_month_Dec()
 	 {
 	 	$month = new Piwik_Period_Month( new Piwik_Date("2006-12-31"));
 	 	$correct=array(
@@ -117,7 +235,7 @@
 	 	$this->assertEqual( $month->isFinished(), true);
 	 }
 	 // testing month feb leap year
-	 function test_monthFebLeap()
+	 function test_month_FebLeap()
 	 {
 	 	$month = new Piwik_Period_Month( new Piwik_Date("2024-02-11"));
 	 	$correct=array(
@@ -155,7 +273,7 @@
 	 	$this->assertEqual( $month->isFinished(), false);
 	 }
 	 // testing month feb non-leap year
-	 function test_monthFebNonLeap()
+	 function test_month_FebNonLeap()
 	 {
 	 	$month = new Piwik_Period_Month( new Piwik_Date("2023-02-11"));
 	 	$correct=array(
@@ -192,7 +310,7 @@
 	 	$this->assertEqual( $month->isFinished(), false);
 	 }
 	 // testing jan
-	  function test_monthJan()
+	  function test_month_Jan()
 	 {
 	 	$month = new Piwik_Period_Month( new Piwik_Date("2007-01-01"));
 	 	$correct=array(
@@ -233,7 +351,7 @@
 	 }
 	 // testing month containing a time change (DST)
 	 
-	  function test_monthDSTChangeMarch()
+	  function test_month_DSTChangeMarch()
 	 {
 	 	$month = new Piwik_Period_Month( new Piwik_Date("2007-02-31"));
 	 	$correct=array(
@@ -272,7 +390,7 @@
 	 	$this->assertEqual( $month->getNumberOfSubperiods(), 31);
 	 	$this->assertEqual( $month->isFinished(), true);
 	 }
-	  function test_monthDSTChangeOct()
+	  function test_month_DSTChangeOct()
 	 {
 	 	$month = new Piwik_Period_Month( new Piwik_Date("2017-10-31"));
 	 	$correct=array(



More information about the Piwik-svn mailing list