<commit_before><?php

$app = 'sympal';
require_once(dirname(__FILE__).'/../../bootstrap/unit.php');

$t = new lime_test(24);

$configuration->loadHelpers(array('I18N'));

function installPlugin($name, $t)
{
  // Install the plugin
  $manager = sfSympalPluginManager::getActionInstance($name, 'install');
  $manager->install();

  // Check that content type was created
  $contentTypeName = $manager->getContentTypeForPlugin($name);
  $contentType = Doctrine_Core::getTable('sfSympalContentType')->findOneByName($contentTypeName);
  $t->is($contentType['name'], $contentTypeName, 'Test content type name set');
  $t->is($contentType['label'], sfInflector::humanize(sfInflector::tableize(str_replace('sfSympal', null, $contentTypeName))), 'Test content type label set');

  $contentList = Doctrine_Core::getTable('sfSympalContentList')->findOneByContentTypeId($contentType['id']);
  $t->is($contentList instanceof sfSympalContentList, true, 'Test sample content list was created.');

  $menuItem = Doctrine_Core::getTable('sfSympalMenuItem')->findOneByContentId($contentList['content_id']);
  $t->is($menuItem instanceof sfSympalMenuItem, true, 'Test menu item to sample content list was created.');
}

function uninstallPlugin($name, $t, $delete = true)
{
  $manager = sfSympalPluginManager::getActionInstance($name, 'uninstall');
  $manager->uninstall($delete);

  $t->is(file_exists(sfConfig::get('sf_plugins_dir').'/'.$name), !$delete, 'Test plugin was was deleted');
  $t->is(file_exists(sfConfig::get('sf_lib_dir').'/model/doctrine/'.$name), !$delete, 'Test plugin models were deleted');
  $t->is(file_exists(sfConfig::get('sf_lib_dir').'/form/doctrine/'.$name), !$delete, 'Test plugin forms were deleted');
  $t->is(file_exists(sfConfig::get('sf_lib_dir').'/filter/doctrine/'.$name), !$delete, 'Test plugin form filters were deleted');
  $t->is(file_exists(sfConfig::get('sf_web_dir').'/'.$name), !$delete, 'Test plugin assets symlink was removed');
}

$t->info('1 - Uninstalling sfSympalBlogPlugin...');
uninstallPlugin('sfSympalBlogPlugin', $t, false);
$t->info('2 - Installing sfSympalBlogPlugin...');
installPlugin('sfSympalBlogPlugin', $t);

$t->info('3 - Installing sfSympalEventPlugin');
installPlugin('sfSympalEventPlugin', $t);

$t->info('4 - Uninstalling sfSympalEventPlugin...');
uninstallPlugin('sfSympalEventPlugin', $t);

$t->info('5 - Uninstalling sfSympalObjectReplacerPlugin');
uninstallPlugin('sfSympalObjectReplacerPlugin', $t);<commit_msg>[1.0][sfSympalPluginManagerPlugin] Reworking this test.<commit_after><?php

/**
 * Tests what happens when you install and uninstall plugins
 * 
 * @package     sfSympalPlugin
 * @subpackage  test
 * @author      <NAME> <<EMAIL>>
 * @author      <NAME> <<EMAIL>>
 */

$app = 'sympal';
require_once(dirname(__FILE__).'/../../bootstrap/unit.php');

$t = new lime_test(16);

$configuration->loadHelpers(array('I18N'));

function installPlugin($name, $t, $contentTypeModelName)
{
  // Install the plugin
  $manager = sfSympalPluginManager::getActionInstance($name, 'install');
  $manager->install();

  // Check that content type was created
  $contentTypeName = $manager->getContentTypeForPlugin($name);
  
  if ($contentTypeModelName)
  {
    $t->is($contentTypeName, $contentTypeModelName, sprintf('getContentTypeForPlugin() returns the content type "%s"', $contentTypeName));

    $contentType = Doctrine_Core::getTable('sfSympalContentType')->findOneByName($contentTypeName);
    $t->is($contentType['name'], $contentTypeName, 'Test content type name set');
    $t->is($contentType['label'], sfInflector::humanize(sfInflector::tableize(str_replace('sfSympal', null, $contentTypeName))), 'Test content type label set');
    
    $contentList = Doctrine_Core::getTable('sfSympalContentList')->findOneByContentTypeId($contentType['id']);
    $t->is($contentList instanceof sfSympalContentList, true, 'Test sample content list was created.');

    $menuItem = Doctrine_Core::getTable('sfSympalMenuItem')->findOneByContentId($contentList['content_id']);
    $t->is($menuItem instanceof sfSympalMenuItem, true, 'Test menu item to sample content list was created.');
  }
  else
  {
    $t->is($contentTypeName, false, '->getContentTypeForPlugin() return false, there is not content type');
  }
}

function uninstallPlugin($name, $t, $delete = true)
{
  $manager = sfSympalPluginManager::getActionInstance($name, 'uninstall');
  $manager->uninstall($delete);

  $t->is(file_exists(sfConfig::get('sf_plugins_dir').'/'.$name), !$delete, 'Test plugin was was deleted');
  $t->is(file_exists(sfConfig::get('sf_lib_dir').'/model/doctrine/'.$name), !$delete, 'Test plugin models were deleted');
  $t->is(file_exists(sfConfig::get('sf_lib_dir').'/form/doctrine/'.$name), !$delete, 'Test plugin forms were deleted');
  $t->is(file_exists(sfConfig::get('sf_lib_dir').'/filter/doctrine/'.$name), !$delete, 'Test plugin form filters were deleted');
  $t->is(file_exists(sfConfig::get('sf_web_dir').'/'.$name), !$delete, 'Test plugin assets symlink was removed');
}

$t->info('1 - Uninstalling sfSympalBlogPlugin...');
uninstallPlugin('sfSympalBlogPlugin', $t, false);
$t->info('2 - Installing sfSympalBlogPlugin...');
installPlugin('sfSympalBlogPlugin', $t, 'sfSympalBlogPost');

$t->info('3 - Uninstalling sfSympalCommentsPlugin...');
uninstallPlugin('sfSympalCommentsPlugin', $t, false);
$t->info('4 - Installing sfSympalCommentsPlugin');
installPlugin('sfSympalCommentsPlugin', $t, false);
{'fraction_non_alphanumeric': 0.17910996689959544, 'fraction_numerical': 0.003493931592497242, 'mean_word_length': 6.837175792507205, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3107404', 'n_tokens_mistral': 1745, 'n_tokens_neox': 1729, 'n_words': 328}