PhpMyObject
[ class tree: PhpMyObject ] [ index: PhpMyObject ] [ all elements ]

Source for file PMO_MyObject_Test.php

Documentation is available at PMO_MyObject_Test.php

  1. <?php
  2. /**
  3.  * This file contains the PMO_MyObject tests.
  4.  *
  5.  * This file is part of the PhpMyObject project,
  6.  * an Object-Relational Mapping (ORM) system.
  7.  * 
  8.  * For questions, help, comments, discussion, etc., please join our
  9.  * forum at {@link http://www.developpez.net/forums/forumdisplay.php?f=770}
  10.  * or our mailing list at {@link http://groups.google.com/group/pmo-dev}.
  11.  *
  12.  * PhpMyObject is free software: you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation, either version 3 of the License, or
  15.  * (at your option) any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with this program.  If not, see {@link http://www.gnu.org/licenses/}.
  24.  *
  25.  * @package            PhpMyObject
  26.  * @subpackage        PMO_Tests
  27.  * @author            Nicolas Boiteux <nicolas_boiteux@yahoo.fr>
  28.  * @author            Nicolas Boiteux <nicolas_boiteux@yahoo.fr>
  29.  * @link                http://pmo.developpez.com/
  30.  * @since            PhpMyObject v0.15
  31.  * @version            $Revision: 404 $
  32.  * @copyright        Copyright (C) 2007-2008 Nicolas Boiteux
  33.  * @license            GPLv3 {@link http://www.gnu.org/licenses/gpl}
  34.  * @filesource
  35.  *
  36.  */ 
  37.  
  38. /**
  39.  * setup this test case if called individually
  40.  */
  41. if (!defined('PMO_TEST_SUITE')) {
  42.     require_once(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'config.php');
  43.     require_once(SIMPLETEST.DS.'autorun.php');
  44. }
  45.  
  46.  
  47. /**
  48.  * requires the PMO_MyController which includes everything needed
  49.  */
  50. require_once(PMO_CORE DS 'PMO_Controller.php');
  51.  
  52. /**
  53.  * requires our basic PMO_MyTest template
  54.  */
  55. require_once(dirname(__FILE__).DS.'PMO_MyTest.php');
  56.  
  57. /**
  58.  * Tests the PMO_MyObject class
  59.  *
  60.  * This will test everything PMO_MyObject is supposed to do
  61.  */
  62. class PMO_MyObject_Test extends PMO_MyTest
  63. {
  64.     /** constructor calls parent contructor. */
  65.     function __construct({
  66.         parent::__construct();
  67.         $this->setData();
  68.     }
  69.  
  70.     function test_load_object({
  71.  
  72.         $inventory PMO_MyObject::factory('inventory');
  73.         $this->assertTrue(is_object($inventory),'$object is an object');
  74.         $this->assertTrue(($inventory instanceof PMO_MyObject)'$inventory is an instance of PMO_MyObject');
  75.  
  76.         $inventory->inventory_id 99;
  77.         $inventory->load();
  78.  
  79.         $this->assertEqual($inventory->film_id20);
  80.         $this->assertEqual($inventory->store_id1);
  81.  
  82.     }
  83.  
  84.     function test_load_many_objects({
  85.         $inventory PMO_MyObject::factory('inventory');
  86.         $inventory->inventory_id 99;
  87.         $inventory->load();
  88.  
  89.         $film PMO_MyObject::factory('film');
  90.         $film->film_id $inventory->film_id;
  91.         $film->load();
  92.         $this->assertEqual($film->title'AMELIE HELLFIGHTERS');
  93.  
  94.         $store PMO_MyObject::factory('store');
  95.         $store->store_id $inventory->store_id;
  96.         $store->load();
  97.         $this->assertEqual($store->manager_staff_id1);
  98.     }
  99.  
  100.     function test_all_columns_are_present({
  101.         $film PMO_MyObject::factory('film');
  102.         $film->film_id 20;
  103.         $film->load();
  104.  
  105.         $this->assertEqual($film->film_id20);
  106.         $this->assertEqual($film->title'AMELIE HELLFIGHTERS');
  107.         $this->AssertEqual($film->description,
  108.                                 'A Boring Drama of a Woman And a Squirrel who must Conquer a Student in A Baloon');
  109.         $this->assertEqual($film->release_year2006);
  110.         $this->assertEqual($film->language_id1);
  111. //pr($film);
  112.         try {
  113.             $this->assertEqual($film->original_language_id'');
  114.             $this->pass('$film->original_language_id is empty');
  115.         }
  116.         catch (Exception $e{
  117.             $this->fail('A NULL value is a perfecty legal value. It should not throw this exception since the attribute exits: '.$e->getMessage());
  118.         }
  119.         $this->assertEqual($film->rental_duration4);
  120.         $this->assertEqual($film->rental_rate4.99);
  121.         $this->assertEqual($film->length79);
  122.         $this->assertEqual($film->replacement_cost23.99);
  123.         $this->assertEqual($film->rating'R');
  124.         $this->assertEqual($film->special_features'Commentaries,Deleted Scenes,Behind the Scenes');
  125.         $this->assertEqual($film->last_update'2006-02-15 05:03:42');
  126.  
  127.     }
  128.  
  129.     function test_load_and_save({
  130.         $this->setConfig('sqlite');
  131.         $this->resetSqliteActor();
  132.  
  133.         $actor PMO_MyObject::factory('actor');
  134.         $actor->actor_id 1;
  135.         $actor->load();
  136.         $this->assertEqual($actor->first_name'Nicolas');
  137.         $this->assertEqual($actor->last_name'nico');
  138.  
  139.         $actor->last_name 'Boiteux';
  140.         $actor->save();
  141.         unset($actor);
  142.  
  143.         $actor2 PMO_MyObject::factory('actor');
  144.         $actor2->actor_id 1;
  145.         $actor2->load();
  146.         $this->assertEqual($actor2->last_name'Boiteux');
  147.     }
  148.  
  149.     function test_insert_new_actor({
  150.         $this->setConfig('sqlite');
  151.         $this->resetSqliteActor();
  152.  
  153.         $actor PMO_MyObject::factory('actor');
  154.         $actor->first_name 'Louis';
  155.         $actor->last_name 'Lapointe';
  156.         $now date('Y-m-d H:i:s');
  157.         $actor->last_update $now;
  158.  
  159.         $actor->setNew(TRUE);
  160.         $actor->save();
  161.  
  162.         $actor2 PMO_MyObject::factory('actor');
  163.         $actor2->actor_id $actor->actor_id;
  164.         $actor2->load();
  165.         $this->assertEqual($actor2->actor_id21);
  166.         $this->assertEqual($actor2->first_name'Louis');
  167.         $this->assertEqual($actor2->last_name'Lapointe');
  168.     }
  169.  
  170.     function test_delete_the_new_actor({
  171.         $this->setConfig('sqlite');
  172.         $this->resetSqliteActor();
  173.  
  174.         $actor PMO_MyObject::factory('actor');
  175.         $actor->first_name 'Louis';
  176.         $actor->last_name 'Lapointe';
  177.         $now date('Y-m-d H:i:s');
  178.         $actor->last_update $now;
  179.  
  180.         $actor->setNew(TRUE);
  181.         $actor->save();
  182.  
  183.         $actor_id $actor->actor_id;
  184.         unset($actor);
  185.  
  186.         $actor PMO_MyObject::factory('actor');
  187.         $actor->actor_id $actor_id;
  188.         $actor->load();
  189.         $this->assertEqual($actor->last_name'Lapointe''Just making sur we have a row');
  190.  
  191.         $actor->delete();
  192.         unset($actor);
  193.  
  194.         $actor PMO_MyObject::factory('actor');
  195.         $actor->actor_id $actor_id;
  196.         try {
  197.             $actor->load();
  198.         }
  199.         catch (Exception $e{
  200.             $this->pass($e->getMessage());
  201.         }
  202.     }
  203. }
  204.  
  205. //
  206. // TODO : POUSUIVRE (plein d'autres choses à tester, les getter et setter d'attributs,
  207. //          les getOnjectXXX , etc.
  208. //
  209.  
  210. {
  211.  
  212.     function __construct({
  213.         parent::__construct();
  214.     }
  215.  
  216.     function test_getTable({
  217.         $actor PMO_MyObject::factory('actor');
  218.         $table $actor->getTable();
  219.         $this->assertTrue(($table instanceof PMO_Table)'$table is an instance or PMO_Table');
  220.         $this->assertTrue(($table instanceof PMO_MyTable)'$table is an instance or PMO_MyTable');
  221.         $this->assertFalse(($table instanceof PMO_MyTable_actor)'$table is NOT YET an instance oF PMO_MyTable_actor');
  222.     }
  223.  
  224.     function test_getTable_not_persistant({
  225.         $file 'actor.php';
  226.         $cnf PMO_MyConfig::factory();
  227.         $prefix $cnf->get('PMO_MyTable.CLASS_FILENAME_PREFIX');
  228.         $classpath $cnf->get('PMO_MyTable.CLASSPATH');
  229.         $persist $classpath.$prefix.$file;
  230.  
  231.         @unlink($persist);
  232.         $actor PMO_MyObject::factory('actor');
  233.         $this->assertFalse(file_exists($persist)"Table ".basename($classpath)."/$prefix$file does not exist");
  234.         
  235.     }
  236. }
  237.  
  238.  
  239. {
  240. }
  241.     
  242.  
  243.  
  244.  
  245.  
  246. // run the tests if called individually
  247. if (!defined('PMO_TEST_SUITE')) {
  248.     $level '';
  249.     if (isset($_GET['level']))
  250.         $level $_GET['level'];
  251.  
  252.     $test new TestSuite('PMO_MyObject Tests');
  253.     $test->add(new PMO_MyObject_Test);
  254.     $test->add(new PMO_MyObject_attributes_Test);
  255.     //$test->add(new PMO_MyObject_get_objects_Test);
  256.     $test->run(new PMO_HTMLReporter($level));
  257. }

Documentation generated on Wed, 15 Oct 2008 09:17:33 -0400 by phpDocumentor 1.4.1