1<?php
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18class Google_Service_YouTubeTest extends BaseTest
19{
20  /** @var Google_Service_YouTube */
21  public $youtube;
22  public function setUp()
23  {
24    $this->checkToken();
25    $this->youtube = new Google_Service_YouTube($this->getClient());
26  }
27
28  public function testMissingFieldsAreNull()
29  {
30    $parts = "id,brandingSettings";
31    $opts = array("mine" => true);
32    $channels = $this->youtube->channels->listChannels($parts, $opts);
33
34    $newChannel = new Google_Service_YouTube_Channel();
35    $newChannel->setId( $channels[0]->getId());
36    $newChannel->setBrandingSettings($channels[0]->getBrandingSettings());
37
38    $simpleOriginal = $channels[0]->toSimpleObject();
39    $simpleNew = $newChannel->toSimpleObject();
40
41    $this->assertObjectHasAttribute('etag', $simpleOriginal);
42    $this->assertObjectNotHasAttribute('etag', $simpleNew);
43
44    $owner_details = new Google_Service_YouTube_ChannelContentOwnerDetails();
45    $owner_details->setTimeLinked("123456789");
46    $o_channel = new Google_Service_YouTube_Channel();
47    $o_channel->setContentOwnerDetails($owner_details);
48    $simpleManual = $o_channel->toSimpleObject();
49    $this->assertObjectHasAttribute('timeLinked', $simpleManual->contentOwnerDetails);
50    $this->assertObjectNotHasAttribute('contentOwner', $simpleManual->contentOwnerDetails);
51
52    $owner_details = new Google_Service_YouTube_ChannelContentOwnerDetails();
53    $owner_details->timeLinked = "123456789";
54    $o_channel = new Google_Service_YouTube_Channel();
55    $o_channel->setContentOwnerDetails($owner_details);
56    $simpleManual = $o_channel->toSimpleObject();
57
58    $this->assertObjectHasAttribute('timeLinked', $simpleManual->contentOwnerDetails);
59    $this->assertObjectNotHasAttribute('contentOwner', $simpleManual->contentOwnerDetails);
60
61    $owner_details = new Google_Service_YouTube_ChannelContentOwnerDetails();
62    $owner_details['timeLinked'] = "123456789";
63    $o_channel = new Google_Service_YouTube_Channel();
64    $o_channel->setContentOwnerDetails($owner_details);
65    $simpleManual = $o_channel->toSimpleObject();
66
67    $this->assertObjectHasAttribute('timeLinked', $simpleManual->contentOwnerDetails);
68    $this->assertObjectNotHasAttribute('contentOwner', $simpleManual->contentOwnerDetails);
69
70    $ping = new Google_Service_YouTube_ChannelConversionPing();
71    $ping->setContext("hello");
72    $pings = new Google_Service_YouTube_ChannelConversionPings();
73    $pings->setPings(array($ping));
74    $simplePings = $pings->toSimpleObject();
75    $this->assertObjectHasAttribute('context', $simplePings->pings[0]);
76    $this->assertObjectNotHasAttribute('conversionUrl', $simplePings->pings[0]);
77  }
78}
79