コード例 #1
0
 /**
  * @param ElementInterface $element
  *
  * @throws ValidationError
  */
 public function validate(ElementInterface $element)
 {
     if ($element->isLeaf()) {
         if (strlen($element->getContent()) === 0) {
             throw new ValidationError(sprintf($this->message, 'content'));
         }
     } else {
         if (count($element->getChildren()) === 0) {
             throw new ValidationError(sprintf($this->message, 'children[]'));
         }
     }
 }
コード例 #2
0
 /**
  * @param ElementInterface $element
  *
  * @throws ValidationError
  */
 public function validate(ElementInterface $element)
 {
     $children = $element->getChildren();
     $allowed = $element->getAllowedChildren();
     $unallowed = [];
     foreach ($children as $child) {
         if (!in_array($child->getName(), $allowed)) {
             $unallowed[] = $child->getName();
         }
     }
     if (count($unallowed) > 0) {
         throw new ValidationError(sprintf($this->message, $element->getName(), implode(', ', $unallowed), implode(', ', $element->getAllowedChildren())));
     }
 }
コード例 #3
0
 /**
  * @param ElementInterface        $element
  * @param string|ElementInterface $children
  * @param bool                    $supports
  * @dataProvider testIsAllowedTrueDataProvider
  */
 public function testIsAllowed(ElementInterface $element, $children, $supports)
 {
     $this->assertEquals($element->isAllowed($children), $supports);
 }