Image example



namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Tests\Section\Field;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\Section\Field\Image;

final class ImageTest extends TestCase
{
    public function testImage()
    {
        $field = (new Image())
            ->image($value = 'https://symfony.com/logo.png');

        $this->assertSame($value$field->toArray()['image']);
    }

    public function testTitle()
    {
        $field = (new Image())
            ->title($value = 'Symfony is great!');

        $this->assertSame($value$field->toArray()['title']);
    }
$this->image = __DIR__.'/Fixtures/test.gif';
        $this->imageLandscape = __DIR__.'/Fixtures/test_landscape.gif';
        $this->imagePortrait = __DIR__.'/Fixtures/test_portrait.gif';
        $this->image4By3 = __DIR__.'/Fixtures/test_4by3.gif';
        $this->image16By9 = __DIR__.'/Fixtures/test_16by9.gif';
        $this->imageCorrupted = __DIR__.'/Fixtures/test_corrupted.gif';
        $this->notAnImage = __DIR__.'/Fixtures/ccc.txt';
    }

    public function testNullIsValid()
    {
        $this->validator->validate(null, new Image());

        $this->assertNoViolation();
    }

    public function testEmptyStringIsValid()
    {
        $this->validator->validate('', new Image());

        $this->assertNoViolation();
    }

    

  public function get($source = NULL, $toolkit_id = NULL) {
    $toolkit_id = $toolkit_id ?: $this->toolkitId;
    return new Image($this->toolkitManager->createInstance($toolkit_id)$source);
  }

  /** * Returns the image file extensions supported by the toolkit. * * @param string|null $toolkit_id * (optional) The ID of the image toolkit to use for checking, or NULL * to use the current toolkit. * * @return array * An array of supported image file extensions (e.g. png/jpeg/gif). * * @see \Drupal\Core\ImageToolkit\ImageToolkitInterface::getSupportedExtensions() */

                }
            }

            if (!empty($data['mediaId'])) {
                $data['media'] = $this->get('models')->find(Media::class$data['mediaId']);
                if (!$data['media']) {
                    unset($data['media']);
                }
            }

            $image = new Image();
            $image->fromArray($data);
            $image->setArticle($product);
            $image->setArticleDetail(null);

            $this->get('models')->persist($image);
        }

        $this->get('models')->flush();
    }

    /** * Internal helper function to duplicate the property configuration from the passed product * to the new product. * * @param int $articleId * @param int $newArticleId */
use PHPUnit\Framework\TestCase;
use Symfony\Component\DomCrawler\Image;

class ImageTest extends TestCase
{
    public function testConstructorWithANonImgTag()
    {
        $this->expectException(\LogicException::class);
        $dom = new \DOMDocument();
        $dom->loadHTML('<html><div><div></html>');

        new Image($dom->getElementsByTagName('div')->item(0), 'http://www.example.com/');
    }

    public function testBaseUriIsOptionalWhenImageUrlIsAbsolute()
    {
        $dom = new \DOMDocument();
        $dom->loadHTML('<html><img alt="foo" src="https://example.com/foo" /></html>');

        $image = new Image($dom->getElementsByTagName('img')->item(0));
        $this->assertSame('https://example.com/foo', $image->getUri());
    }

    

        if (!\count($this)) {
            throw new \InvalidArgumentException('The current node list is empty.');
        }

        $node = $this->getNode(0);

        if (!$node instanceof \DOMElement) {
            throw new \InvalidArgumentException(sprintf('The selected node should be instance of DOMElement, got "%s".', get_debug_type($node)));
        }

        return new Image($node$this->baseHref);
    }

    /** * Returns an array of Image objects for the nodes in the list. * * @return Image[] */
    public function images(): array
    {
        $images = [];
        foreach ($this as $node) {
            
'activityImage' => $imageUrl,
                'activityTitle' => $title,
                'activitySubtitle' => $subtitle,
                'activityText' => $text,
            ],
            $section->toArray()
        );
    }

    public function testImage()
    {
        $image = (new Image())
            ->image($imageUrl = 'https://symfony.com/logo.png')
            ->title($title = 'Symfony logo');

        $section = (new Section())
            ->image($image);

        $this->assertCount(1, $section->toArray()['images']);
        $this->assertSame(
            [
                ['image' => $imageUrl, 'title' => $title],
            ],
            

        return $this->prepareData($data$article$variant);
    }

    /** * Helper function which creates a variant image for the passed product image. * * @return Image */
    public function createVariantImage(Image $articleImage, Detail $variant)
    {
        $variantImage = new Image();
        $variantImage->setParent($articleImage);
        $variantImage->setArticleDetail($variant);
        $variantImage->setPosition($articleImage->getPosition());
        $variantImage->setMain($articleImage->getMain());
        $variantImage->setExtension($articleImage->getExtension());

        return $variantImage;
    }

    /** * @param Collection|array $options * * @return Mapping */

        $this->getManager()->flush();
    }

    /** * Helper function which creates a new product image with the passed media object. * * @return Image */
    public function createNewArticleImage(ProductModel $article, MediaModel $media)
    {
        $image = new Image();
        $image = $this->updateArticleImageWithMedia(
            $article,
            $image,
            $media
        );
        $this->getManager()->persist($image);
        $article->getImages()->add($image);

        return $image;
    }

    

    public function withFile(string $path)
    {
        // Clear out the old resource so that         // it doesn't try to use a previous image         $this->resource = null;
        $this->verified = false;

        $this->image = new Image($path, true);

        $this->image->getProperties(false);
        $this->width  = $this->image->origWidth;
        $this->height = $this->image->origHeight;

        return $this;
    }

    /** * Make the image resource object if needed * * @return void */
$this->toolkit = $this->getToolkitMock($stubs);

    $this->toolkit->expects($this->any())
      ->method('getPluginId')
      ->willReturn('gd');

    if (!$load_expected) {
      $this->toolkit->expects($this->never())
        ->method('load');
    }

    $this->image = new Image($this->toolkit, $this->source);

    return $this->image;
  }

  /** * Get an image with mocked toolkit and operation, for operation testing. * * @param string $class_name * The name of the GD toolkit operation class to be mocked. * * @return \Drupal\Core\Image\Image * An image object. */
Home | Imprint | This part of the site doesn't use cookies.