PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/tests/kernel/classes/ezpendingactions_test.php

https://github.com/granitegreg/ezpublish
PHP | 139 lines | 82 code | 16 blank | 41 comment | 0 complexity | 22fe408ae0af25d700101955bf13eeeb MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * File containing the eZPendingActions class tests
  4. *
  5. * @copyright Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.
  6. * @license http://ez.no/licenses/gnu_gpl GNU GPLv2
  7. * @author Jerome Vieilledent
  8. * @package tests
  9. */
  10. class eZPendingActionsTest extends ezpDatabaseTestCase
  11. {
  12. /**
  13. * Unit test for eZPersistentObject implementation
  14. */
  15. public function testPersistentObjectInterface()
  16. {
  17. $this->assertTrue( is_subclass_of( 'eZPendingActions', 'eZPersistentObject' ) );
  18. $this->assertTrue( method_exists( 'eZPendingActions', 'definition' ) );
  19. }
  20. /**
  21. * Unit test for good eZPersistentObject (ORM) implementation for ezsite_data table
  22. */
  23. public function testORMImplementation()
  24. {
  25. $def = eZPendingActions::definition();
  26. $this->assertEquals( 'eZPendingActions', $def['class_name'] );
  27. $this->assertEquals( 'ezpending_actions', $def['name'] );
  28. $fields = $def['fields'];
  29. $this->assertArrayHasKey( 'action', $fields );
  30. $this->assertArrayHasKey( 'created', $fields );
  31. $this->assertArrayHasKey( 'param', $fields );
  32. }
  33. /**
  34. * Unit test for fetchByAction() method
  35. */
  36. public function testFetchByAction()
  37. {
  38. // Insert several fixtures at one time. Can't use @dataProvider to do that
  39. $fixtures = $this->providerForTestFecthByAction();
  40. foreach( $fixtures as $fixture )
  41. {
  42. $this->insertPendingAction( $fixture[0], $fixture[1], $fixture[2] );
  43. }
  44. $res = eZPendingActions::fetchByAction( 'test' );
  45. $this->assertType( PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $res );
  46. foreach($res as $row)
  47. {
  48. $this->assertType( 'eZPendingActions', $row );
  49. }
  50. unset($res);
  51. $dateFilter = array( '<=', time() );
  52. $res = eZPendingActions::fetchByAction( 'test', $dateFilter );
  53. $this->assertType( PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $res );
  54. }
  55. /**
  56. * Data provider for self::testFetchByAction()
  57. * @see testFetchByAction()
  58. */
  59. public function providerForTestFecthByAction()
  60. {
  61. $time = time();
  62. return array(
  63. array( 'test', $time, 'Some params' ),
  64. array( 'test', $time+10, 'Other params' ),
  65. array( 'test', $time+20, '' )
  66. );
  67. }
  68. /**
  69. * Inserts a pending action
  70. * @param $action
  71. * @param $created
  72. * @param $params
  73. */
  74. private function insertPendingAction( $action, $created, $params )
  75. {
  76. $row = array(
  77. 'action' => $action,
  78. 'created' => $created,
  79. 'param' => $params
  80. );
  81. $obj = new eZPendingActions( $row );
  82. $obj->store();
  83. unset( $obj );
  84. }
  85. /**
  86. * Test for bad date filter token in eZPendingActions::fetchByAction()
  87. * @param $badFilter
  88. * @dataProvider providerForTestBadDateFilter
  89. */
  90. public function testBadDateFilter( $badFilter )
  91. {
  92. $res = eZPendingActions::fetchByAction( 'test', $badFilter );
  93. $this->assertNull( $res );
  94. }
  95. /**
  96. * Provider for self::testBadDateFilter()
  97. * @see testBadDateFilter()
  98. */
  99. public function providerForTestBadDateFilter()
  100. {
  101. return array(
  102. array( array( time(), '=' ) ), // Wrong order
  103. array( array( '<=', time(), 'foobar' ) ), // Wrong entries count
  104. array( array( '<>', time() ) ) // Invalid token
  105. );
  106. }
  107. /**
  108. * Test for eZPendingActions::removeByAction()
  109. */
  110. public function testRemoveByAction()
  111. {
  112. // Insert several fixtures at one time. Can't use @dataProvider to do that
  113. $fixtures = $this->providerForTestFecthByAction();
  114. foreach( $fixtures as $fixture )
  115. {
  116. $this->insertPendingAction( $fixture[0], $fixture[1], $fixture[2] );
  117. }
  118. eZPendingActions::removeByAction( 'test' );
  119. $res = eZPendingActions::fetchByAction( 'test' );
  120. $this->assertTrue( empty( $res ) );
  121. }
  122. }
  123. ?>