diff options
| author | Horus3 | 2014-02-24 16:42:14 +0100 |
|---|---|---|
| committer | Horus3 | 2014-02-24 16:42:14 +0100 |
| commit | 06f945f27840b53e57795dadbc38e76f7e11ab1c (patch) | |
| tree | 689d5c7f4ffa15460c7e90f47c6a7dd59ce4e8bd /zend/tests/Zend/Gdata/Analytics | |
| download | random-06f945f27840b53e57795dadbc38e76f7e11ab1c.tar.gz | |
init
Diffstat (limited to 'zend/tests/Zend/Gdata/Analytics')
| -rwxr-xr-x | zend/tests/Zend/Gdata/Analytics/AccountFeedTest.php | 71 | ||||
| -rw-r--r-- | zend/tests/Zend/Gdata/Analytics/AccountQueryTest.php | 126 | ||||
| -rw-r--r-- | zend/tests/Zend/Gdata/Analytics/DataFeedTest.php | 80 | ||||
| -rw-r--r-- | zend/tests/Zend/Gdata/Analytics/DataQueryTest.php | 101 | ||||
| -rw-r--r-- | zend/tests/Zend/Gdata/Analytics/_files/TestAccountFeed.xml | 32 | ||||
| -rw-r--r-- | zend/tests/Zend/Gdata/Analytics/_files/TestDataFeed.xml | 76 |
6 files changed, 486 insertions, 0 deletions
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 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Gdata_Analytics + * @subpackage UnitTests + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +require_once 'Zend/Gdata/Analytics.php'; +require_once 'Zend/Http/Client.php'; + +/** + * @category Zend + * @package Zend_Gdata_Analytics + * @subpackage UnitTests + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @group Zend_Gdata + * @group Zend_Gdata_Analytics + */ +class Zend_Gdata_Analytics_AccountFeedTest extends PHPUnit_Framework_TestCase +{ + /** @var AccountFeed */ + public $accountFeed; + + public function setUp() + { + $this->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 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Gdata_Analytics + * @subpackage UnitTests + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +require_once 'Zend/Gdata/Analytics.php'; + +/** + * @category Zend + * @package Zend_Gdata_Analytics + * @subpackage UnitTests + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @group Zend_Gdata + * @group Zend_Gdata_Analytics + */ +class Zend_GData_Analytics_AccountQueryTest extends PHPUnit_Framework_TestCase +{ + /** + * @var Zend_GData_Analytics_AccountQuery + */ + public $accountQuery; + + public function setUp() + { + $this->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 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Gdata_Analytics + * @subpackage UnitTests + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +require_once 'Zend/Gdata/Analytics.php'; +require_once 'Zend/Http/Client.php'; + +/** + * @category Zend + * @package Zend_Gdata_Analytics + * @subpackage UnitTests + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @group Zend_Gdata + * @group Zend_Gdata_Analytics + */ +class Zend_Gdata_Analytics_DataFeedTest extends PHPUnit_Framework_TestCase +{ + public $testData = array( + 'foobarbaz.de' => 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 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Gdata_Analytics + * @subpackage UnitTests + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +require_once 'Zend/Gdata/Analytics.php'; + +/** + * @category Zend + * @package Zend_Gdata_Analytics + * @subpackage UnitTests + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @group Zend_Gdata + * @group Zend_Gdata_Analytics + */ +class Zend_GData_Analytics_DataQueryTest extends PHPUnit_Framework_TestCase +{ + + /** + * @var Zend_GData_Analytics_DataQuery + */ + public $dataQuery; + + public function setUp() + { + $this->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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<feed gd:kind="analytics#accounts" xmlns="http://www.w3.org/2005/Atom" xmlns:dxp="http://schemas.google.com/analytics/2009" xmlns:gd="http://schemas.google.com/g/2005" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/"> + <id>https://www.googleapis.com/analytics/v2.4/management/accounts</id> + <updated>2012-07-13T16:53:15.150Z</updated> + <title type="text">Google Analytics Accounts for mail@storkki.de</title> + <link rel="self" type="application/atom+xml" href="https://www.googleapis.com/analytics/v2.4/management/accounts" /> + <author> + <name>Google Analytics</name> + </author> + <generator>Google Analytics</generator> + <openSearch:totalResults>2</openSearch:totalResults> + <openSearch:startIndex>1</openSearch:startIndex> + <openSearch:itemsPerPage>1000</openSearch:itemsPerPage> + <entry gd:kind="analytics#account"> + <id>https://www.googleapis.com/analytics/v2.4/management/accounts/876543</id> + <updated>2010-03-02T16:04:23.720Z</updated> + <title type="text">Google Analytics Account foobarbaz</title> + <link rel="self" type="application/atom+xml" href="https://www.googleapis.com/analytics/v2.4/management/accounts/876543" /> + <link rel="http://schemas.google.com/ga/2009#child" type="application/atom+xml" gd:targetKind="analytics#webproperties" href="https://www.googleapis.com/analytics/v2.4/management/accounts/876543/webproperties" /> + <dxp:property name="ga:accountId" value="876543" /> + <dxp:property name="ga:accountName" value="foobarbaz" /> + </entry> + <entry gd:kind="analytics#account"> + <id>https://www.googleapis.com/analytics/v2.4/management/accounts/23456789</id> + <updated>2011-05-17T06:53:24.385Z</updated> + <title type="text">Google Analytics Account brain dump</title> + <link rel="self" type="application/atom+xml" href="https://www.googleapis.com/analytics/v2.4/management/accounts/23456789" /> + <link rel="http://schemas.google.com/ga/2009#child" type="application/atom+xml" gd:targetKind="analytics#webproperties" href="https://www.googleapis.com/analytics/v2.4/management/accounts/23456789/webproperties" /> + <dxp:property name="ga:accountId" value="23456789" /> + <dxp:property name="ga:accountName" value="brain dump" /> + </entry> +</feed>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dxp="http://schemas.google.com/analytics/2009" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/"> + <id>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</id> + <updated>2012-07-13T17:05:16.454Z</updated> + <title type="text">Google Analytics Data for Profile 45678912</title> + <link rel="self" type="application/atom+xml" href="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" /> + <author> + <name>Google Analytics</name> + </author> + <generator>Google Analytics</generator> + <openSearch:totalResults>4</openSearch:totalResults> + <openSearch:startIndex>1</openSearch:startIndex> + <openSearch:itemsPerPage>50</openSearch:itemsPerPage> + <dxp:aggregates> + <dxp:metric name="ga:bounces" type="integer" value="9" /> + <dxp:metric name="ga:visits" type="integer" value="20" /> + </dxp:aggregates> + <dxp:containsSampledData>false</dxp:containsSampledData> + <dxp:dataSource> + <dxp:property name="ga:profileId" value="45678912" /> + <dxp:property name="ga:webPropertyId" value="UA-23456789-1" /> + <dxp:property name="ga:accountName" value="foobar" /> + <dxp:tableId>ga:45678912</dxp:tableId> + <dxp:tableName>www.foobar.de</dxp:tableName> + </dxp:dataSource> + <dxp:endDate>2011-05-31</dxp:endDate> + <dxp:startDate>2011-05-01</dxp:startDate> + <entry> + <id>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</id> + <updated>2012-07-13T17:05:16.454Z</updated> + <title type="text">ga:medium=referral | ga:source=foobarbaz.de | ga:browserVersion=4.0.1 | ga:month=05</title> + <link rel="alternate" type="text/html" href="http://www.google.com/analytics" /> + <dxp:dimension name="ga:medium" value="referral" /> + <dxp:dimension name="ga:source" value="foobarbaz.de" /> + <dxp:dimension name="ga:browserVersion" value="4.0.1" /> + <dxp:dimension name="ga:month" value="05" /> + <dxp:metric name="ga:bounces" type="integer" value="5" /> + <dxp:metric name="ga:visits" type="integer" value="12" /> + </entry> + <entry> + <id>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</id> + <updated>2012-07-13T17:05:16.454Z</updated> + <title type="text">ga:medium=referral | ga:source=foobar.de | ga:browserVersion=3.6.17 | ga:month=05</title> + <link rel="alternate" type="text/html" href="http://www.google.com/analytics" /> + <dxp:dimension name="ga:medium" value="referral" /> + <dxp:dimension name="ga:source" value="foobar.de" /> + <dxp:dimension name="ga:browserVersion" value="3.6.17" /> + <dxp:dimension name="ga:month" value="05" /> + <dxp:metric name="ga:bounces" type="integer" value="1" /> + <dxp:metric name="ga:visits" type="integer" value="3" /> + </entry> + <entry> + <id>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</id> + <updated>2012-07-13T17:05:16.454Z</updated> + <title type="text">ga:medium=referral | ga:source=foobarbaz.ch | ga:browserVersion=3.5.19 | ga:month=05</title> + <link rel="alternate" type="text/html" href="http://www.google.com/analytics" /> + <dxp:dimension name="ga:medium" value="referral" /> + <dxp:dimension name="ga:source" value="foobarbaz.ch" /> + <dxp:dimension name="ga:browserVersion" value="3.5.19" /> + <dxp:dimension name="ga:month" value="05" /> + <dxp:metric name="ga:bounces" type="integer" value="1" /> + <dxp:metric name="ga:visits" type="integer" value="1" /> + </entry> + <entry> + <id>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</id> + <updated>2012-07-13T17:05:16.454Z</updated> + <title type="text">ga:medium=referral | ga:source=baz.ch | ga:browserVersion=3.6.17 | ga:month=05</title> + <link rel="alternate" type="text/html" href="http://www.google.com/analytics" /> + <dxp:dimension name="ga:medium" value="referral" /> + <dxp:dimension name="ga:source" value="baz.ch" /> + <dxp:dimension name="ga:browserVersion" value="3.6.17" /> + <dxp:dimension name="ga:month" value="05" /> + <dxp:metric name="ga:bounces" type="integer" value="1" /> + <dxp:metric name="ga:visits" type="integer" value="1" /> + </entry> +</feed>
\ No newline at end of file |
