2008-02-15 03:57:34 +03:00
|
|
|
<?php /* vim: set et sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* $Id: Doctrine.php 3754 2008-02-13 10:53:07Z romanb $
|
|
|
|
*
|
|
|
|
* 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, see
|
|
|
|
* <http://www.phpdoctrine.org>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Doctrine
|
|
|
|
* the base class of Doctrine framework
|
|
|
|
*
|
|
|
|
* @package Doctrine
|
|
|
|
* @author Bjarte Stien Karlsen <doctrine@bjartek.org>
|
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
2008-02-22 21:11:35 +03:00
|
|
|
* @link www.phpdoctrine.org
|
2008-06-15 19:56:28 +04:00
|
|
|
* @since 2.0
|
2008-02-15 03:57:34 +03:00
|
|
|
* @version $Revision: 3754 $
|
|
|
|
*/
|
|
|
|
require_once 'lib/DoctrineTestInit.php';
|
|
|
|
|
|
|
|
class Orm_Component_CollectionTest extends Doctrine_OrmTestCase
|
|
|
|
{
|
|
|
|
|
|
|
|
private $coll;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2008-05-17 16:22:24 +04:00
|
|
|
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock());
|
|
|
|
|
2008-02-15 03:57:34 +03:00
|
|
|
$this->coll = new Doctrine_Collection('ForumUser');
|
|
|
|
|
|
|
|
//we create a CmsUser with username as key column and add a user to it
|
|
|
|
$cmsColl = new Doctrine_Collection('CmsUser', 'username');
|
|
|
|
$user = new CmsUser();
|
|
|
|
$user->username ='test';
|
|
|
|
$cmsColl[] = $user;
|
|
|
|
$this->cmsColl = $cmsColl;
|
|
|
|
$this->cmsUser = $user;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldHaveBlankAsDefaultKeyColumn()
|
|
|
|
{
|
2008-03-23 14:30:29 +03:00
|
|
|
$this->assertEquals('', $this->coll->getKeyField());
|
2008-02-15 03:57:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldUseSpecifiedKeyColumn()
|
|
|
|
{
|
|
|
|
$coll = new Doctrine_Collection('ForumUser', 'id');
|
2008-03-23 14:30:29 +03:00
|
|
|
$this->assertEquals('id', $coll->getKeyField());
|
2008-02-15 03:57:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This test is currently failing. I do not understand why it should be
|
|
|
|
* possible to set this to something that is not valid.
|
|
|
|
*
|
|
|
|
* @test
|
2008-03-23 14:30:29 +03:00
|
|
|
* @expectedException Doctrine_Collection_Exception
|
2008-02-15 03:57:34 +03:00
|
|
|
*/
|
|
|
|
public function shouldThrowExceptionIfNonValidFieldSetAsKey()
|
|
|
|
{
|
2008-03-23 14:30:29 +03:00
|
|
|
$coll = new Doctrine_Collection('ForumUser', 'xxNonValidFieldxx');
|
2008-02-15 03:57:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldSerializeEmptyCollection()
|
|
|
|
{
|
2008-03-23 14:30:29 +03:00
|
|
|
$serialized = serialize($this->coll);
|
|
|
|
$this->assertTrue(is_string($serialized));
|
2008-02-15 03:57:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldUnserializeEmptyCollectionIntoObject()
|
|
|
|
{
|
2008-03-23 14:30:29 +03:00
|
|
|
$serialized = serialize($this->coll);
|
|
|
|
$coll = unserialize($serialized);
|
2008-02-16 22:37:51 +03:00
|
|
|
$this->assertEquals('Doctrine_Collection', get_class($coll));
|
2008-02-15 03:57:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2008-07-21 00:13:24 +04:00
|
|
|
/*public function shouldSetKeyColumnWhenAddingNewRowAsArray()
|
2008-02-15 03:57:34 +03:00
|
|
|
{
|
|
|
|
$this->assertTrue(isset($this->cmsColl['test']));
|
|
|
|
$this->assertEquals($this->cmsUser, $this->cmsColl['test']);
|
2008-07-21 00:13:24 +04:00
|
|
|
}*/
|
2008-02-15 03:57:34 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2008-07-21 00:13:24 +04:00
|
|
|
/*public function shouldSerializeAndUnserializeCollectionWithData()
|
2008-02-15 03:57:34 +03:00
|
|
|
{
|
|
|
|
$serialized = serialize($this->cmsColl);
|
|
|
|
$coll = unserialize($serialized);
|
|
|
|
|
2008-03-23 14:30:29 +03:00
|
|
|
$this->assertEquals('username', $coll->getKeyField());
|
2008-02-15 03:57:34 +03:00
|
|
|
$this->assertTrue(isset($coll['test']));
|
|
|
|
$user = $coll['test'];
|
|
|
|
$this->assertTrue($user instanceOf CmsUser);
|
|
|
|
$this->assertEquals('test', $user['username']);
|
2008-07-21 00:13:24 +04:00
|
|
|
}*/
|
2008-02-15 03:57:34 +03:00
|
|
|
|
|
|
|
}
|