当前位置: 首页>>代码示例>>PHP>>正文


PHP Book::getValidationFailures方法代码示例

本文整理汇总了PHP中Book::getValidationFailures方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::getValidationFailures方法的具体用法?PHP Book::getValidationFailures怎么用?PHP Book::getValidationFailures使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Book的用法示例。


在下文中一共展示了Book::getValidationFailures方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: doValidate

 /**
  * This function performs the validation work for complex object models.
  *
  * In addition to checking the current object, all related objects will
  * also be validated.  If all pass then <code>true</code> is returned; otherwise
  * an aggreagated array of ValidationFailed objects will be returned.
  *
  * @param      array $columns Array of column names to validate.
  * @return     mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
  */
 protected function doValidate($columns = null)
 {
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         $failureMap = array();
         // We call the validate method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aCategory !== null) {
             if (!$this->aCategory->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aCategory->getValidationFailures());
             }
         }
         if ($this->aBook !== null) {
             if (!$this->aBook->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aBook->getValidationFailures());
             }
         }
         if (($retval = ArticlePeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         if ($this->collAuthorArticles !== null) {
             foreach ($this->collAuthorArticles as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         if ($this->collAttachments !== null) {
             foreach ($this->collAttachments as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
开发者ID:omarcl,项目名称:training-spot,代码行数:51,代码来源:BaseArticle.php

示例2: testScenarioUsingQuery


//.........这里部分代码省略.........
     $r2 = ReviewQuery::create()->findPk($r_id);
     $this->assertEquals(new Datetime('2004-02-29 00:00:00'), $r2->getReviewDate(null), 'ability to fetch DateTime');
     $this->assertEquals($control, $r2->getReviewDate('U'), 'ability to fetch native unix timestamp');
     $this->assertEquals('2-29-2004', $r2->getReviewDate('n-j-Y'), 'ability to use date() formatter');
     // Handle BLOB/CLOB Columns
     // ------------------------
     $blob_path = dirname(__FILE__) . '/../../etc/lob/tin_drum.gif';
     $blob2_path = dirname(__FILE__) . '/../../etc/lob/propel.gif';
     $clob_path = dirname(__FILE__) . '/../../etc/lob/tin_drum.txt';
     $m1 = new Media();
     $m1->setBook($phoenix);
     $m1->setCoverImage(file_get_contents($blob_path));
     $m1->setExcerpt(file_get_contents($clob_path));
     $m1->save();
     $m1_id = $m1->getId();
     $m1_lookup = MediaQuery::create()->findPk($m1_id);
     $this->assertNotNull($m1_lookup, 'Can find just-created media item');
     $this->assertEquals(md5(file_get_contents($blob_path)), md5(stream_get_contents($m1_lookup->getCoverImage())), 'BLOB was correctly updated');
     $this->assertEquals(file_get_contents($clob_path), (string) $m1_lookup->getExcerpt(), 'CLOB was correctly updated');
     // now update the BLOB column and save it & check the results
     $m1_lookup->setCoverImage(file_get_contents($blob2_path));
     $m1_lookup->save();
     $m2_lookup = MediaQuery::create()->findPk($m1_id);
     $this->assertNotNull($m2_lookup, 'Can find just-created media item');
     $this->assertEquals(md5(file_get_contents($blob2_path)), md5(stream_get_contents($m2_lookup->getCoverImage())), 'BLOB was correctly overwritten');
     // Test Validators
     // ---------------
     require_once 'tools/helpers/bookstore/validator/ISBNValidator.php';
     $bk1 = new Book();
     $bk1->setTitle("12345");
     // min length is 10
     $ret = $bk1->validate();
     $this->assertFalse($ret, 'validation failed');
     $failures = $bk1->getValidationFailures();
     $this->assertEquals(1, count($failures), '1 validation message was returned');
     $el = array_shift($failures);
     $this->assertContains("must be more than", $el->getMessage(), 'Expected validation message was returned');
     $bk2 = new Book();
     $bk2->setTitle("Don Juan");
     $ret = $bk2->validate();
     $this->assertFalse($ret, 'validation failed');
     $failures = $bk2->getValidationFailures();
     $this->assertEquals(1, count($failures), '1 validation message was returned');
     $el = array_shift($failures);
     $this->assertContains("Book title already in database.", $el->getMessage(), 'Expected validation message was returned');
     //Now trying some more complex validation.
     $auth1 = new Author();
     $auth1->setFirstName("Hans");
     // last name required; will fail
     $bk1->setAuthor($auth1);
     $rev1 = new Review();
     $rev1->setReviewDate("08/09/2001");
     // will fail: reviewed_by column required
     $bk1->addReview($rev1);
     $ret2 = $bk1->validate();
     $this->assertFalse($ret2, 'validation failed');
     $failures2 = $bk1->getValidationFailures();
     $this->assertEquals(3, count($failures2), '3 validation messages were returned');
     $expectedKeys = array(AuthorPeer::LAST_NAME, BookPeer::TITLE, ReviewPeer::REVIEWED_BY);
     $this->assertEquals($expectedKeys, array_keys($failures2), 'correct columns failed');
     $bk2 = new Book();
     $bk2->setTitle("12345678901");
     // passes
     $auth2 = new Author();
     $auth2->setLastName("Blah");
     //passes
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:67,代码来源:BookstoreTest.php

示例3: boolTest

    print boolTest($m2_lookup->getCoverImage() === file_get_contents($blob2_path));
} catch (Exception $e) {
    die("Error doing blob/clob updates: " . $e->__toString());
}
// Test Validators
// ---------------
try {
    print "\nTesting the column validators\n";
    print "-----------------------------\n\n";
    $bk1 = new Book();
    $bk1->setTitle("12345");
    // min length is 10
    $ret = $bk1->validate();
    print "Making sure validation failed: ";
    print boolTest($ret !== true);
    $failures = $bk1->getValidationFailures();
    print "Making sure 1 validation message was returned: ";
    print boolTest(count($failures) === 1);
    print "Making sure expected validation message was returned: ";
    $el = array_shift($failures);
    print boolTest(stripos($el->getMessage(), "must be more than") !== false);
    print "\n(Unique validator)\n";
    $bk2 = new Book();
    $bk2->setTitle("Don Juan");
    $ret = $bk2->validate();
    print "Making sure validation failed: ";
    print boolTest($ret !== true);
    $failures = $bk2->getValidationFailures();
    print "Making sure 1 validation message was returned: ";
    print boolTest(count($failures) === 1);
    print "Making sure expected validation message was returned: ";
开发者ID:yasirgit,项目名称:afids,代码行数:31,代码来源:bookstore-test.php

示例4: testDoValidate_CustomValidator

 public function testDoValidate_CustomValidator()
 {
     $book = new Book();
     $book->setTitle("testDoValidate_CustomValidator");
     // (valid)
     $book->setISBN("Foo.Bar.Baz");
     // (invalid)
     $res = $book->validate();
     $this->assertFalse($res, "Expected validation to fail.");
     $failures = $book->getValidationFailures();
     $this->assertEquals(1, count($failures), "Expected 1 column to fail validation.");
     $this->assertEquals(array(BookPeer::ISBN), array_keys($failures), "Expected EMAIL to fail validation.");
     $validator = $failures[BookPeer::ISBN]->getValidator();
     $this->assertType('ISBNValidator', $validator, "Expected validator that failed to be ISBNValidator");
 }
开发者ID:nhemsley,项目名称:propel,代码行数:15,代码来源:ValidatorTest.php


注:本文中的Book::getValidationFailures方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。