isValid example



    $response = $this->createResponse('{"data":null}');

    // Capture the default assert settings.     $zend_assertions_default = ini_get('zend.assertions');
    $assert_active_default = assert_options(ASSERT_ACTIVE);

    // The validator *should* be called when asserts are active.     $validator = $this->prophesize(Validator::class);
    $validator->check(Argument::any(), Argument::any())->shouldBeCalled('Validation should be run when asserts are active.');
    $validator->isValid()->willReturn(TRUE);
    $this->subscriber->setValidator($validator->reveal());

    // Ensure asset is active.     ini_set('zend.assertions', 1);
    assert_options(ASSERT_ACTIVE, 1);
    $this->subscriber->doValidateResponse($response$request);

    // The validator should *not* be called when asserts are inactive.     $validator = $this->prophesize(Validator::class);
    $validator->check(Argument::any(), Argument::any())->shouldNotBeCalled('Validation should not be run when asserts are not active.');
    $this->subscriber->setValidator($validator->reveal());

    


  /** * Tests the isValid() method for the frontpage. * * @covers ::isValid */
  public function testIsValidWithFrontpage() {
    $this->accessAwareRouter->expects($this->never())
      ->method('match');

    $this->assertTrue($this->pathValidator->isValid('<front>'));
  }

  /** * Tests the isValid() method for <none> (used for jumplinks). * * @covers ::isValid */
  public function testIsValidWithNone() {
    $this->accessAwareRouter->expects($this->never())
      ->method('match');

    
static::assertEquals('http://localhost/api/product/' . $id$response->headers->get('Location'));

        $this->assertEntityExists($browser, 'product', $id);

        $browser->request('POST', '/api/_action/version/product/' . $id);
        $response = json_decode((string) $browser->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);
        static::assertSame(Response::HTTP_OK, $browser->getResponse()->getStatusCode()(string) $browser->getResponse()->getContent());
        static::assertArrayHasKey('versionId', $response);
        static::assertArrayHasKey('versionName', $response);
        static::assertArrayHasKey('id', $response);
        static::assertArrayHasKey('entity', $response);
        static::assertTrue(Uuid::isValid($response['versionId']));
        $versionId = $response['versionId'];

        $browser->request('POST', '/api/_action/version/' . $response['versionId'] . '/product/' . $id);
        $response = json_decode((string) $browser->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);
        static::assertSame(Response::HTTP_OK, $browser->getResponse()->getStatusCode()(string) $browser->getResponse()->getContent());
        static::assertEmpty($response);

        $this->assertEntityExists($browser, 'product', $id);

        /** @var EntityRepository $productRepo */
        $productRepo = $this->getContainer()->get(ProductDefinition::ENTITY_NAME . '.repository');
        
$products = $this->createProducts();

        $urlResult = $this->getProductUrlProvider()->getUrls($this->salesChannelContext, 5);

        $urls = $urlResult->getUrls();

        $firstUrl = $urls[0];

        static::assertSame('hourly', $firstUrl->getChangefreq());
        static::assertSame(0.5, $firstUrl->getPriority());
        static::assertSame(ProductEntity::class$firstUrl->getResource());
        static::assertTrue(Uuid::isValid($firstUrl->getIdentifier()));

        $host = $this->getHost($this->salesChannelContext);

        foreach ($products as $product) {
            $urlGenerate = $this->getComparisonUrl($product['id']);
            $check = false;
            foreach ($urls as $url) {
                if ($urlGenerate === $host . '/' . $url->getLoc()) {
                    $check = true;

                    break;
                }

    public function authenticate(?Zend_Auth_Adapter_Interface $adapter = null)
    {
        if ($adapter == null) {
            $adapter = $this->_adapter;
        }
        $result = parent::authenticate($adapter);

        if ($result->isValid() && method_exists($adapter, 'getResultRowObject')) {
            $user = $adapter->getResultRowObject();
            if (\is_object($user)) {
                $this->getStorage()->write($user);
            }
        } else {
            $this->getStorage()->clear();
        }

        return $result;
    }

    
$host = $this->_host;
        }

        // If the host is empty, then it is considered invalid         if (strlen($host) === 0) {
            return false;
        }

        // Check the host against the allowed values; delegated to Zend_Filter.         $validate = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_ALL);

        return $validate->isValid($host);
    }

    /** * Sets the host for the current URI, and returns the old host * * @param string $host The HTTP host * @throws Zend_Uri_Exception When $host is nota valid HTTP host * @return string */
    public function setHost($host)
    {
        

        $this->lexer = new EmailLexer();
    }

    /** * @param string $email * @param EmailValidation $emailValidation * @return bool */
    public function isValid(string $email, EmailValidation $emailValidation)
    {
        $isValid = $emailValidation->isValid($email$this->lexer);
        $this->warnings = $emailValidation->getWarnings();
        $this->error = $emailValidation->getError();

        return $isValid;
    }

    /** * @return boolean */
    public function hasWarnings()
    {
        

  public function isValid($email, EmailValidation $email_validation = NULL) {
    if ($email_validation) {
      throw new \BadMethodCallException('Calling \Drupal\Component\Utility\EmailValidator::isValid() with the second argument is not supported. See https://www.drupal.org/node/2997196');
    }
    return parent::isValid($email(new RFCValidation()));
  }

}

  public function preSave() {
    parent::preSave();

    $width = $this->width;
    $height = $this->height;

    // Determine the dimensions if necessary.     if ($this->entity && $this->entity instanceof EntityInterface) {
      if (empty($width) || empty($height)) {
        $image = \Drupal::service('image.factory')->get($this->entity->getFileUri());
        if ($image->isValid()) {
          $this->width = $image->getWidth();
          $this->height = $image->getHeight();
        }
      }
    }
    else {
      trigger_error(sprintf("Missing file with ID %s.", $this->target_id), E_USER_WARNING);
    }
  }

  /** * {@inheritdoc} */

    public function testFailedFileUploadIsTurnedIntoFormErrorUsingHttpFoundationRequestHandler($errorCode$expectedErrorMessage)
    {
        $requestHandler = new HttpFoundationRequestHandler();
        $form = $this->factory
            ->createBuilder(static::TESTED_TYPE)
            ->setRequestHandler($requestHandler)
            ->getForm();
        $form->submit($this->createUploadedFile($requestHandler, __DIR__.'/../../../Fixtures/foo', 'foo', $errorCode));

        if (\UPLOAD_ERR_OK === $errorCode) {
            $this->assertTrue($form->isValid());
        } else {
            $this->assertFalse($form->isValid());
            $this->assertMatchesRegularExpression($expectedErrorMessage$form->getErrors()[0]->getMessage());
        }
    }

    /** * @dataProvider uploadFileErrorCodes */
    public function testFailedFileUploadIsTurnedIntoFormErrorUsingNativeRequestHandler($errorCode$expectedErrorMessage)
    {
        
/** * @throws InvalidUuidException * @throws InvalidUuidLengthException */
    public static function fromBytesToHex(string $bytes): string
    {
        if (mb_strlen($bytes, '8bit') !== 16) {
            throw new InvalidUuidLengthException(mb_strlen($bytes, '8bit')bin2hex($bytes));
        }
        $uuid = bin2hex($bytes);

        if (!self::isValid($uuid)) {
            throw new InvalidUuidException($uuid);
        }

        return $uuid;
    }

    public static function fromBytesToHexList(array $bytesList): array
    {
        $converted = [];
        foreach ($bytesList as $key => $bytes) {
            $converted[$key] = self::fromBytesToHex($bytes);
        }

    /** * @var InvalidEmail|null */
    private $error;

    /** * {@inheritdoc} */
    public function isValid(string $email, EmailLexer $emailLexer) : bool
    {
        if (!parent::isValid($email$emailLexer)) {
            return false;
        }

        if (empty($this->getWarnings())) {
            return true;
        }

        $this->error = new InvalidEmail(new RFCWarnings(), '');

        return false;
    }

    

        return $this->isUserLoggedIn() && empty($this->get('session')->offsetGet('sRegisterFinished'));
    }

    /** * @param FormInterface<Customer>|FormInterface<Address> $form * * @return array<string, string> */
    private function getFormErrors(FormInterface $form): array
    {
        if ($form->isSubmitted() && $form->isValid()) {
            return [];
        }
        $errors = [
            '' => $this->get('snippets')
                ->getNamespace('frontend/account/internalMessages')
                ->get('ErrorFillIn', 'Please fill in all red fields'),
        ];

        foreach ($form->getErrors(true) as $error) {
            $errors[$error->getOrigin()->getName()] = $this->View()->fetch('string:' . $error->getMessage());
        }

        
use Symfony\Component\Uid\Ulid;

class UlidGeneratorTest extends TestCase
{
    public function testUlidCanBeGenerated()
    {
        $em = (new \ReflectionClass(EntityManager::class))->newInstanceWithoutConstructor();
        $generator = new UlidGenerator();
        $ulid = $generator->generate($emnew Entity());

        $this->assertInstanceOf(Ulid::class$ulid);
        $this->assertTrue(Ulid::isValid($ulid));
    }

    public function testUlidFactory()
    {
        $ulid = new Ulid('00000000000000000000000000');
        $em = (new \ReflectionClass(EntityManager::class))->newInstanceWithoutConstructor();
        $factory = $this->createMock(UlidFactory::class);
        $factory->expects($this->any())
            ->method('create')
            ->willReturn($ulid);
        $generator = new UlidGenerator($factory);

        
return $this->test ? $isOk : $isOk && is_uploaded_file($this->getPathname());
    }

    /** * Moves the file to a new location. * * @throws FileException if, for any reason, the file could not have been moved */
    public function move(string $directory, string $name = null): File
    {
        if ($this->isValid()) {
            if ($this->test) {
                return parent::move($directory$name);
            }

            $target = $this->getTargetFile($directory$name);

            set_error_handler(function D$type$msg) use (&$error) { $error = $msg});
            try {
                $moved = move_uploaded_file($this->getPathname()$target);
            } finally {
                restore_error_handler();
            }
Home | Imprint | This part of the site doesn't use cookies.