/** * @covers Kunstmaan\MediaBundle\Entity\Media::getMetadata * @covers Kunstmaan\MediaBundle\Entity\Media::getMetadataValue * @covers Kunstmaan\MediaBundle\Entity\Media::setMetadata * @covers Kunstmaan\MediaBundle\Entity\Media::setMetadataValue */ public function testGetSetMetaDataAndValues() { $meta = array('original_width' => 320, 'original_height' => 200); $this->object->setMetadata($meta); $this->assertEquals($meta, $this->object->getMetadata()); $this->assertEquals(320, $this->object->getMetadataValue('original_width')); $this->assertEquals(200, $this->object->getMetadataValue('original_height')); $this->object->setMetadataValue('original_width', 640); $this->assertEquals(640, $this->object->getMetadataValue('original_width')); }
private function validateDimensions(MediaObject $value, Media $constraint) { $height = $value->getMetadataValue('original_height'); $width = $value->getMetadataValue('original_width'); if ($constraint->minHeight) { if (!ctype_digit((string) $constraint->minHeight)) { throw new ConstraintDefinitionException(sprintf('"%s" is not a valid minimum height', $constraint->minHeight)); } if ($height < $constraint->minHeight) { $this->context->buildViolation($constraint->minHeightMessage)->setParameter('{{ height }}', $height)->setParameter('{{ min_height }}', $constraint->minHeight)->setCode(Media::TOO_LOW_ERROR)->addViolation(); return; } } if ($constraint->maxHeight) { if (!ctype_digit((string) $constraint->maxHeight)) { throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum height', $constraint->maxHeight)); } if ($height > $constraint->maxHeight) { $this->context->buildViolation($constraint->maxHeightMessage)->setParameter('{{ height }}', $height)->setParameter('{{ max_height }}', $constraint->maxHeight)->setCode(Media::TOO_HIGH_ERROR)->addViolation(); return; } } if ($constraint->minWidth) { if (!ctype_digit((string) $constraint->minWidth)) { throw new ConstraintDefinitionException(sprintf('"%s" is not a valid minimum width', $constraint->minWidth)); } if ($width < $constraint->minWidth) { $this->context->buildViolation($constraint->minWidthMessage)->setParameter('{{ width }}', $width)->setParameter('{{ min_width }}', $constraint->minWidth)->setCode(Media::TOO_NARROW_ERROR)->addViolation(); return; } } if ($constraint->maxWidth) { if (!ctype_digit((string) $constraint->maxWidth)) { throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum width', $constraint->maxWidth)); } if ($width > $constraint->maxWidth) { $this->context->buildViolation($constraint->maxWidthMessage)->setParameter('{{ width }}', $width)->setParameter('{{ max_width }}', $constraint->maxWidth)->setCode(Media::TOO_WIDE_ERROR)->addViolation(); return; } } }
/** * Get type * * @return string|null */ public function getType() { return $this->media->getMetadataValue('type'); }