當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ContentEntityBase::validate方法代碼示例

本文整理匯總了PHP中Drupal\Core\Entity\ContentEntityBase::validate方法的典型用法代碼示例。如果您正苦於以下問題:PHP ContentEntityBase::validate方法的具體用法?PHP ContentEntityBase::validate怎麽用?PHP ContentEntityBase::validate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\Core\Entity\ContentEntityBase的用法示例。


在下文中一共展示了ContentEntityBase::validate方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testRequiredValidation

 /**
  * Tests required validation.
  *
  * @covers ::validate
  * @covers ::isValidationRequired
  * @covers ::setValidationRequired
  * @covers ::save
  * @covers ::preSave
  *
  * @expectedException \LogicException
  * @expectedExceptionMessage Entity validation was skipped.
  */
 public function testRequiredValidation()
 {
     $validator = $this->getMock('\\Symfony\\Component\\Validator\\ValidatorInterface');
     /** @var \Symfony\Component\Validator\ConstraintViolationList|\PHPUnit_Framework_MockObject_MockObject $empty_violation_list */
     $empty_violation_list = $this->getMockBuilder('\\Symfony\\Component\\Validator\\ConstraintViolationList')->setMethods(NULL)->getMock();
     $validator->expects($this->at(0))->method('validate')->with($this->entity->getTypedData())->will($this->returnValue($empty_violation_list));
     $this->typedDataManager->expects($this->any())->method('getValidator')->will($this->returnValue($validator));
     /** @var \Drupal\Core\Entity\EntityStorageInterface|\PHPUnit_Framework_MockObject_MockObject $storage */
     $storage = $this->getMock('\\Drupal\\Core\\Entity\\EntityStorageInterface');
     $storage->expects($this->any())->method('save')->willReturnCallback(function (ContentEntityInterface $entity) use($storage) {
         $entity->preSave($storage);
     });
     $this->entityManager->expects($this->any())->method('getStorage')->with($this->entityTypeId)->will($this->returnValue($storage));
     // Check that entities can be saved normally when validation is not
     // required.
     $this->assertFalse($this->entity->isValidationRequired());
     $this->entity->save();
     // Make validation required and check that if the entity is validated, it
     // can be saved normally.
     $this->entity->setValidationRequired(TRUE);
     $this->assertTrue($this->entity->isValidationRequired());
     $this->entity->validate();
     $this->entity->save();
     // Check that the "validated" status is reset after saving the entity and
     // that trying to save a non-validated entity when validation is required
     // results in an exception.
     $this->assertTrue($this->entity->isValidationRequired());
     $this->entity->save();
 }
開發者ID:aWEBoLabs,項目名稱:taxi,代碼行數:41,代碼來源:ContentEntityBaseUnitTest.php

示例2: testValidate

 /**
  * @covers ::validate
  */
 public function testValidate()
 {
     $validator = $this->getMock('\\Symfony\\Component\\Validator\\ValidatorInterface');
     /** @var \Symfony\Component\Validator\ConstraintViolationList|\PHPUnit_Framework_MockObject_MockObject $empty_violation_list */
     $empty_violation_list = $this->getMockBuilder('\\Symfony\\Component\\Validator\\ConstraintViolationList')->setMethods(NULL)->getMock();
     $non_empty_violation_list = clone $empty_violation_list;
     $violation = $this->getMock('\\Symfony\\Component\\Validator\\ConstraintViolationInterface');
     $non_empty_violation_list->add($violation);
     $validator->expects($this->at(0))->method('validate')->with($this->entity->getTypedData())->will($this->returnValue($empty_violation_list));
     $validator->expects($this->at(1))->method('validate')->with($this->entity->getTypedData())->will($this->returnValue($non_empty_violation_list));
     $this->typedDataManager->expects($this->exactly(2))->method('getValidator')->will($this->returnValue($validator));
     $this->assertSame(0, count($this->entity->validate()));
     $this->assertSame(1, count($this->entity->validate()));
 }
開發者ID:davidsoloman,項目名稱:drupalconsole.com,代碼行數:17,代碼來源:ContentEntityBaseUnitTest.php


注:本文中的Drupal\Core\Entity\ContentEntityBase::validate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。