Location: PHPKode > projects > DIY Blog > diy-blog/lib/propel/generator/test/php4/classes/propel/GeneratedObjectTest.php
<?php
/*
 *  $Id: GeneratedObjectTest.php 536 2007-01-10 14:30:38Z heltem $
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the LGPL. For more information please see
 * <http://propel.phpdb.org>.
 */

require_once 'bookstore/BookstoreTestBase.php';

/**
 * Tests the generated Object classes.
 *
 * This test uses generated Bookstore classes to test the behavior of various
 * object operations.  The _idea_ here is to test every possible generated method
 * from Object.tpl; if necessary, bookstore will be expanded to accommodate this.
 *
 * The database is relaoded before every test and flushed after every test.  This
 * means that you can always rely on the contents of the databases being the same
 * for each test method in this class.  See the BookstoreDataPopulator::populate()
 * method for the exact contents of the database.
 *
 * @see        BookstoreDataPopulator
 * @author     Hans Lellelid <hide@address.com>
 */
class GeneratedObjectTest extends BookstoreTestBase
{

  /**
  * Test saving an object after setting default values for it.
  */
  function testSaveWithDefaultValues()
  {
	// From the schema.xml, I am relying on the following:
	//  - that 'Penguin' is the default Name for a Publisher
	//  - that 01/01/2001 is the default ReviewDate for a Review

	// 1) check regular values (VARCHAR)
	$pub = new Publisher();
	$pub->setName('Penguin');
	$pub->save();

	$this->assertTrue($pub->getId() !== null, "Expect Publisher to have been saved when default value set.");

	// 2) check date/time values
	$review = new Review();
	// note that this is different from how it's represented in schema, but should resolve to same unix timestamp
	$review->setReviewDate('2001-01-01');
	$this->assertTrue($review->isModified(), "Expect Review to have been marked 'modified' after default date/time value set.");
  }

  /**
   * Test deleting an object using the delete() method.
   */
  function testDelete()
  {
	// 1) grab an arbitrary object
	$book = BookPeer::doSelectOne(new Criteria());
	$bookId = $book->getId();

	// 2) delete it
	$e = $book->delete();
	if (Propel::isError($e)) {
	  $this->fail($e->getMessage());
	  return;
	}

	// 3) make sure it can't be save()d now that it's deleted
	$book->setTitle("Will Fail");

	$e = $book->save();

	if (! Propel::isError($e)) {
	  $this->fail("Expect an exception to be thrown when attempting to save() a deleted object.");
	  return;
	}

	// 4) make sure that it doesn't exist in db
	$book = BookPeer::retrieveByPK($bookId);
	$this->assertNull($book, "Expect NULL from retrieveByPK on deleted book !");
  }

}
Return current item: DIY Blog