Ejemplo n.º 1
0
 /**
  * @covers ::setDom
  * @covers ::getDom
  */
 public function testSetDom()
 {
     $subject = new Subject('');
     $dom = new \DOMDocument();
     $subject->setDom($dom);
     $reflector = new \ReflectionClass($subject);
     $domProperty = $reflector->getProperty('dom');
     $domProperty->setAccessible(true);
     $this->assertSame($dom, $domProperty->getValue($subject));
     $this->assertSame($dom, $subject->getDom());
 }
Ejemplo n.º 2
0
 /**
  * @covers ::check
  */
 public function testCheckEmptyAlt()
 {
     $html = '<html><body><img src="" alt=""></body></html>';
     $dom = new \DOMDocument();
     $dom->loadHTML($html);
     $subject = new Subject('');
     $subject->setDom($dom);
     $resultCollection = $this->imageRule->check($subject);
     $this->assertSame(1, $resultCollection->count());
     /**
      * @var Result $result
      */
     $result = $resultCollection->current();
     $this->assertSame('1 img tag is missing alt attribute', $result->getDescription());
 }
Ejemplo n.º 3
0
 /**
  * @covers ::check
  */
 public function testCheckTooManyTitleTags()
 {
     $html = '<html><head><title>Foo</title><title>Bar</title></head></html>';
     $dom = new \DOMDocument();
     $dom->loadHTML($html);
     $subject = new Subject('');
     $subject->setDom($dom);
     $resultCollection = $this->titleRule->check($subject);
     $this->assertSame(1, $resultCollection->count());
     /**
      * @var Result $result
      */
     $result = $resultCollection->current();
     $this->assertSame('There are more than one title tag', $result->getDescription());
 }
Ejemplo n.º 4
0
 /**
  * Check title rules
  *
  * @param Subject $subject
  *
  * @return ResultCollection
  */
 public function check(Subject $subject) : ResultCollection
 {
     $resultCollection = new ResultCollection();
     /**
      * Check
      */
     $contextDescription = $subject->getContextDescription();
     $titleTags = $subject->getDom()->getElementsByTagName('title');
     if ($titleTags->length === 0) {
         $resultCollection->add(new Result($contextDescription, 'Title tag is missing'));
     } else {
         if ($titleTags->length === 1) {
             if (strlen($titleTags->item(0)->nodeValue) > 55) {
                 $resultCollection->add(new Result($contextDescription, 'Title is longer than 55 characters'));
             }
         } else {
             $resultCollection->add(new Result($contextDescription, 'There are more than one title tag'));
         }
     }
     return $resultCollection;
 }
Ejemplo n.º 5
0
 /**
  * Check image rules
  *
  * @param Subject $subject
  *
  * @return ResultCollection
  */
 public function check(Subject $subject) : ResultCollection
 {
     $resultCollection = new ResultCollection();
     /**
      * Check
      */
     $contextDescription = $subject->getContextDescription();
     $imgTags = $subject->getDom()->getElementsByTagName('img');
     /**
      * @var \DOMElement $imgTag
      */
     $missingAltAttributes = 0;
     foreach ($imgTags as $imgTag) {
         $altAttribute = $imgTag->attributes->getNamedItem('alt');
         if (!$altAttribute || empty($altAttribute->nodeValue)) {
             $missingAltAttributes++;
         }
     }
     if ($missingAltAttributes > 0) {
         $resultCollection->add(new Result($contextDescription, "{$missingAltAttributes} img tag is missing alt attribute"));
     }
     return $resultCollection;
 }