Changeset 4866 for trunk/tests/Orm

Show
Ignore:
Timestamp:
08/31/08 19:27:16 (4 months ago)
Author:
romanb
Message:

checkin of occasional work from the past weeks.

Location:
trunk/tests/Orm
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/tests/Orm/AllTests.php

    r4776 r4866  
    1212require_once 'Orm/Ticket/AllTests.php'; 
    1313require_once 'Orm/Entity/AllTests.php'; 
     14require_once 'Orm/Associations/AllTests.php'; 
    1415 
    1516// Tests 
     
    4041        $suite->addTest(Orm_Entity_AllTests::suite()); 
    4142        $suite->addTest(Orm_Ticket_AllTests::suite()); 
     43        $suite->addTest(Orm_Associations_AllTests::suite()); 
    4244 
    4345        return $suite; 
  • trunk/tests/Orm/Query/LanguageRecognitionTest.php

    r4523 r4866  
    3939class Orm_Query_LanguageRecognitionTest extends Doctrine_OrmTestCase 
    4040{ 
    41     public function assertValidDql($dql) 
     41    public function assertValidDql($dql, $debug = false) 
    4242    { 
    4343        try { 
     
    4646            $parserResult = $query->parse(); 
    4747        } catch (Doctrine_Exception $e) { 
     48            if ($debug) { 
     49                echo $e->getTraceAsString() . PHP_EOL; 
     50            } 
    4851            $this->fail($e->getMessage()); 
    4952        } 
    5053    } 
    5154 
    52     public function assertInvalidDql($dql) 
     55    public function assertInvalidDql($dql, $debug = false) 
    5356    { 
    5457        try { 
     
    6063            $this->fail('No syntax errors were detected, when syntax errors were expected'); 
    6164        } catch (Doctrine_Exception $e) { 
     65            //echo $e->getMessage() . PHP_EOL; 
     66            if ($debug) { 
     67                echo $e->getMessage() . PHP_EOL; 
     68                echo $e->getTraceAsString() . PHP_EOL; 
     69            } 
    6270            // It was expected! 
    6371        } 
     
    352360        $this->assertValidDql("SELECT * FROM CmsUser u WHERE u.name NOT BETWEEN 'jepso' AND 'zYne'"); 
    353361    } 
    354 /* 
    355     public function testAllExpression() 
     362 
     363/*    public function testAllExpressionWithCorrelatedSubquery() 
    356364    { 
    357365        // We need existant classes here, otherwise semantical will always fail 
    358         $this->assertValidDql('SELECT * FROM Employee e WHERE e.salary > ALL (SELECT m.salary FROM Manager m WHERE m.department = e.department)'); 
    359     } 
    360  
    361     public function testAnyExpression() 
     366        $this->assertValidDql('SELECT * FROM CompanyEmployee e WHERE e.salary > ALL (SELECT m.salary FROM CompanyManager m WHERE m.department = e.department)', true); 
     367    } 
     368 
     369    public function testAnyExpressionWithCorrelatedSubquery() 
    362370    { 
    363371        // We need existant classes here, otherwise semantical will always fail 
     
    365373    } 
    366374 
    367     public function testSomeExpression() 
     375    public function testSomeExpressionWithCorrelatedSubquery() 
    368376    { 
    369377        // We need existant classes here, otherwise semantical will always fail 
     
    386394    } 
    387395 
     396    /** 
     397     * TODO: Hydration can't deal with this currently but it should be allowed. 
     398     *       Also, generated SQL looks like: "... FROM cms_user, cms_article ..." which 
     399     *       may not work on all dbms. 
     400     *  
     401     * The main use case for this generalized style of join is when a join condition  
     402     * does not involve a foreign key relationship that is mapped to an entity relationship. 
     403     */ 
     404    public function testImplicitJoinWithCartesianProductAndConditionInWhere() 
     405    { 
     406        $this->assertValidDql("SELECT u.*, a.* FROM CmsUser u, CmsArticle a WHERE u.name = a.topic"); 
     407    } 
     408     
     409    public function testImplicitJoinInWhereOnSingleValuedAssociationPathExpression() 
     410    { 
     411        // This should be allowed because avatar is a single-value association. 
     412        // SQL: SELECT ... FROM forum_user fu INNER JOIN forum_avatar fa ON fu.avatar_id = fa.id WHERE fa.id = ? 
     413        $this->assertValidDql("SELECT u.* FROM ForumUser u WHERE u.avatar.id = ?"); 
     414    } 
     415     
     416    public function testImplicitJoinInWhereOnCollectionValuedPathExpression() 
     417    { 
     418        // This should be forbidden, because articles is a collection 
     419        $this->assertInvalidDql("SELECT u.* FROM CmsUser u WHERE u.articles.title = ?"); 
     420    } 
    388421 
    389422    public function testInvalidSyntaxIsRejected() 
    390423    { 
    391424        $this->assertInvalidDql("FOOBAR CmsUser"); 
    392  
    393425        $this->assertInvalidDql("DELETE FROM CmsUser.articles"); 
    394  
    395426        $this->assertInvalidDql("DELETE FROM CmsUser cu WHERE cu.articles.id > ?"); 
     427        $this->assertInvalidDql("SELECT user FROM CmsUser user"); 
     428         
     429        // Error message here is: Relation 'comments' does not exist in component 'CmsUser' 
     430        // This means it is intepreted as: 
     431        // SELECT u.* FROM CmsUser u JOIN u.articles JOIN u.comments 
     432        // This seems wrong. "JOIN u.articles.comments" should not be allowed. 
     433        $this->assertInvalidDql("SELECT u.* FROM CmsUser u JOIN u.articles.comments"); 
     434         
     435        // Currently UNDEFINED OFFSET error 
     436        $this->assertInvalidDql("SELECT * FROM CmsUser.articles.comments"); 
    396437    } 
    397438