PageRenderTime 57ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

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

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