FeedTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php defined('SYSPATH') OR die('Kohana bootstrap needs to be included before tests run');
  2. /**
  3. * Test for feed helper
  4. *
  5. * @group kohana
  6. * @group kohana.core
  7. * @group kohana.core.feed
  8. *
  9. * @package Kohana
  10. * @category Tests
  11. * @author Kohana Team
  12. * @author Jeremy Bush <[email protected]>
  13. * @copyright (c) 2008-2012 Kohana Team
  14. * @license http://kohanaframework.org/license
  15. */
  16. class Kohana_FeedTest extends Unittest_TestCase
  17. {
  18. /**
  19. * Provides test data for test_parse()
  20. *
  21. * @return array
  22. */
  23. public function provider_parse()
  24. {
  25. return array(
  26. // $source, $expected
  27. array('http://dev.kohanaframework.org/projects/kohana3/activity.atom', 15),
  28. );
  29. }
  30. /**
  31. * Tests that Feed::parse gets the correct number of elements
  32. *
  33. * @test
  34. * @dataProvider provider_parse
  35. * @covers feed::parse
  36. * @param string $source URL to test
  37. * @param integer $expected Count of items
  38. */
  39. public function test_parse($source, $expected)
  40. {
  41. $this->markTestSkipped('We don\'t go to the internet for tests.');
  42. $this->assertEquals($expected, count(Feed::parse($source)));
  43. }
  44. /**
  45. * Provides test data for test_create()
  46. *
  47. * @return array
  48. */
  49. public function provider_create()
  50. {
  51. $info = array('pubDate' => 123, 'image' => array('link' => 'http://kohanaframework.org/image.png', 'url' => 'http://kohanaframework.org/', 'title' => 'title'));
  52. return array(
  53. // $source, $expected
  54. array($info, array('foo' => array('foo' => 'bar', 'pubDate' => 123, 'link' => 'foo')), array('_SERVER' => array('HTTP_HOST' => 'localhost')+$_SERVER),
  55. array(
  56. 'tag' => 'channel',
  57. 'descendant' => array(
  58. 'tag' => 'item',
  59. 'child' => array(
  60. 'tag' => 'foo',
  61. 'content' => 'bar'
  62. )
  63. )
  64. ),
  65. array(
  66. $this->matcher_composer($info, 'image', 'link'),
  67. $this->matcher_composer($info, 'image', 'url'),
  68. $this->matcher_composer($info, 'image', 'title')
  69. )
  70. ),
  71. );
  72. }
  73. /**
  74. * Helper for handy matcher composing
  75. *
  76. * @param array $data
  77. * @param string $tag
  78. * @param string $child
  79. * @return array
  80. */
  81. private function matcher_composer($data, $tag, $child)
  82. {
  83. return array(
  84. 'tag' => 'channel',
  85. 'descendant' => array(
  86. 'tag' => $tag,
  87. 'child' => array(
  88. 'tag' => $child,
  89. 'content' => $data[$tag][$child]
  90. )
  91. )
  92. );
  93. }
  94. /**
  95. * @test
  96. *
  97. * @dataProvider provider_create
  98. *
  99. * @covers feed::create
  100. *
  101. * @param string $info info to pass
  102. * @param integer $items items to add
  103. * @param integer $matcher output
  104. */
  105. public function test_create($info, $items, $enviroment, $matcher_item, $matchers_image)
  106. {
  107. $this->setEnvironment($enviroment);
  108. $this->assertTag($matcher_item, Feed::create($info, $items), '', FALSE);
  109. foreach ($matchers_image as $matcher_image)
  110. {
  111. $this->assertTag($matcher_image, Feed::create($info, $items), '', FALSE);
  112. }
  113. }
  114. }