2
0

MetadataTest.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Tool
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see TestHelper.php
  24. */
  25. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  26. /**
  27. * @see Zend_Tool_Framework_Action_Base
  28. */
  29. require_once 'Zend/Tool/Framework/Manifest/Metadata.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Tool
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. *
  37. * @group Zend_Tool
  38. * @group Zend_Tool_Framework
  39. * @group Zend_Tool_Framework_Manifest
  40. */
  41. class Zend_Tool_Framework_Manifest_MetadataTest extends PHPUnit_Framework_TestCase
  42. {
  43. /**
  44. * @var Zend_Tool_Framework_Manifest_Metadata
  45. */
  46. protected $_metadata = null;
  47. public function setup()
  48. {
  49. $this->_metadata = new Zend_Tool_Framework_Manifest_Metadata();
  50. }
  51. public function teardown()
  52. {
  53. $this->_metadata = null;
  54. }
  55. public function testConstructorWillAcceptAndPersistValues()
  56. {
  57. $obj1 = new ArrayObject();
  58. $metadata = new Zend_Tool_Framework_Manifest_Metadata(array(
  59. 'name' => 'Foo',
  60. 'value' => 'Bar',
  61. 'reference' => $obj1
  62. ));
  63. $this->assertEquals('Foo', $metadata->getName());
  64. $this->assertEquals('Bar', $metadata->getValue());
  65. $this->assertTrue($obj1 === $metadata->getReference());
  66. }
  67. public function testSetOptionsPersistValues()
  68. {
  69. $obj1 = new ArrayObject();
  70. $this->_metadata->setOptions(array(
  71. 'name' => 'Foo',
  72. 'value' => 'Bar',
  73. 'reference' => $obj1
  74. ));
  75. $this->assertEquals('Foo', $this->_metadata->getName());
  76. $this->assertEquals('Bar', $this->_metadata->getValue());
  77. $this->assertTrue($obj1 === $this->_metadata->getReference());
  78. }
  79. public function testGetTypeHasDefaultValue()
  80. {
  81. $this->assertEquals('Global', $this->_metadata->getType());
  82. }
  83. public function testTypeIsModifiable()
  84. {
  85. $this->_metadata->setType('foo');
  86. $this->assertEquals('foo', $this->_metadata->getType());
  87. }
  88. public function testSettersPersistValuesAndAreRetievableThroughGetters()
  89. {
  90. $this->_metadata->setName('Foo');
  91. $this->assertEquals('Foo', $this->_metadata->getName());
  92. $this->_metadata->setValue('Bar');
  93. $this->assertEquals('Bar', $this->_metadata->getValue());
  94. }
  95. public function testGetAttributesReturnsProperValues()
  96. {
  97. $obj1 = new ArrayObject();
  98. $this->_metadata->setOptions(array(
  99. 'name' => 'Foo',
  100. 'value' => null,
  101. 'reference' => $obj1
  102. ));
  103. $attributes = $this->_metadata->getAttributes();
  104. $this->assertEquals(4, count($attributes));
  105. $this->assertEquals('Global', $attributes['type']);
  106. $this->assertEquals('Foo', $attributes['name']);
  107. $this->assertEquals(null, $attributes['value']);
  108. $this->assertTrue($obj1 === $attributes['reference']);
  109. $attributes = $this->_metadata->getAttributes(Zend_Tool_Framework_Manifest_Metadata::ATTRIBUTES_NO_PARENT);
  110. $this->assertEquals(0, count($attributes));
  111. $attributes = $this->_metadata->getAttributes(Zend_Tool_Framework_Manifest_Metadata::ATTRIBUTES_ALL, true);
  112. $this->assertEquals(4, count($attributes));
  113. $this->assertEquals('Global', $attributes['type']);
  114. $this->assertEquals('Foo', $attributes['name']);
  115. $this->assertEquals('(null)', $attributes['value']);
  116. $this->assertEquals('(object)', $attributes['reference']);
  117. }
  118. public function testMetadataObjectCanCastToStringRepresentation()
  119. {
  120. $obj1 = new ArrayObject();
  121. $this->_metadata->setOptions(array(
  122. 'name' => 'Foo',
  123. 'value' => 'Bar',
  124. 'reference' => $obj1
  125. ));
  126. $this->assertEquals('Type: Global, Name: Foo, Value: Bar', (string) $this->_metadata);
  127. }
  128. }