2017-11-13 23:23:13 +00:00
|
|
|
<?php
|
2017-11-15 18:50:11 +00:00
|
|
|
|
|
|
|
namespace Tainacan\Tests;
|
2017-11-24 21:15:41 +00:00
|
|
|
use Tainacan\Entities\Log;
|
2017-11-15 18:50:11 +00:00
|
|
|
|
2017-11-13 23:23:13 +00:00
|
|
|
/**
|
|
|
|
* Class TestCollections
|
|
|
|
*
|
|
|
|
* @package Test_Tainacan
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sample test case.
|
|
|
|
*/
|
2017-12-04 18:20:49 +00:00
|
|
|
class Logs extends TAINACAN_UnitTestCase {
|
2017-11-13 23:23:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Teste da insercao de um log simples apenas se criar o dado bruto
|
|
|
|
*/
|
|
|
|
function test_add() {
|
2018-03-20 16:04:02 +00:00
|
|
|
$Tainacan_Logs = \Tainacan\Repositories\Logs::getInstance();
|
2017-11-13 23:23:13 +00:00
|
|
|
|
2017-12-04 18:20:49 +00:00
|
|
|
$log = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'log',
|
|
|
|
array(
|
|
|
|
'title' => 'blame someone',
|
|
|
|
'description' => 'someone did that'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2017-11-21 01:31:46 +00:00
|
|
|
|
|
|
|
$user_id = get_current_user_id();
|
|
|
|
$blog_id = get_current_blog_id();
|
2017-11-13 23:23:13 +00:00
|
|
|
|
|
|
|
//retorna a taxonomia
|
2017-11-20 17:24:07 +00:00
|
|
|
$test = $Tainacan_Logs->fetch($log->get_id());
|
2017-11-13 23:23:13 +00:00
|
|
|
|
|
|
|
$this->assertEquals( 'blame someone', $test->get_title() );
|
|
|
|
$this->assertEquals( 'someone did that', $test->get_description() );
|
2017-11-21 01:31:46 +00:00
|
|
|
$this->assertEquals( $user_id, $test->get_user_id() );
|
2017-11-24 21:15:41 +00:00
|
|
|
$this->assertEquals( $blog_id, $test->get_blog_id() );
|
|
|
|
|
2017-12-04 18:20:49 +00:00
|
|
|
$value = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'testeLogs',
|
|
|
|
'description' => 'adasdasdsa123',
|
|
|
|
'default_order' => 'DESC'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2017-11-24 21:15:41 +00:00
|
|
|
|
2018-03-20 16:04:02 +00:00
|
|
|
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance();
|
2017-11-24 21:15:41 +00:00
|
|
|
|
|
|
|
$value->set_name('new_testeLogs');
|
2017-11-30 18:00:25 +00:00
|
|
|
$value->validate();
|
2017-11-24 21:15:41 +00:00
|
|
|
$new_value = $Tainacan_Collections->insert($value);
|
|
|
|
|
|
|
|
$create_log = Log::create('teste create', 'testing a log creation function', $new_value, $value);
|
|
|
|
|
|
|
|
$this->assertEquals( 'teste create', $create_log->get_title() );
|
|
|
|
$this->assertEquals( 'testing a log creation function', $create_log->get_description() );
|
|
|
|
$this->assertEquals( $new_value, $create_log->get_value() );
|
|
|
|
$this->assertEquals( $value, $create_log->get_old_value() );
|
|
|
|
|
|
|
|
$testDB = $Tainacan_Logs->fetch($create_log->get_id());
|
|
|
|
|
|
|
|
$this->assertEquals( 'teste create', $testDB->get_title() );
|
|
|
|
$this->assertEquals( 'testing a log creation function', $testDB->get_description() );
|
|
|
|
$this->assertEquals( $new_value, $testDB->get_value() );
|
|
|
|
$this->assertEquals( $value, $testDB->get_old_value() );
|
|
|
|
|
|
|
|
$last_log = $Tainacan_Logs->fetch_last();
|
2017-12-01 02:52:26 +00:00
|
|
|
$this->assertTrue(is_object($last_log));
|
2017-11-24 21:15:41 +00:00
|
|
|
$collection = $last_log->get_value();
|
|
|
|
|
|
|
|
$this->assertEquals($collection->get_name(), 'new_testeLogs');
|
|
|
|
$this->assertEquals($collection->get_description(), 'adasdasdsa123');
|
2017-11-28 20:49:20 +00:00
|
|
|
$this->assertEquals($collection->get_default_order(), 'DESC');
|
2017-11-13 23:23:13 +00:00
|
|
|
}
|
2018-04-06 18:29:13 +00:00
|
|
|
|
|
|
|
public function test_log_diff(){
|
|
|
|
$Tainacan_Logs = \Tainacan\Repositories\Logs::getInstance();
|
|
|
|
$Tainacan_Filters = \Tainacan\Repositories\Filters::getInstance();
|
|
|
|
|
|
|
|
$filter = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'No name'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
// Modify filter name
|
|
|
|
$filter->set_name('With name');
|
|
|
|
|
|
|
|
$Tainacan_Filters->update($filter);
|
|
|
|
|
|
|
|
$log = $Tainacan_Logs->fetch_last();
|
|
|
|
|
|
|
|
$diff = $log->diff();
|
|
|
|
|
|
|
|
$this->assertEquals('With name', $diff['name']['new']);
|
|
|
|
$this->assertEquals('No name', $diff['name']['old']);
|
|
|
|
}
|
2017-11-13 23:23:13 +00:00
|
|
|
}
|