DataFeedTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata_Analytics
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once 'Zend/Gdata/Analytics.php';
  23. require_once 'Zend/Http/Client.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Gdata_Analytics
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @group Zend_Gdata
  31. * @group Zend_Gdata_Analytics
  32. */
  33. class Zend_Gdata_Analytics_DataFeedTest extends PHPUnit_Framework_TestCase
  34. {
  35. public $testData = array(
  36. 'foobarbaz.de' => 12,
  37. 'foobar.de' => 3,
  38. 'foobarbaz.ch' => 1,
  39. 'baz.ch' => 1,
  40. );
  41. /** @var DataFeed */
  42. public $dataFeed;
  43. public function setUp()
  44. {
  45. $this->dataFeed = new Zend_Gdata_Analytics_DataFeed(
  46. file_get_contents(dirname(__FILE__) . '/_files/TestDataFeed.xml')
  47. );
  48. }
  49. public function testDataFeed()
  50. {
  51. $count = count($this->testData);
  52. $this->assertEquals(count($this->dataFeed->entries), $count);
  53. $this->assertEquals($this->dataFeed->entries->count(), $count);
  54. foreach ($this->dataFeed->entries as $entry) {
  55. $this->assertTrue($entry instanceof Zend_Gdata_Analytics_DataEntry);
  56. }
  57. }
  58. public function testGetters()
  59. {
  60. $sources = array_keys($this->testData);
  61. $values = array_values($this->testData);
  62. foreach ($this->dataFeed as $index => $row) {
  63. $source = $row->getDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_SOURCE);
  64. $medium = $row->getDimension('ga:medium');
  65. $visits = $row->getMetric('ga:visits');
  66. $visitsValue = $row->getValue('ga:visits');
  67. $this->assertEquals("$medium", 'referral');
  68. $this->assertEquals("$source", $sources[$index]);
  69. $this->assertEquals("$visits", $values[$index]);
  70. $this->assertEquals("$visitsValue", $values[$index]);
  71. }
  72. }
  73. }