| 1 |
<?php |
| 2 |
/** |
| 3 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 4 |
* or more contributor license agreements. See the NOTICE file |
| 5 |
* distributed with this work for additional information |
| 6 |
* regarding copyright ownership. The ASF licenses this file |
| 7 |
* to you under the Apache License, Version 2.0 (the |
| 8 |
* "License"); you may not use this file except in compliance |
| 9 |
* with the License. You may obtain a copy of the License at |
| 10 |
* |
| 11 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
* |
| 13 |
* Unless required by applicable law or agreed to in writing, |
| 14 |
* software distributed under the License is distributed on an |
| 15 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 |
* KIND, either express or implied. See the License for the |
| 17 |
* specific language governing permissions and limitations |
| 18 |
* under the License. |
| 19 |
*/ |
| 20 |
|
| 21 |
class TestModel extends Google_Model |
| 22 |
{ |
| 23 |
public function mapTypes($array) |
| 24 |
{ |
| 25 |
return parent::mapTypes($array); |
| 26 |
} |
| 27 |
|
| 28 |
public function isAssociativeArray($array) |
| 29 |
{ |
| 30 |
return parent::isAssociativeArray($array); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
class ServiceTest extends PHPUnit_Framework_TestCase |
| 35 |
{ |
| 36 |
|
| 37 |
public function testModel() |
| 38 |
{ |
| 39 |
$model = new TestModel(); |
| 40 |
|
| 41 |
$model->mapTypes( |
| 42 |
array( |
| 43 |
'name' => 'asdf', |
| 44 |
'gender' => 'z', |
| 45 |
) |
| 46 |
); |
| 47 |
$this->assertEquals('asdf', $model->name); |
| 48 |
$this->assertEquals('z', $model->gender); |
| 49 |
$model->mapTypes( |
| 50 |
array( |
| 51 |
'__infoType' => 'Google_Model', |
| 52 |
'__infoDataType' => 'map', |
| 53 |
'info' => array ( |
| 54 |
'location' => 'mars', |
| 55 |
'timezone' => 'mst', |
| 56 |
), |
| 57 |
'name' => 'asdf', |
| 58 |
'gender' => 'z', |
| 59 |
) |
| 60 |
); |
| 61 |
$this->assertEquals('asdf', $model->name); |
| 62 |
$this->assertEquals('z', $model->gender); |
| 63 |
|
| 64 |
$this->assertEquals(false, $model->isAssociativeArray("")); |
| 65 |
$this->assertEquals(false, $model->isAssociativeArray(false)); |
| 66 |
$this->assertEquals(false, $model->isAssociativeArray(null)); |
| 67 |
$this->assertEquals(false, $model->isAssociativeArray(array())); |
| 68 |
$this->assertEquals(false, $model->isAssociativeArray(array(1, 2))); |
| 69 |
$this->assertEquals(false, $model->isAssociativeArray(array(1 => 2))); |
| 70 |
|
| 71 |
$this->assertEquals(true, $model->isAssociativeArray(array('test' => 'a'))); |
| 72 |
$this->assertEquals(true, $model->isAssociativeArray(array("a", "b" => 2))); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* @dataProvider serviceProvider |
| 77 |
*/ |
| 78 |
public function testIncludes($class) |
| 79 |
{ |
| 80 |
$this->assertTrue( |
| 81 |
class_exists($class), |
| 82 |
sprintf('Failed asserting class %s exists.', $class) |
| 83 |
); |
| 84 |
} |
| 85 |
|
| 86 |
public function serviceProvider() |
| 87 |
{ |
| 88 |
$classes = array(); |
| 89 |
$path = dirname(dirname(dirname(__FILE__))) . '/src/Google/Service'; |
| 90 |
foreach (glob($path . "/*.php") as $file) { |
| 91 |
$classes[] = array('Google_Service_' . basename($file, '.php')); |
| 92 |
} |
| 93 |
|
| 94 |
return $classes; |
| 95 |
} |
| 96 |
|
| 97 |
public function testStrLen() |
| 98 |
{ |
| 99 |
$this->assertEquals(0, Google_Utils::getStrLen(null)); |
| 100 |
$this->assertEquals(0, Google_Utils::getStrLen(false)); |
| 101 |
$this->assertEquals(0, Google_Utils::getStrLen("")); |
| 102 |
|
| 103 |
$this->assertEquals(1, Google_Utils::getStrLen(" ")); |
| 104 |
$this->assertEquals(2, Google_Utils::getStrLen(" 1")); |
| 105 |
$this->assertEquals(7, Google_Utils::getStrLen("0a\\n\n\r\n")); |
| 106 |
} |
| 107 |
} |
| 108 |
|