From 06f945f27840b53e57795dadbc38e76f7e11ab1c Mon Sep 17 00:00:00 2001 From: Horus3 Date: Mon, 24 Feb 2014 16:42:14 +0100 Subject: init --- .../tests/Zend/Gdata/Analytics/AccountFeedTest.php | 71 ++++++++++++ .../Zend/Gdata/Analytics/AccountQueryTest.php | 126 +++++++++++++++++++++ zend/tests/Zend/Gdata/Analytics/DataFeedTest.php | 80 +++++++++++++ zend/tests/Zend/Gdata/Analytics/DataQueryTest.php | 101 +++++++++++++++++ .../Gdata/Analytics/_files/TestAccountFeed.xml | 32 ++++++ .../Zend/Gdata/Analytics/_files/TestDataFeed.xml | 76 +++++++++++++ 6 files changed, 486 insertions(+) create mode 100755 zend/tests/Zend/Gdata/Analytics/AccountFeedTest.php create mode 100644 zend/tests/Zend/Gdata/Analytics/AccountQueryTest.php create mode 100644 zend/tests/Zend/Gdata/Analytics/DataFeedTest.php create mode 100644 zend/tests/Zend/Gdata/Analytics/DataQueryTest.php create mode 100644 zend/tests/Zend/Gdata/Analytics/_files/TestAccountFeed.xml create mode 100644 zend/tests/Zend/Gdata/Analytics/_files/TestDataFeed.xml (limited to 'zend/tests/Zend/Gdata/Analytics') diff --git a/zend/tests/Zend/Gdata/Analytics/AccountFeedTest.php b/zend/tests/Zend/Gdata/Analytics/AccountFeedTest.php new file mode 100755 index 0000000..d7b4344 --- /dev/null +++ b/zend/tests/Zend/Gdata/Analytics/AccountFeedTest.php @@ -0,0 +1,71 @@ +accountFeed = new Zend_Gdata_Analytics_AccountFeed( + file_get_contents(dirname(__FILE__) . '/_files/TestAccountFeed.xml') + ); + } + + public function testAccountFeed() + { + $this->assertEquals(2, count($this->accountFeed->entries)); + + foreach ($this->accountFeed->entries as $entry) { + $this->assertInstanceOf('Zend_Gdata_Analytics_AccountEntry', $entry); + } + } + + public function testFirstAccountProperties() + { + $account = $this->accountFeed->entries[0]; + $this->assertEquals(876543, "{$account->accountId}"); + $this->assertEquals('foobarbaz', "{$account->accountName}"); + $this->assertInstanceOf('Zend_GData_App_Extension_Link', $account->link[0]); + } + + public function testSecondAccountProperties() + { + $account = $this->accountFeed->entries[1]; + $this->assertEquals(23456789, "{$account->accountId}"); + $this->assertEquals('brain dump', "{$account->accountName}"); + $this->assertInstanceOf('Zend_GData_App_Extension_Link', $account->link[0]); + } +} diff --git a/zend/tests/Zend/Gdata/Analytics/AccountQueryTest.php b/zend/tests/Zend/Gdata/Analytics/AccountQueryTest.php new file mode 100644 index 0000000..a98f48d --- /dev/null +++ b/zend/tests/Zend/Gdata/Analytics/AccountQueryTest.php @@ -0,0 +1,126 @@ +accountQuery = new Zend_GData_Analytics_AccountQuery(); + $this->queryBase = Zend_GData_Analytics_AccountQuery::ANALYTICS_FEED_URI; + } + + public function testWebpropertiesAll() + { + $this->accountQuery->webproperties(); + $allQuery = $this->accountQuery->getQueryUrl(); + + $this->assertEquals( + $this->queryBase . '/~all/webproperties', + $allQuery + ); + } + + public function testWebpropertiesSpecific() + { + $this->accountQuery->webproperties(12345678); + $specificQuery = $this->accountQuery->getQueryUrl(); + + $this->assertEquals( + $this->queryBase . '/12345678/webproperties', + $specificQuery + ); + } + + public function testProfilesAll() + { + $this->accountQuery->profiles(); + $allQuery = $this->accountQuery->getQueryUrl(); + + $this->assertEquals( + $this->queryBase . '/~all/webproperties/~all/profiles', + $allQuery + ); + } + + public function testProfilesSpecific() + { + $this->accountQuery->profiles('U-87654321-0', 87654321); + $specificQuery = $this->accountQuery->getQueryUrl(); + + $this->assertEquals( + $this->queryBase . '/87654321/webproperties/U-87654321-0/profiles', + $specificQuery + ); + } + + public function testGoalsAll() + { + $this->accountQuery->goals(); + $allQuery = $this->accountQuery->getQueryUrl(); + + $this->assertEquals( + $this->queryBase . '/~all/webproperties/~all/profiles/~all/goals', + $allQuery + ); + } + + public function testGoalsSpecific() + { + $this->accountQuery->goals(42, 'U-87654321-0', 87654321); + $specificQuery = $this->accountQuery->getQueryUrl(); + + $this->assertEquals( + $this->queryBase . '/87654321/webproperties/U-87654321-0/profiles/42/goals', + $specificQuery + ); + } + + public function testChainedProperties() + { + $this->accountQuery + ->goals(42) + ->profiles('U-87654321-0') + ->webproperties(87654321); + $specificQuery = $this->accountQuery->getQueryUrl(); + + $this->assertEquals( + $this->queryBase . '/87654321/webproperties/U-87654321-0/profiles/42/goals', + $specificQuery + ); + } +} diff --git a/zend/tests/Zend/Gdata/Analytics/DataFeedTest.php b/zend/tests/Zend/Gdata/Analytics/DataFeedTest.php new file mode 100644 index 0000000..83b9b19 --- /dev/null +++ b/zend/tests/Zend/Gdata/Analytics/DataFeedTest.php @@ -0,0 +1,80 @@ + 12, + 'foobar.de' => 3, + 'foobarbaz.ch' => 1, + 'baz.ch' => 1, + ); + /** @var DataFeed */ + public $dataFeed; + + public function setUp() + { + $this->dataFeed = new Zend_Gdata_Analytics_DataFeed( + file_get_contents(dirname(__FILE__) . '/_files/TestDataFeed.xml') + ); + } + + public function testDataFeed() + { + $count = count($this->testData); + $this->assertEquals(count($this->dataFeed->entries), $count); + $this->assertEquals($this->dataFeed->entries->count(), $count); + foreach ($this->dataFeed->entries as $entry) { + $this->assertTrue($entry instanceof Zend_Gdata_Analytics_DataEntry); + } + } + + public function testGetters() + { + $sources = array_keys($this->testData); + $values = array_values($this->testData); + + foreach ($this->dataFeed as $index => $row) { + $source = $row->getDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_SOURCE); + $medium = $row->getDimension('ga:medium'); + $visits = $row->getMetric('ga:visits'); + $visitsValue = $row->getValue('ga:visits'); + + $this->assertEquals("$medium", 'referral'); + $this->assertEquals("$source", $sources[$index]); + $this->assertEquals("$visits", $values[$index]); + $this->assertEquals("$visitsValue", $values[$index]); + } + } +} diff --git a/zend/tests/Zend/Gdata/Analytics/DataQueryTest.php b/zend/tests/Zend/Gdata/Analytics/DataQueryTest.php new file mode 100644 index 0000000..f3d4653 --- /dev/null +++ b/zend/tests/Zend/Gdata/Analytics/DataQueryTest.php @@ -0,0 +1,101 @@ +dataQuery = new Zend_GData_Analytics_DataQuery(); + } + + public function testProfileId() + { + $this->assertTrue($this->dataQuery->getProfileId() == null); + $this->dataQuery->setProfileId(123456); + $this->assertTrue($this->dataQuery->getProfileId() == 123456); + } + + public function testAddMetric() + { + $this->assertTrue(count($this->dataQuery->getMetrics()) == 0); + $this->dataQuery->addMetric(Zend_GData_Analytics_DataQuery::METRIC_BOUNCES); + $this->assertTrue(count($this->dataQuery->getMetrics()) == 1); + } + + public function testAddAndRemoveMetric() + { + $this->dataQuery->addMetric(Zend_GData_Analytics_DataQuery::METRIC_BOUNCES); + $this->dataQuery->removeMetric(Zend_GData_Analytics_DataQuery::METRIC_BOUNCES); + $this->assertTrue(count($this->dataQuery->getMetrics()) == 0); + } + + public function testAddDimension() + { + $this->assertTrue(count($this->dataQuery->getDimensions()) == 0); + $this->dataQuery->addDimension(Zend_GData_Analytics_DataQuery::DIMENSION_AD_SLOT); + $this->assertTrue(count($this->dataQuery->getDimensions()) == 1); + } + + public function testAddAndRemoveDimension() + { + $this->dataQuery->addDimension(Zend_GData_Analytics_DataQuery::DIMENSION_AD_SLOT); + $this->dataQuery->removeDimension(Zend_GData_Analytics_DataQuery::DIMENSION_AD_SLOT); + $this->assertTrue(count($this->dataQuery->getDimensions()) == 0); + } + + public function testQueryString() + { + $this->dataQuery + ->setProfileId(123456789) + ->addFilter('foo=bar') + ->addFilter('bar>2') + ->addOrFilter('baz=42') + ->addDimension(Zend_GData_Analytics_DataQuery::DIMENSION_CITY) + ->addMetric(Zend_GData_Analytics_DataQuery::METRIC_PAGEVIEWS) + ->addMetric(Zend_GData_Analytics_DataQuery::METRIC_VISITS); + $url = parse_url($this->dataQuery->getQueryUrl()); + parse_str($url['query'], $parameter); + + $this->assertEquals(count($parameter), 4); + $this->assertEquals($parameter['ids'], "ga:123456789"); + $this->assertEquals($parameter['dimensions'], "ga:city"); + $this->assertEquals($parameter['metrics'], "ga:pageviews,ga:visits"); + $this->assertEquals($parameter['filters'], 'foo=bar;bar>2,baz=42'); + } +} diff --git a/zend/tests/Zend/Gdata/Analytics/_files/TestAccountFeed.xml b/zend/tests/Zend/Gdata/Analytics/_files/TestAccountFeed.xml new file mode 100644 index 0000000..9d2b83a --- /dev/null +++ b/zend/tests/Zend/Gdata/Analytics/_files/TestAccountFeed.xml @@ -0,0 +1,32 @@ + + + https://www.googleapis.com/analytics/v2.4/management/accounts + 2012-07-13T16:53:15.150Z + Google Analytics Accounts for mail@storkki.de + + + Google Analytics + + Google Analytics + 2 + 1 + 1000 + + https://www.googleapis.com/analytics/v2.4/management/accounts/876543 + 2010-03-02T16:04:23.720Z + Google Analytics Account foobarbaz + + + + + + + https://www.googleapis.com/analytics/v2.4/management/accounts/23456789 + 2011-05-17T06:53:24.385Z + Google Analytics Account brain dump + + + + + + \ No newline at end of file diff --git a/zend/tests/Zend/Gdata/Analytics/_files/TestDataFeed.xml b/zend/tests/Zend/Gdata/Analytics/_files/TestDataFeed.xml new file mode 100644 index 0000000..3d9b647 --- /dev/null +++ b/zend/tests/Zend/Gdata/Analytics/_files/TestDataFeed.xml @@ -0,0 +1,76 @@ + + + https://www.googleapis.com/analytics/v2.4/data?ids=ga:45678912&dimensions=ga:medium,ga:source,ga:browserVersion,ga:month&metrics=ga:bounces,ga:visits&sort=-ga:visits,ga:bounces&filters=ga:browser%3D%3DFirefox&start-date=2011-05-01&end-date=2011-05-31&start-index=1&max-results=50 + 2012-07-13T17:05:16.454Z + Google Analytics Data for Profile 45678912 + + + Google Analytics + + Google Analytics + 4 + 1 + 50 + + + + + false + + + + + ga:45678912 + www.foobar.de + + 2011-05-31 + 2011-05-01 + + https://www.googleapis.com/analytics/v2.4/data?ids=ga:45678912&ga:browserVersion=4.0.1&ga:medium=referral&ga:month=05&ga:source=foobarbaz.de&filters=ga:browser%3D%3DFirefox&start-date=2011-05-01&end-date=2011-05-31 + 2012-07-13T17:05:16.454Z + ga:medium=referral | ga:source=foobarbaz.de | ga:browserVersion=4.0.1 | ga:month=05 + + + + + + + + + + https://www.googleapis.com/analytics/v2.4/data?ids=ga:45678912&ga:browserVersion=3.6.17&ga:medium=referral&ga:month=05&ga:source=foobarbaz.de&filters=ga:browser%3D%3DFirefox&start-date=2011-05-01&end-date=2011-05-31 + 2012-07-13T17:05:16.454Z + ga:medium=referral | ga:source=foobar.de | ga:browserVersion=3.6.17 | ga:month=05 + + + + + + + + + + https://www.googleapis.com/analytics/v2.4/data?ids=ga:45678912&ga:browserVersion=3.5.19&ga:medium=referral&ga:month=05&ga:source=foobarbaz.ch&filters=ga:browser%3D%3DFirefox&start-date=2011-05-01&end-date=2011-05-31 + 2012-07-13T17:05:16.454Z + ga:medium=referral | ga:source=foobarbaz.ch | ga:browserVersion=3.5.19 | ga:month=05 + + + + + + + + + + https://www.googleapis.com/analytics/v2.4/data?ids=ga:45678912&ga:browserVersion=3.6.17&ga:medium=referral&ga:month=05&ga:source=foobarbaz.ch&filters=ga:browser%3D%3DFirefox&start-date=2011-05-01&end-date=2011-05-31 + 2012-07-13T17:05:16.454Z + ga:medium=referral | ga:source=baz.ch | ga:browserVersion=3.6.17 | ga:month=05 + + + + + + + + + \ No newline at end of file -- cgit v1.2.3