Skip to content

Commit

Permalink
New: Add traits.
Browse files Browse the repository at this point in the history
  • Loading branch information
iNewLegend committed Aug 24, 2021
1 parent e2dad24 commit 6251d11
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
26 changes: 26 additions & 0 deletions phpunit/traits/kit-trait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace ElementorEditorTesting\Traits;

use Elementor\Plugin;
use Elementor\Core\Kits\Manager;

/**
* @mixin \WP_UnitTestCase
*/
trait Kit_Trait {
protected function create_default_kit() {
return Manager::create_default_kit();
}

protected function remove_default_kit() {
// Make sure the the 'wp_delete_post' function will actually delete the kit.
$_GET['force_delete_kit'] = '1';

$active_kit_id = Plugin::$instance->kits_manager->get_active_id();

wp_delete_post( $active_kit_id, true );
delete_option( Manager::OPTION_ACTIVE );

unset( $_GET['force_delete_kit'] );
}
}
38 changes: 38 additions & 0 deletions phpunit/traits/rest-trait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
namespace ElementorEditorTesting\Traits;

use Elementor\Data\Manager;
use ElementorEditorTesting\Elementor_Test_Base;

/**
* @mixin Elementor_Test_Base
*/
Trait Rest_Trait {
/**
* @var Manager
*/
protected $data_manager;

public function setUp() {
parent::setUp();

$this->data_manager = Manager::instance();
$this->data_manager->kill_server();
}

protected function http_get( $command, $args = [] ) {
return $this->data_manager->run( $command, $args, 'GET' );
}

protected function http_post( $command, $args = [] ) {
return $this->data_manager->run( $command, $args, 'POST' );
}

protected function http_put( $command, $args = [] ) {
return $this->data_manager->run( $command, $args, 'PUT' );
}

protected function http_delete( $command, $args = [] ) {
return $this->data_manager->run( $command, $args, 'DELETE' );
}
}

0 comments on commit 6251d11

Please sign in to comment.