/plugins/Actions/tests/Actions.test.php

https://github.com/quarkness/piwik · PHP · 105 lines · 97 code · 8 blank · 0 comment · 1 complexity · cc78b5bf96abcab20da4c9e037609872 MD5 · raw file

  1. <?php
  2. if(!defined('PIWIK_CONFIG_TEST_INCLUDED'))
  3. {
  4. require_once dirname(__FILE__)."/../../../tests/config_test.php";
  5. }
  6. require_once 'Actions/Actions.php';
  7. require_once 'Tracker/Action.php';
  8. require_once 'Tracker/Config.php';
  9. class Test_Piwik_Actions extends UnitTestCase
  10. {
  11. function setUp()
  12. {
  13. $userFile = PIWIK_INCLUDE_PATH . '/tests/resources/plugins/Actions/Actions.config.ini.php';
  14. Piwik::createConfigObject($userFile);
  15. Piwik_Translate::getInstance()->loadEnglishTranslation();
  16. Zend_Registry::get('config')->setTestEnvironment();
  17. }
  18. function tearDown()
  19. {
  20. Piwik::createConfigObject();
  21. Zend_Registry::get('config')->setTestEnvironment();
  22. }
  23. function test_getActionExplodedNames()
  24. {
  25. $action = new Test_Piwik_Actions_getActionExplodedNames();
  26. $tests = array(
  27. array(
  28. 'params' => array( 'name' => 'http://example.org/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
  29. 'expected' => array('/index' ),
  30. ),
  31. array(
  32. 'params' => array( 'name' => 'http://example.org/path/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
  33. 'expected' => array( 'path', '/index' ),
  34. ),
  35. array(
  36. 'params' => array( 'name' => 'http://example.org/test/path', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
  37. 'expected' => array( 'test', '/path' ),
  38. ),
  39. array(
  40. 'params' => array( 'name' => 'Test / Path', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
  41. 'expected' => array( 'Test', '/Path' ),
  42. ),
  43. array(
  44. 'params' => array( 'name' => ' Test trim ', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
  45. 'expected' => array( '/Test trim' ),
  46. ),
  47. array(
  48. 'params' => array( 'name' => 'Category / Subcategory', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
  49. 'expected' => array( 'Category', ' Subcategory' ),
  50. ),
  51. array(
  52. 'params' => array( 'name' => '/path/index.php?var=test', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
  53. 'expected' => array( 'path', ' index.php?var=test' ),
  54. ),
  55. array(
  56. 'params' => array( 'name' => 'http://example.org/path/Default.aspx#anchor', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
  57. 'expected' => array( 'path', ' Default.aspx' ),
  58. ),
  59. array(
  60. 'params' => array( 'name' => '', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
  61. 'expected' => array( 'Page Name not defined' ),
  62. ),
  63. array(
  64. 'params' => array( 'name' => '', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
  65. 'expected' => array( 'Page URL not defined' ),
  66. ),
  67. array(
  68. 'params' => array( 'name' => 'http://example.org/download.zip', 'type' => Piwik_Tracker_Action::TYPE_DOWNLOAD),
  69. 'expected' => array( 'example.org', '/download.zip' ),
  70. ),
  71. array(
  72. 'params' => array( 'name' => 'http://example.org/download/1/', 'type' => Piwik_Tracker_Action::TYPE_DOWNLOAD),
  73. 'expected' => array( 'example.org', '/download/1/' ),
  74. ),
  75. array(
  76. 'params' => array( 'name' => 'http://example.org/link', 'type' => Piwik_Tracker_Action::TYPE_OUTLINK),
  77. 'expected' => array( 'example.org', '/link' ),
  78. ),
  79. array(
  80. 'params' => array( 'name' => 'http://example.org/some/path/', 'type' => Piwik_Tracker_Action::TYPE_OUTLINK),
  81. 'expected' => array( 'example.org', '/some/path/' ),
  82. ),
  83. );
  84. foreach($tests as $test) {
  85. $params = $test['params'];
  86. $expected = $test['expected'];
  87. $processed = $action->public_getActionExplodedNames($params['name'],$params['type']);
  88. $this->assertEqual($processed, $expected, "Processed: ".var_export($processed, true) . " | Expected: ". var_export($expected, true));
  89. }
  90. }
  91. }
  92. class Test_Piwik_Actions_getActionExplodedNames extends Piwik_Actions {
  93. public function public_getActionExplodedNames($name, $type)
  94. {
  95. return self::getActionExplodedNames($name, $type);
  96. }
  97. }