block.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. include_once __DIR__.'/../config.php';
  3. __p::load_utils('block');
  4. class BlockTest extends PHPUnit_Framework_TestCase {
  5. var $block;
  6. function setUp() {
  7. $this->block = new Block('foo');
  8. }
  9. function test_constructor() {
  10. $count = Block::$count;
  11. $block = new Block('foo');
  12. $this->assertEquals('foo', $block->name);
  13. $this->assertEquals($count + 1, Block::$count);
  14. }
  15. function test_set_single() {
  16. $block = $this->block->set('bar', 'baz');
  17. $this->assertEquals('baz', $this->block->vars['bar']);
  18. $this->assertSame($this->block, $block);
  19. }
  20. function test_set_multiple() {
  21. $data = array('bar' => 'baz', 'bar2' => 'baz2');
  22. $block = $this->block->set($data);
  23. $this->assertEquals($data, $this->block->vars);
  24. $this->assertSame($this->block, $block);
  25. }
  26. /**
  27. * @depends test_set_single
  28. */
  29. function test_get_simple() {
  30. $this->block->set('bar', 'baz');
  31. $this->assertEquals('baz', $this->block->get('bar'));
  32. }
  33. function test_get_null() {
  34. $this->assertNull($this->block->get('bar'));
  35. }
  36. /**
  37. * @depends test_get_simple
  38. */
  39. function test_getter() {
  40. $this->block->set('bar', 'baz');
  41. $this->assertEquals('baz', $this->block->bar);
  42. }
  43. /**
  44. * @depends test_set_multiple
  45. */
  46. function test_add_empty() {
  47. $block = $this->block->add('bar');
  48. $this->assertInstanceOf('Block', $block);
  49. $this->assertEquals('bar', $block->name);
  50. }
  51. /**
  52. * @depends test_get_simple
  53. * @depends test_add_empty
  54. */
  55. function test_add_data() {
  56. $block = $this->block->add('bar', array('baz' => 'foo'));
  57. $this->assertEquals('foo', $block->get('baz'));
  58. }
  59. /**
  60. * @depends test_add_empty
  61. * @depends test_get_simple
  62. */
  63. function test_get_parent() {
  64. $block = $this->block->set('bar', 'baz')->add('new-foo');
  65. $this->assertEquals('baz', $block->get('bar'));
  66. }
  67. /**
  68. * @depends test_add_empty
  69. */
  70. function test_find_single() {
  71. $block = $this->block->add('bar');
  72. $this->block->add('baz');
  73. $this->assertSame(array($block), $this->block->find('bar'));
  74. }
  75. /**
  76. * @depends test_add_empty
  77. */
  78. function test_find_multiple() {
  79. $block0 = $this->block->add('bar');
  80. $block1 = $this->block->add('bar');
  81. $this->block->add('baz');
  82. $this->assertSame(array($block0, $block1), $this->block->find('bar'));
  83. }
  84. /**
  85. * @depends test_add_empty
  86. */
  87. function test_find_none() {
  88. $this->block->add('bar');
  89. $this->block->add('baz');
  90. $this->assertSame(array(), $this->block->find('foo'));
  91. }
  92. /**
  93. * @depends test_add_empty
  94. */
  95. function test_remove_child() {
  96. $block0 = $this->block->add('bar');
  97. $block1 = $this->block->add('baz');
  98. $ret = $this->block->remove_child($block0);
  99. $this->assertSame(array($block1), $this->block->children);
  100. $this->assertSame($this->block, $ret);
  101. }
  102. /**
  103. * @depends test_remove_child
  104. */
  105. function test_remove() {
  106. $block0 = $this->block->add('bar');
  107. $block1 = $this->block->add('baz');
  108. $ret = $block0->remove();
  109. $this->assertSame(array($block1), $this->block->children);
  110. $this->assertSame($block0, $ret);
  111. }
  112. }
  113. ?>