ServiceTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. class TestModel extends Google_Model
  21. {
  22. public function mapTypes($array)
  23. {
  24. return parent::mapTypes($array);
  25. }
  26. public function isAssociativeArray($array)
  27. {
  28. return parent::isAssociativeArray($array);
  29. }
  30. }
  31. class ServiceTest extends PHPUnit_Framework_TestCase
  32. {
  33. public function testModel()
  34. {
  35. $model = new TestModel();
  36. $model->mapTypes(
  37. array(
  38. 'name' => 'asdf',
  39. 'gender' => 'z',
  40. )
  41. );
  42. $this->assertEquals('asdf', $model->name);
  43. $this->assertEquals('z', $model->gender);
  44. $model->mapTypes(
  45. array(
  46. '__infoType' => 'Google_Model',
  47. '__infoDataType' => 'map',
  48. 'info' => array (
  49. 'location' => 'mars',
  50. 'timezone' => 'mst',
  51. ),
  52. 'name' => 'asdf',
  53. 'gender' => 'z',
  54. )
  55. );
  56. $this->assertEquals('asdf', $model->name);
  57. $this->assertEquals('z', $model->gender);
  58. $this->assertEquals(false, $model->isAssociativeArray(""));
  59. $this->assertEquals(false, $model->isAssociativeArray(false));
  60. $this->assertEquals(false, $model->isAssociativeArray(null));
  61. $this->assertEquals(false, $model->isAssociativeArray(array()));
  62. $this->assertEquals(false, $model->isAssociativeArray(array(1, 2)));
  63. $this->assertEquals(false, $model->isAssociativeArray(array(1 => 2)));
  64. $this->assertEquals(true, $model->isAssociativeArray(array('test' => 'a')));
  65. $this->assertEquals(true, $model->isAssociativeArray(array("a", "b" => 2)));
  66. }
  67. /**
  68. * @dataProvider serviceProvider
  69. */
  70. public function testIncludes($class)
  71. {
  72. $this->assertTrue(
  73. class_exists($class),
  74. sprintf('Failed asserting class %s exists.', $class)
  75. );
  76. }
  77. public function serviceProvider()
  78. {
  79. $classes = array();
  80. $path = dirname(dirname(dirname(__FILE__))) . '/src/Google/Service';
  81. foreach (glob($path . "/*.php") as $file) {
  82. $classes[] = array('Google_Service_' . basename($file, '.php'));
  83. }
  84. return $classes;
  85. }
  86. public function testStrLen()
  87. {
  88. $this->assertEquals(0, Google_Utils::getStrLen(null));
  89. $this->assertEquals(0, Google_Utils::getStrLen(false));
  90. $this->assertEquals(0, Google_Utils::getStrLen(""));
  91. $this->assertEquals(1, Google_Utils::getStrLen(" "));
  92. $this->assertEquals(2, Google_Utils::getStrLen(" 1"));
  93. $this->assertEquals(7, Google_Utils::getStrLen("0a\\n\n\r\n"));
  94. }
  95. }