2
0

MetadataTest.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @see TestHelper.php
  23. */
  24. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  25. /**
  26. * @see Zend_Tool_Framework_Action_Base
  27. */
  28. require_once 'Zend/Tool/Framework/Manifest/Metadata.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Tool
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. *
  36. * @group Zend_Tool_Framework
  37. * @group Zend_Tool_Framework_Action
  38. */
  39. class Zend_Tool_Framework_Manifest_MetadataTest extends PHPUnit_Framework_TestCase
  40. {
  41. /**
  42. * @var Zend_Tool_Framework_Manifest_Metadata
  43. */
  44. protected $_metadata = null;
  45. public function setup()
  46. {
  47. $this->_metadata = new Zend_Tool_Framework_Manifest_Metadata();
  48. }
  49. public function teardown()
  50. {
  51. $this->_metadata = null;
  52. }
  53. public function testConstructorWillAcceptAndPersistValues()
  54. {
  55. $obj1 = new ArrayObject();
  56. $metadata = new Zend_Tool_Framework_Manifest_Metadata(array(
  57. 'name' => 'Foo',
  58. 'value' => 'Bar',
  59. 'reference' => $obj1
  60. ));
  61. $this->assertEquals('Foo', $metadata->getName());
  62. $this->assertEquals('Bar', $metadata->getValue());
  63. $this->assertTrue($obj1 === $metadata->getReference());
  64. }
  65. public function testSetOptionsPersistValues()
  66. {
  67. $obj1 = new ArrayObject();
  68. $this->_metadata->setOptions(array(
  69. 'name' => 'Foo',
  70. 'value' => 'Bar',
  71. 'reference' => $obj1
  72. ));
  73. $this->assertEquals('Foo', $this->_metadata->getName());
  74. $this->assertEquals('Bar', $this->_metadata->getValue());
  75. $this->assertTrue($obj1 === $this->_metadata->getReference());
  76. }
  77. public function testGetTypeHasDefaultValue()
  78. {
  79. $this->assertEquals('Global', $this->_metadata->getType());
  80. }
  81. public function testTypeIsModifiable()
  82. {
  83. $this->_metadata->setType('foo');
  84. $this->assertEquals('foo', $this->_metadata->getType());
  85. }
  86. public function testSettersPersistValuesAndAreRetievableThroughGetters()
  87. {
  88. $this->_metadata->setName('Foo');
  89. $this->assertEquals('Foo', $this->_metadata->getName());
  90. $this->_metadata->setValue('Bar');
  91. $this->assertEquals('Bar', $this->_metadata->getValue());
  92. }
  93. public function testGetAttributesReturnsProperValues()
  94. {
  95. $obj1 = new ArrayObject();
  96. $this->_metadata->setOptions(array(
  97. 'name' => 'Foo',
  98. 'value' => null,
  99. 'reference' => $obj1
  100. ));
  101. $attributes = $this->_metadata->getAttributes();
  102. $this->assertEquals(4, count($attributes));
  103. $this->assertEquals('Global', $attributes['type']);
  104. $this->assertEquals('Foo', $attributes['name']);
  105. $this->assertEquals(null, $attributes['value']);
  106. $this->assertTrue($obj1 === $attributes['reference']);
  107. $attributes = $this->_metadata->getAttributes(Zend_Tool_Framework_Manifest_Metadata::ATTRIBUTES_NO_PARENT);
  108. $this->assertEquals(0, count($attributes));
  109. $attributes = $this->_metadata->getAttributes(Zend_Tool_Framework_Manifest_Metadata::ATTRIBUTES_ALL, true);
  110. $this->assertEquals(4, count($attributes));
  111. $this->assertEquals('Global', $attributes['type']);
  112. $this->assertEquals('Foo', $attributes['name']);
  113. $this->assertEquals('(null)', $attributes['value']);
  114. $this->assertEquals('(object)', $attributes['reference']);
  115. }
  116. public function testMetadataObjectCanCastToStringRepresentation()
  117. {
  118. $obj1 = new ArrayObject();
  119. $this->_metadata->setOptions(array(
  120. 'name' => 'Foo',
  121. 'value' => 'Bar',
  122. 'reference' => $obj1
  123. ));
  124. $this->assertEquals('Type: Global, Name: Foo, Value: Bar', (string) $this->_metadata);
  125. }
  126. }