2
0

MetadataTest.php 4.5 KB

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