|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace DDTrace\Tests\Integrations\WordPress\V5_9; |
| 4 | + |
| 5 | +use DDTrace\Tests\Common\WebFrameworkTestCase; |
| 6 | +use DDTrace\Tests\Frameworks\Util\Request\GetSpec; |
| 7 | +use datadog\appsec\AppsecStatus; |
| 8 | + |
| 9 | +class PathParamsTest extends WebFrameworkTestCase |
| 10 | +{ |
| 11 | + protected static function getAppIndexScript() |
| 12 | + { |
| 13 | + return __DIR__ . '/../../../Frameworks/WordPress/Version_4_8/index.php'; |
| 14 | + } |
| 15 | + |
| 16 | + protected function connection() |
| 17 | + { |
| 18 | + return new \PDO('mysql:host=mysql_integration;dbname=test', 'test', 'test'); |
| 19 | + } |
| 20 | + |
| 21 | + protected function ddSetUp() |
| 22 | + { |
| 23 | + parent::ddSetUp(); |
| 24 | + $this->connection()->exec(file_get_contents(__DIR__ . '/../../../Frameworks/WordPress/Version_5_5/wp_2020-10-21.sql')); |
| 25 | + AppsecStatus::getInstance()->setDefaults(); |
| 26 | + } |
| 27 | + |
| 28 | + public static function ddSetUpBeforeClass() |
| 29 | + { |
| 30 | + parent::ddSetUpBeforeClass(); |
| 31 | + AppsecStatus::getInstance()->init(); |
| 32 | + } |
| 33 | + |
| 34 | + public static function ddTearDownAfterClass() |
| 35 | + { |
| 36 | + AppsecStatus::getInstance()->destroy(); |
| 37 | + parent::ddTearDownAfterClass(); |
| 38 | + } |
| 39 | + |
| 40 | + public function testPost() |
| 41 | + { |
| 42 | + $this->call( |
| 43 | + GetSpec::create( |
| 44 | + 'Post example', |
| 45 | + '/hello-world' |
| 46 | + ) |
| 47 | + ); |
| 48 | + |
| 49 | + $events = AppsecStatus::getInstance()->getEvents(); |
| 50 | + $this->assertEquals(1, count($events)); |
| 51 | + $this->assertEquals('hello-world', $events[0]['name']); |
| 52 | + $this->assertEquals('push_params', $events[0]['eventName']); |
| 53 | + } |
| 54 | + |
| 55 | + public function testCategory() |
| 56 | + { |
| 57 | + $this->call( |
| 58 | + GetSpec::create( |
| 59 | + 'Category', |
| 60 | + '/category/uncategorized' |
| 61 | + ) |
| 62 | + ); |
| 63 | + |
| 64 | + $events = AppsecStatus::getInstance()->getEvents(); |
| 65 | + $this->assertEquals(1, count($events)); |
| 66 | + $this->assertEquals('uncategorized', $events[0]['category_name']); |
| 67 | + $this->assertEquals('push_params', $events[0]['eventName']); |
| 68 | + } |
| 69 | + |
| 70 | + public function testAuthor() |
| 71 | + { |
| 72 | + $this->call( |
| 73 | + GetSpec::create( |
| 74 | + 'Author', |
| 75 | + '/author/test' |
| 76 | + ) |
| 77 | + ); |
| 78 | + |
| 79 | + $events = AppsecStatus::getInstance()->getEvents(); |
| 80 | + $this->assertEquals(1, count($events)); |
| 81 | + $this->assertEquals('test', $events[0]['author_name']); |
| 82 | + $this->assertEquals('push_params', $events[0]['eventName']); |
| 83 | + } |
| 84 | + |
| 85 | + public function testNonExistingPost() |
| 86 | + { |
| 87 | + $this->call( |
| 88 | + GetSpec::create( |
| 89 | + 'Not existing post', |
| 90 | + '/non-existing-post' |
| 91 | + ) |
| 92 | + ); |
| 93 | + |
| 94 | + $events = AppsecStatus::getInstance()->getEvents(); |
| 95 | + $this->assertEquals(0, count($events)); |
| 96 | + } |
| 97 | +} |
0 commit comments