Projet

Général

Profil

Paste
Télécharger (2,15 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / feeds / tests / FeedsEnclosureTest.test @ ed9a13f1

1
<?php
2

    
3
/**
4
 * @coversDefaultClass FeedsEnclosure
5
 * @group feeds
6
 */
7
class FeedsEnclosureTest extends FeedsWebTestCase {
8

    
9
  /**
10
   * {@inheritdoc}
11
   */
12
  public static function getInfo() {
13
    return array(
14
      'name' => 'FeedsEnclosure class test',
15
      'description' => 'Covers class FeedsEnclosure.',
16
      'group' => 'Feeds',
17
    );
18
  }
19

    
20
  /**
21
   * Tests getting content from an URL that failed to parse.
22
   *
23
   * @see ::getUrlParseErrorDataProvider()
24
   */
25
  public function testUrlParseError() {
26
    foreach ($this->getUrlParseErrorDataProvider() as $testdata) {
27
      $e = NULL;
28
      $vars = $testdata['vars'] + array(
29
        '@url' => $testdata['url'],
30
      );
31

    
32
      // Create a new enclosure.
33
      $enclosure = new FeedsEnclosure($testdata['url'], 'text/plain');
34
      try {
35
        // The enclosure will try to download the content via HTTP.
36
        $enclosure->getContent();
37
      }
38
      catch (Exception $e) {
39
        $this->pass(format_string("Exception thrown on url '@url'.", $vars));
40
        $this->assertEqual(format_string($testdata['error'], $vars), $e->getMessage());
41
      }
42
      if (!isset($e)) {
43
        $this->fail(format_string("Exception thrown on url '@url'.", $vars));
44
      }
45
    }
46
  }
47

    
48
  /**
49
   * Data provider for ::testUrlParseError().
50
   */
51
  protected function getUrlParseErrorDataProvider() {
52
    return array(
53
      array(
54
        'url' => 'http://',
55
        'error' => 'Download of @url failed because it could not be parsed.',
56
        'vars' => array(),
57
      ),
58
      array(
59
        'url' => '//www.example.com/path?foo=bar',
60
        'error' => "Download of @url failed because its scheme could not be determined. The URL is expected to start with something like '@example'.",
61
        'vars' => array(
62
          '@example' => 'http://',
63
        ),
64
      ),
65
      array(
66
        'url' => 'nonsupportedscheme://www.example.com',
67
        'error' => 'Download of @url failed because its scheme is not supported: @error. Examples of supported schemes are: @supported.',
68
        'vars' => array(
69
          '@error' => 'invalid schema nonsupportedscheme',
70
          '@supported' => implode(', ', array('http', 'https')),
71
        ),
72
      ),
73
    );
74
  }
75

    
76
}