Skip to content

Commit b0160d5

Browse files
committed
Merge branch 'mightymax-master'
2 parents 3a72102 + f0fdbf4 commit b0160d5

File tree

3 files changed

+118
-2
lines changed

3 files changed

+118
-2
lines changed

src/Google/Spreadsheet/ListFeed.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,21 @@ public function getEntries()
9090

9191
if(count($this->xml->entry) > 0) {
9292
$colNames = $this->getColumnNames($this->xml);
93-
93+
$colNamesCount = count($colNames);
94+
9495
foreach ($this->xml->entry as $entry) {
9596
$cols = $entry->xpath('gsx:*');
9697
$vals = array();
98+
9799
foreach($cols as $col) {
98100
$vals[] = $col->__toString();
99101
}
100-
$rows[] = new ListEntry($entry, array_combine($colNames, $vals));
101102

103+
if(count($vals) < $colNamesCount) {
104+
$vals = array_pad($vals, $colNamesCount, null);
105+
}
106+
107+
$rows[] = new ListEntry($entry, array_combine($colNames, $vals));
102108
}
103109
}
104110
return $rows;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
namespace Google\Spreadsheet;
3+
4+
use PHPUnit_Framework_TestCase;
5+
6+
class ListFeedTest extends PHPUnit_Framework_TestCase
7+
{
8+
9+
public function testGetPostUrl()
10+
{
11+
$xml = file_get_contents(__DIR__.'/xml/list-feed.xml');
12+
$listFeed = new ListFeed($xml);
13+
14+
$this->assertEquals(
15+
'https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full',
16+
$listFeed->getPostUrl()
17+
);
18+
}
19+
20+
public function testInsert()
21+
{
22+
$mockServiceRequest = $this->getMockBuilder('Google\Spreadsheet\DefaultServiceRequest')
23+
->setMethods(array("post"))
24+
->disableOriginalConstructor()
25+
->getMock();
26+
27+
$mockServiceRequest->expects($this->once())
28+
->method('post')
29+
->with(
30+
$this->equalTo('https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full'),
31+
$this->stringContains('<gsx:occupation>software engineer</gsx:occupation>')
32+
);
33+
34+
ServiceRequestFactory::setInstance($mockServiceRequest);
35+
36+
$listFeed = new ListFeed(file_get_contents(__DIR__.'/xml/list-feed.xml'));
37+
$listFeed->insert(["name" => "asim", "occupation" => "software engineer"]);
38+
}
39+
40+
public function testGetEntries()
41+
{
42+
$xml = file_get_contents(__DIR__.'/xml/list-feed.xml');
43+
$listFeed = new ListFeed($xml);
44+
45+
$this->assertEquals(4, count($listFeed->getEntries()));
46+
}
47+
48+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gsx='http://schemas.google.com/spreadsheets/2006/extended'>
3+
<id>https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full</id>
4+
<updated>2014-11-17T21:26:55.831Z</updated>
5+
<category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#list'/>
6+
<title type='text'>Sheet1</title>
7+
<link rel='alternate' type='text/html' href='https://spreadsheets.google.com/ccc?key=G3345eEsfsk60'/>
8+
<link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full'/>
9+
<link rel='http://schemas.google.com/g/2005#post' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full'/>
10+
<link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full'/>
11+
<author>
12+
<name>asimlqt22</name>
13+
<email>asimlqt22@gmail.com</email>
14+
</author>
15+
<openSearch:totalResults>4</openSearch:totalResults>
16+
<openSearch:startIndex>1</openSearch:startIndex>
17+
<entry>
18+
<id>https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full/cokwr</id>
19+
<updated>2014-11-17T21:26:55.831Z</updated>
20+
<category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#list'/>
21+
<title type='text'>asim</title>
22+
<content type='text'>age: 60, _cpzh4: bug</content>
23+
<link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full/cokwr'/>
24+
<link rel='edit' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full/cokwr/bnkj8i7jo6c'/>
25+
<gsx:nname>asim</gsx:nname>
26+
<gsx:age>30</gsx:age>
27+
<gsx:_cpzh4>bug</gsx:_cpzh4>
28+
</entry>
29+
<entry>
30+
<id>https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full/cre1l</id>
31+
<updated>2014-11-17T21:26:55.831Z</updated>
32+
<category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#list'/>
33+
<title type='text'>Cassie</title>
34+
<content type='text'>age: 61</content>
35+
<link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full/cre1l'/>
36+
<link rel='edit' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full/cre1l/k6mclgl'/>
37+
<gsx:nname>Cassie</gsx:nname>
38+
<gsx:age>31</gsx:age>
39+
</entry>
40+
<entry>
41+
<id>https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full/chk2m</id>
42+
<updated>2014-11-17T21:26:55.831Z</updated>
43+
<category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#list'/>
44+
<title type='text'>Alex</title>
45+
<content type='text'>age: 20</content>
46+
<link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full/chk2m'/>
47+
<link rel='edit' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full/chk2m/i45d8c'/>
48+
<gsx:nname>Alex</gsx:nname>
49+
<gsx:age>20</gsx:age>
50+
</entry>
51+
<entry>
52+
<id>https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full/ciyn3</id>
53+
<updated>2014-11-17T21:26:55.831Z</updated>
54+
<category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#list'/>
55+
<title type='text'>Test</title>
56+
<content type='text'>age: 75</content>
57+
<link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full/ciyn3'/>
58+
<link rel='edit' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full/ciyn3/k1lali'/>
59+
<gsx:nname>Test</gsx:nname>
60+
<gsx:age>75</gsx:age>
61+
</entry>
62+
</feed>

0 commit comments

Comments
 (0)