DataQueryTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. /**
  24. * @category Zend
  25. * @package Zend_Gdata_Analytics
  26. * @subpackage UnitTests
  27. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. * @group Zend_Gdata
  30. * @group Zend_Gdata_Analytics
  31. */
  32. class Zend_GData_Analytics_DataQueryTest extends PHPUnit_Framework_TestCase
  33. {
  34. /**
  35. * @var Zend_GData_Analytics_DataQuery
  36. */
  37. public $dataQuery;
  38. public function setUp()
  39. {
  40. $this->dataQuery = new Zend_GData_Analytics_DataQuery();
  41. }
  42. public function testProfileId()
  43. {
  44. $this->assertTrue($this->dataQuery->getProfileId() == null);
  45. $this->dataQuery->setProfileId(123456);
  46. $this->assertTrue($this->dataQuery->getProfileId() == 123456);
  47. }
  48. public function testAddMetric()
  49. {
  50. $this->assertTrue(count($this->dataQuery->getMetrics()) == 0);
  51. $this->dataQuery->addMetric(Zend_GData_Analytics_DataQuery::METRIC_BOUNCES);
  52. $this->assertTrue(count($this->dataQuery->getMetrics()) == 1);
  53. }
  54. public function testAddAndRemoveMetric()
  55. {
  56. $this->dataQuery->addMetric(Zend_GData_Analytics_DataQuery::METRIC_BOUNCES);
  57. $this->dataQuery->removeMetric(Zend_GData_Analytics_DataQuery::METRIC_BOUNCES);
  58. $this->assertTrue(count($this->dataQuery->getMetrics()) == 0);
  59. }
  60. public function testAddDimension()
  61. {
  62. $this->assertTrue(count($this->dataQuery->getDimensions()) == 0);
  63. $this->dataQuery->addDimension(Zend_GData_Analytics_DataQuery::DIMENSION_AD_SLOT);
  64. $this->assertTrue(count($this->dataQuery->getDimensions()) == 1);
  65. }
  66. public function testAddAndRemoveDimension()
  67. {
  68. $this->dataQuery->addDimension(Zend_GData_Analytics_DataQuery::DIMENSION_AD_SLOT);
  69. $this->dataQuery->removeDimension(Zend_GData_Analytics_DataQuery::DIMENSION_AD_SLOT);
  70. $this->assertTrue(count($this->dataQuery->getDimensions()) == 0);
  71. }
  72. public function testQueryString()
  73. {
  74. $this->dataQuery
  75. ->setProfileId(123456789)
  76. ->addFilter('foo=bar')
  77. ->addFilter('bar>2')
  78. ->addOrFilter('baz=42')
  79. ->addDimension(Zend_GData_Analytics_DataQuery::DIMENSION_CITY)
  80. ->addMetric(Zend_GData_Analytics_DataQuery::METRIC_PAGEVIEWS)
  81. ->addMetric(Zend_GData_Analytics_DataQuery::METRIC_VISITS);
  82. $url = parse_url($this->dataQuery->getQueryUrl());
  83. parse_str($url['query'], $parameter);
  84. $this->assertEquals(count($parameter), 4);
  85. $this->assertEquals($parameter['ids'], "ga:123456789");
  86. $this->assertEquals($parameter['dimensions'], "ga:city");
  87. $this->assertEquals($parameter['metrics'], "ga:pageviews,ga:visits");
  88. $this->assertEquals($parameter['filters'], 'foo=bar;bar>2,baz=42');
  89. }
  90. }