public function test_column_value_too_long() { $constraint_width = 80; $table = new cli\Table(); $renderer = new cli\Table\Ascii(); $renderer->setConstraintWidth($constraint_width); $table->setRenderer($renderer); $table->setHeaders(array('Field', 'Value')); $table->addRow(array('description', 'The 2012 theme for WordPress is a fully responsive theme that looks great on any device. Features include a front page template with its own widgets, an optional display font, styling for post formats on both index and single views, and an optional no-sidebar page template. Make it yours with a custom menu, header image, and background.')); $table->addRow(array('author', '<a href="http://wordpress.org/" title="Visit author homepage">the WordPress team</a>')); $out = $table->getDisplayLines(); // "+ 1" accommodates "\n" $this->assertCount(12, $out); $this->assertEquals($constraint_width, strlen($out[0]) + 1); $this->assertEquals($constraint_width, strlen($out[1]) + 1); $this->assertEquals($constraint_width, strlen($out[2]) + 1); $this->assertEquals($constraint_width, strlen($out[3]) + 1); $this->assertEquals($constraint_width, strlen($out[4]) + 1); $this->assertEquals($constraint_width, strlen($out[5]) + 1); $this->assertEquals($constraint_width, strlen($out[6]) + 1); $this->assertEquals($constraint_width, strlen($out[7]) + 1); $this->assertEquals($constraint_width, strlen($out[8]) + 1); $this->assertEquals($constraint_width, strlen($out[9]) + 1); $this->assertEquals($constraint_width, strlen($out[10]) + 1); $this->assertEquals($constraint_width, strlen($out[11]) + 1); }
/** * Show items in a \cli\Table. * * @param array $items * @param array $fields */ private static function show_table($items, $fields) { $table = new \cli\Table(); $enabled = \cli\Colors::shouldColorize(); if ($enabled) { \cli\Colors::disable(true); } $table->setHeaders($fields); foreach ($items as $item) { $table->addRow(array_values(\WP_CLI\Utils\pick_fields($item, $fields))); } foreach ($table->getDisplayLines() as $line) { \WP_CLI::line($line); } if ($enabled) { \cli\Colors::enable(true); } }
public function execute(array $args, array $options = array()) { # setUserMigration Path $this->migrationPath = isset($options['migration_path']) ? $options['migration_path'] : null; $list = $this->getDirectoryTree($this->getMigrationPath(), "php"); # get filename $file = isset($options['f']) ? true : false; $filter_apply = isset($options['a']) ? $options['a'] : false; $filter_new = isset($options['n']) ? $options['n'] : false; $filter_from = isset($options['from']) ? $options['from'] : false; $filter_to = isset($options['to']) ? $options['to'] : false; $filter_from = $filter_from ? strtotime($filter_from) : false; $filter_to = $filter_to ? strtotime($filter_to) : false; #check tag list $filer_tag = isset($options['tag']) ? $options['tag'] : false; if (!empty($list)) { $headers = array('№', 'id', 'Author', 'Date'); if ($file) { $headers[] = 'File'; } $headers[] = 'Description'; $headers[] = 'Status'; $table = new \cli\Table(); $table->setHeaders($headers); $count = 0; $applied = 0; $new = 0; $i = 1; $return_array_new = array(); $return_array_apply = array(); #filter $is_filter = false; $this->prepareFilter($list, $filter_from, $filter_to, $filer_tag, $options, $is_filter); foreach ($list as $id => $data) { $count++; $row = $data['file']; $name = $data['name']; # check in db $is_new = !$this->checkInDb($id); $class_name = "Migration" . $id; include_once "" . $this->getMigrationPath() . $row . ""; $color = ConsoleKit\Colors::GREEN; $status = ConsoleKit\Colors::colorize('apply', Colors::GREEN); # check in db if ($is_new) { $new++; $color = ConsoleKit\Colors::RED; $status = ConsoleKit\Colors::colorize('new', Colors::RED); } else { $applied++; } $rowArray = array(ConsoleKit\Colors::colorize($i, $color), ConsoleKit\Colors::colorize($id, $color), $data['author'], date("d.m.y G:h", $data['date'])); if ($file) { $rowArray[] = $row; } $rowArray[] = $data['description']; $rowArray[] = $status; if ($is_new) { $return_array_new[] = $rowArray; } else { $return_array_apply[] = $rowArray; } $i++; } if ($filter_new) { $table->setRows($return_array_new); } else { if ($filter_apply) { $table->setRows($return_array_apply); } else { $table->setRows(array_merge($return_array_apply, $return_array_new)); } } $displayArray = $table->getDisplayLines(); if (!empty($displayArray)) { $table->display(); } if (!$is_filter) { # count info $return[] = Colors::colorize('New:', Colors::RED) . " " . $new; $return[] = Colors::colorize('Applied:', Colors::GREEN) . " " . $applied; $return[] = "Count: " . $count; } # display $this->padding(implode(PHP_EOL, $return)); } else { $this->info('Empty migration'); } }