SortByDateFieldTest

The Contact Form DB SortByDateFieldTest class.

Defined (1)

The class is defined in the following location(s).

/phpunit/SortByDateFieldTest.php  
  1. class SortByDateFieldTest extends PHPUnit_Framework_TestCase { 
  2.  
  3. public function setup() { 
  4. date_default_timezone_set('America/New_York'); 
  5.  
  6. public function test_no_format_strtotime() { 
  7. $sort = new SortByDateField('date'); 
  8.  
  9. $before = array('date' => 'yesterday'); 
  10. $after = array('date' => 'today'); 
  11.  
  12. $this->assertEquals(-1, $sort->sort($before, $after)); 
  13. $this->assertEquals(1, $sort->sort($after, $before)); 
  14. $this->assertEquals(0, $sort->sort($after, $after)); 
  15.  
  16. public function test_no_format_strtotime2() { 
  17. $sort = new SortByDateField('date'); 
  18.  
  19. $before = array('date' => '1/1/2010'); 
  20. $after = array('date' => '1/1/2014'); 
  21.  
  22. $this->assertEquals(-1, $sort->sort($before, $after)); 
  23. $this->assertEquals(1, $sort->sort($after, $before)); 
  24. $this->assertEquals(0, $sort->sort($after, $after)); 
  25.  
  26. public function test_no_format_strtotime2_asc() { 
  27. $sort = new SortByDateField('date', 'ASC'); 
  28.  
  29. $before = array('date' => '1/1/2010'); 
  30. $after = array('date' => '1/1/2014'); 
  31.  
  32. $this->assertEquals(-1, $sort->sort($before, $after)); 
  33. $this->assertEquals(1, $sort->sort($after, $before)); 
  34. $this->assertEquals(0, $sort->sort($after, $after)); 
  35.  
  36. public function test_no_format_strtotime2_desc() { 
  37. $sort = new SortByDateField('date', 'DESC'); 
  38.  
  39. $before = array('date' => '1/1/2010'); 
  40. $after = array('date' => '1/1/2014'); 
  41.  
  42. $this->assertEquals(1, $sort->sort($before, $after)); 
  43. $this->assertEquals(-1, $sort->sort($after, $before)); 
  44. $this->assertEquals(0, $sort->sort($after, $after)); 
  45.  
  46. public function test_format() { 
  47. $sort = new SortByDateField('date', 'ASC', 'j.n.Y H:iP'); 
  48.  
  49. $before = array('date' => '6.1.2009 13:00+01:00'); 
  50. $after = array('date' => '6.2.2009 13:00+01:00'); 
  51.  
  52. $this->assertEquals(-1, $sort->sort($before, $after)); 
  53. $this->assertEquals(1, $sort->sort($after, $before)); 
  54. $this->assertEquals(0, $sort->sort($after, $after)); 
  55.  
  56. // bad data tests 
  57. public function test_bad_data1() { 
  58. $sort = new SortByDateField('date'); 
  59.  
  60. $before = array('date' => 'crap'); 
  61. $after = array('date' => 'today'); 
  62.  
  63. $this->assertEquals(-1, $sort->sort($before, $after)); 
  64. $this->assertEquals(1, $sort->sort($after, $before)); 
  65. $this->assertEquals(0, $sort->sort($after, $after)); 
  66.  
  67. public function test_bad_data2() { 
  68. $sort = new SortByDateField('date'); 
  69.  
  70. $before = array('date' => 'yesterday'); 
  71. $after = array('date' => 'crap'); 
  72.  
  73. $this->assertEquals(1, $sort->sort($before, $after)); 
  74. $this->assertEquals(-1, $sort->sort($after, $before)); 
  75. $this->assertEquals(0, $sort->sort($after, $after)); 
  76.  
  77. public function test_bad_data3() { 
  78. $sort = new SortByDateField('date'); 
  79.  
  80. $before = array('date' => 'crap'); 
  81. $after = array('date' => 'more crap'); 
  82.  
  83. $this->assertEquals(0, $sort->sort($before, $after)); 
  84. $this->assertEquals(0, $sort->sort($after, $before)); 
  85. $this->assertEquals(0, $sort->sort($after, $after)); 
  86.  
  87.