You are here

class HttpHelpersTest in Feeds 8.3

@coversDefaultClass \Drupal\feeds\Component\HttpHelpers @group feeds

Hierarchy

Expanded class hierarchy of HttpHelpersTest

File

tests/src/Unit/Component/HttpHelpersTest.php, line 12

Namespace

Drupal\Tests\feeds\Unit\Component
View source
class HttpHelpersTest extends UnitTestCase {

  /**
   * Tests finding relation links in several headers.
   *
   * @dataProvider httpResponses
   */
  public function testFindLinkHeader($headers, $rel, $expected) {
    $this
      ->assertSame($expected, HttpHelpers::findLinkHeader($headers, $rel));
  }

  /**
   * @covers ::findRelationFromXml
   */
  public function testFindLinkXml() {
    $xml = '<feed xmlns="http://www.w3.org/2005/Atom">
            <title>Blah blah blah</title>
            <link href="http://example.com/feed" rel="self" type="application/atom+xml"/>
            <link href="http://example.com" rel="alternate" type="text/html"/>
            <link rel="hub" href="http://example.com/hub" />
            <updated>2015-02-03T13:08:02+01:00</updated>
            <id>http://blog.superfeedr.com/</id></feed>';
    $this
      ->assertSame('http://example.com/hub', HttpHelpers::findRelationFromXml($xml, 'hub'));
    $xml = '<?xml version="1.0"?>
            <rss xmlns:atom="http://www.w3.org/2005/Atom">
            <channel>
            <atom:link rel="hub" href="http://example.com/hub"/>
            </channel></rss>';
    $this
      ->assertSame('http://example.com/hub', HttpHelpers::findRelationFromXml($xml, 'hub'));
    $this
      ->assertSame(FALSE, HttpHelpers::findRelationFromXml('', 'hub'));
    $this
      ->assertSame(FALSE, HttpHelpers::findRelationFromXml(' ', 'hub'));
  }

  /**
   * Data provider for testFindLinkHeader().
   */
  public function httpResponses() {
    $headers1 = [
      'Link' => '<http://example.com/TheBook/chapter2>;
         rel="previous";
         title="previous chapter"',
    ];
    $headers2 = [
      'Link' => [
        '<http://example.com/TheBook/chapter2>; rel="previous";
         title="previous chapter"',
      ],
    ];
    $headers3 = [
      'LINK' => '</>; rel="http://example.net/foo"',
    ];
    $headers4 = [
      'link' => '<http://example.com>; rel="hub self"',
    ];
    $headers5 = [
      'link' => '</TheBook/chapter2>;
         rel="previous"; title*=UTF-8\'de\'letztes%20Kapitel,
         </TheBook/chapter4>;
         rel="next"; title*=UTF-8\'de\'n%c3%a4chstes%20Kapitel',
    ];
    $headers6 = [
      'link' => '<http://example.com>; rel=hub',
    ];
    $headers7 = [
      'link' => '<http://example.com>; rel= hub ',
    ];
    return [
      [
        $headers1,
        'previous',
        'http://example.com/TheBook/chapter2',
      ],
      [
        $headers2,
        'previous',
        'http://example.com/TheBook/chapter2',
      ],
      [
        $headers3,
        'http://example.net/foo',
        '/',
      ],
      [
        $headers4,
        'hub',
        'http://example.com',
      ],
      [
        $headers4,
        'self',
        'http://example.com',
      ],
      [
        $headers5,
        'next',
        '/TheBook/chapter4',
      ],
      [
        $headers6,
        'hub',
        'http://example.com',
      ],
      [
        $headers7,
        'hub',
        'http://example.com',
      ],
      [
        $headers7,
        'self',
        FALSE,
      ],
      [
        [],
        'hub',
        FALSE,
      ],
      [
        [
          'link' => '',
        ],
        'hub',
        FALSE,
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HttpHelpersTest::httpResponses public function Data provider for testFindLinkHeader().
HttpHelpersTest::testFindLinkHeader public function Tests finding relation links in several headers.
HttpHelpersTest::testFindLinkXml public function @covers ::findRelationFromXml
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340