Overview

Namespaces

  • mechanicious
    • Columnizer
    • Extensions
      • Bs3Table
    • Support
    • Tableman
    • TablemanExtension
    • Test
      • Tableman
  • PHP

Classes

  • Other
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php namespace mechanicious\Test;
  2: 
  3: require_once __dir__ . '/../../../vendor/autoload.php';
  4: 
  5: /**
  6:  *  Little testing I run for myself, that isn't necessary 
  7:  * a part of the public API.
  8:  * Best way to run this tests is to use
  9:  * separate files with everything set to public.
 10:  */
 11: 
 12: class Other extends \PHPUnit_Framework_TestCase
 13: {
 14:   /**
 15:    *  Data to play with
 16:    * @var array
 17:    */
 18:   protected $mockData = array(
 19:         array(
 20:             'id'    => 1,
 21:             'name'  => 'Joe',
 22:             'age'   => 25
 23:         ),
 24:         array(
 25:             'id'    => 2,
 26:             'name'  => 'Tony',
 27:             'age'   => 27,
 28:             'hobby' => 'sport',
 29:         ),
 30:     );
 31: 
 32:   /**
 33:    *  Useful with formatted string comparison  
 34:    * @param   string $string
 35:    * @return  string
 36:    */
 37:   public function cleanWhiteSpace($string, $replace = "")
 38:   {
 39:     return str_replace(array("\n", "\r", "\t", " "), $replace, $string);
 40:   }
 41: 
 42:   /**
 43:    *  This method is not in the Columnizer's public API. If you wanna test it
 44:    * make it temporarily public.
 45:    */
 46:   public function testColumnizerIdentifyColumns()
 47:   {
 48:     $columnizer = new \mechanicious\Columnizer\Columnizer($this->mockData);
 49:     // It the hobby 'column' should be included because we assume that 
 50:     // the largest row contains a complete set of columns. Some data may
 51:     // be inconsistent like that but there's not problem handling it.
 52:     $this->assertEquals($columnizer->identifyColumns(), array('id', 'name', 'age', 'hobby'));
 53:   }
 54: 
 55:   public function testColumnizerColumnizeItems()
 56:   {
 57:     $columnizer = new \mechanicious\Columnizer\Columnizer($this->mockData);
 58:     $this->assertEquals($columnizer->columnizeArrayRow(), array(
 59:       'id'  => array(1, 2),
 60:       'name'  => array('Joe', 'Tony'),
 61:       'age' => array(25, 27),
 62:       // Notice the hobby one below. That's a example when we're dealing with
 63:       // inconsistent data.
 64:       'hobby' => array('sport'),
 65:       ));
 66:   }
 67: 
 68:   /**
 69:    *  For this test you need to have $items and symmetrize() set to public.
 70:    */
 71:   public function testColumnizeSymmetrize()
 72:   {
 73:     // Here we test if the hobby field for Joe will get pre-filled.
 74:     $columnizer = $columnizer = new \mechanicious\Columnizer\Columnizer($this->mockData);
 75:     $columnizer->symmetrize();
 76:     $this->assertEquals($columnizer->items, array(
 77:       array(
 78:             'id'    => 1,
 79:             'name'  => 'Joe',
 80:             'age'   => 25,
 81:             'hobby' => null,
 82:         ),
 83:         array(
 84:             'id'    => 2,
 85:             'name'  => 'Tony',
 86:             'age'   => 27,
 87:             'hobby' => 'sport',
 88:         )
 89:     ));
 90:   }
 91: 
 92:   public function testTablemanRenameColumns()
 93:   {
 94:     $columnBag = with(new \mechanicious\Columnizer\Columnizer($this->mockData))->columnize();
 95:     $tableman = new \mechanicious\Tableman\Tableman($columnBag);
 96:     $headers = array(
 97:       'id'    => 'identification',
 98:       'name'  => 'firstname',
 99:       'age'   => 'level',
100:       'hobby' => 'likes',
101:       );
102: 
103:     $tableman->renameHeaders($headers);
104:     $this->assertEquals($this->cleanWhiteSpace($tableman->toJson()), $this->cleanWhiteSpace('
105:         {
106:           "identification":[1,2],
107:           "firstname":["Joe","Tony"],
108:           "level":[25,27],
109:           "likes":[null,"sport"]
110:         }
111:       '));
112:   }
113: }
API documentation generated by ApiGen 2.8.0