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

Source for file PMO_MyController_Test.php

Documentation is available at PMO_MyController_Test.php

  1. <?php
  2. /**
  3.  * This file contains the PMO_MyController 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_MyController class
  59.  */
  60. {
  61.     public function __construct({
  62.         parent::__construct();
  63.         $this->setData();
  64.     }
  65.  
  66.     function test_simple_query({
  67.         $controller new PMO_MyController;
  68.  
  69.         $map $controller->query('SELECT * FROM actor LIMIT 5');
  70.         $this->assertTrue(($map instanceof PMO_Map)'controller returned a PMO_Map');
  71.  
  72.         // then we make sure we have the right number of rows
  73.         $this->assertEqual($map->count()5);
  74.  
  75.         // and the right data (1, 2, last)
  76.         $result $map->fetch();
  77.         $this->assertEqual($result['actor']->first_name'Nicolas');
  78.         $result $map->fetch();
  79.         $this->assertEqual($result['actor']->first_name'NICK');
  80.         $result $map->fetch();
  81.         $result $map->fetch();
  82.         $result $map->fetch();
  83.         $this->assertEqual($result['actor']->first_name'JOHNNY');
  84.  
  85.         try {
  86.             // we get 2 errors from PHP when trying to access
  87.             // 1) an undefined index
  88.             $this->expectError();
  89.             // and 2) trying to get a property on a non object
  90.             $this->expectError();
  91.             $id $result['film_actor']->film_id;
  92.         }
  93.         catch(Exception $e{
  94.             $this->fail('Errors were not caught');
  95.         }
  96.     }
  97.  
  98.  
  99.     function test_basic_rawquery({
  100.         $controller new PMO_MyController;
  101.  
  102.         $dbms $controller->rawquery('SELECT * FROM actor LIMIT 5');
  103.         $this->assertTrue(($dbms instanceof PMO_Dbms)'controller returned a PMO_Dbms object');
  104.  
  105.         $row $dbms->fetchArray();
  106.         $this->assertTrue($row['first_name']'Nicolas');
  107.         $row $dbms->fetchArray();
  108.         $this->assertTrue($row['first_name']'NICK');
  109.         $row $dbms->fetchArray();
  110.         $row $dbms->fetchArray();
  111.         $row $dbms->fetchArray();
  112.         $this->assertTrue($row['first_name']'JOHNNY');
  113.     }
  114. }
  115.  
  116.  
  117.  
  118. // run the tests if called individually
  119. if (!defined('PMO_TEST_SUITE')) {
  120.     $level '';
  121.     if (isset($_GET['level']))
  122.         $level $_GET['level'];
  123.  
  124.     $test new TestSuite('PMO_MyController Tests');
  125.     $test->add(new PMO_MyController_Test);
  126.     $test->run(new PMO_HTMLReporter($level));
  127. }

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